Skip to content

Commit

Permalink
cleaned up, release 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
micwallace committed Mar 4, 2015
1 parent 20e26e1 commit c9e02f9
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 213 deletions.
432 changes: 280 additions & 152 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file added reddinator/reddinator-release.apk
Binary file not shown.
Binary file removed reddinator/reddinator.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions reddinator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="au.com.wallaceit.reddinator"
android:versionCode="10"
android:versionName="2.1">
android:versionCode="11"
android:versionName="2.2">

<uses-permission android:name="android.permission.INTERNET" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void loadPersonalList() {

private void savePersonalList() {
SharedPreferences.Editor editor = mSharedPreferences.edit();
Set<String> set = new HashSet<String>();
Set<String> set = new HashSet<>();
set.addAll(personalList);
editor.putStringSet("personalsr", set);
editor.apply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RedditData {
private SharedPreferences sharedPrefs;
private DefaultHttpClient httpclient;
static JSONObject jObj = null;
private static final String STANDARD_ENDPOINT = "http://www.reddit.com";
private static final String OAUTH_ENDPOINT = "https://oauth.reddit.com";
public static final String OAUTH_CLIENTID = "wY63YAHgSPSh5w";
Expand Down Expand Up @@ -299,7 +297,7 @@ private JSONObject getJSONFromUrl(String url, boolean useAuth) throws RedditApiE
// HTTPS POST Request
private JSONObject getJSONFromPost(String url, ArrayList<NameValuePair> data, boolean addOauthHeaders) throws RedditApiException {
JSONObject jObj = new JSONObject();
String json = "";
String json;
InputStream is = null;
// create client if null
if (httpclient == null) {
Expand Down Expand Up @@ -348,7 +346,7 @@ private JSONObject getJSONFromPost(String url, ArrayList<NameValuePair> data, bo
}

private String getStringFromStream(InputStream is) {
BufferedReader reader = null;
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
} catch (UnsupportedEncodingException e) {
Expand All @@ -374,10 +372,6 @@ private String getStringFromStream(InputStream is) {
}

class RedditApiException extends Exception {
//Parameterless Constructor
public RedditApiException() {
}

//Constructor that accepts a message
public RedditApiException(String message) {
super(message);
Expand Down Expand Up @@ -409,9 +403,8 @@ private boolean isTokenExpired() {
} catch (JSONException e) {
e.printStackTrace();
}
boolean expired = expiry < now;
//System.out.println("Token is " + (expired ? "expired" : "valid"));
return expired;
//System.out.println("Token is " + (expiry < now ? "expired" : "valid"));
return expiry < now;
}

private String getTokenValue(String key) {
Expand All @@ -431,7 +424,7 @@ public boolean retrieveToken(String code, String state) throws RedditApiExceptio
}
String url = "https://www.reddit.com/api/v1/access_token";
JSONObject resultjson;
ArrayList params = new ArrayList<NameValuePair>();
ArrayList<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("grant_type", "authorization_code"));
params.add(new BasicNameValuePair("code", code));
params.add(new BasicNameValuePair("redirect_uri", OAUTH_REDIRECT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private void loadReddits(boolean loadMore) {
clearImageCache();
// reload feed
int limit = Integer.valueOf(mSharedPreferences.getString("numitemloadpref", "25"));
JSONArray tempArray = null;
JSONArray tempArray;
tempArray = global.mRedditData.getRedditFeed(curFeed, sort, limit, "0");
// check if data is valid; if the getredditfeed function fails to create a connection it returns -1 in the first value of the array
if (!isError(tempArray)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.srtoolbar).setBackgroundColor(Color.parseColor("#5F99CF")); // set dark theme
}
// get subreddit list and set adapter
Set<String> feeds = mSharedPreferences.getStringSet("personalsr", new HashSet<String>());
personalList = global.getPersonalList();
mListAdapter = new MyRedditsAdapter(this, personalList);
setListAdapter(mListAdapter);
Expand Down Expand Up @@ -334,6 +333,7 @@ public void run() {
list.add(0, "Front Page");
list.add(1, "all");
personalList.addAll(list);
global.setPersonalList(personalList);
}
runOnUiThread(new Runnable() {
public void run() {
Expand Down Expand Up @@ -375,6 +375,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
public void onClick(View v) {
String sreddit = ((TextView) ((View) v.getParent()).findViewById(R.id.subreddit_name)).getText().toString();
personalList.remove(sreddit);
global.removeFromPersonalList(sreddit);
mListAdapter.notifyDataSetChanged();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void onResume() {
sreddits = global.getSrList();
setListAdaptor();
} else {
sreddits = new ArrayList<String>();
sreddits = new ArrayList<>();
setListAdaptor();
loadPopularSubreddits();
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public void run() {
e.printStackTrace();
}
// put into arraylist
sreddits = new ArrayList<String>();
sreddits = new ArrayList<>();
int i = 0;
while (i < srjson.length()) {
try {
Expand Down Expand Up @@ -254,7 +254,7 @@ protected ArrayList<String> doInBackground(String... string) {
e.printStackTrace();
}
// put into arraylist
ArrayList<String> popreddits = new ArrayList<String>();
ArrayList<String> popreddits = new ArrayList<>();
int i = 0;
popreddits.add("Front Page"); // slap the front page on there
popreddits.add("all"); // and an all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/
package au.com.wallaceit.reddinator;

import java.util.HashMap;

import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -31,19 +28,15 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
Expand All @@ -52,6 +45,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class ViewRedditActivity extends FragmentActivity implements TabHost.OnTabChangeListener {

private TabHost mTabHost;
Expand Down Expand Up @@ -327,32 +322,36 @@ protected String doInBackground(String... strings) {
protected void onPostExecute(String result) {
ViewRedditActivity.this.setTitle("Reddinator"); // reset title
voteinprogress = false;
if (result.equals("OK")) {
curvote = direction;
switch (direction) {
case -1:
upvote.setIcon(R.drawable.upvote);
downvote.setIcon(R.drawable.downvote_active);
setUpdateRecord("false");
break;

case 0:
upvote.setIcon(R.drawable.upvote);
downvote.setIcon(R.drawable.downvote);
setUpdateRecord("null");
break;

case 1:
upvote.setIcon(R.drawable.upvote_active);
downvote.setIcon(R.drawable.downvote);
setUpdateRecord("true");
break;
}
} else if (result.equals("LOGIN")) {
global.mRedditData.initiateLogin(ViewRedditActivity.this);
} else {
// show error
Toast.makeText(ViewRedditActivity.this, "API Error: " + result, Toast.LENGTH_LONG).show();
switch (result) {
case "OK":
curvote = direction;
switch (direction) {
case -1:
upvote.setIcon(R.drawable.upvote);
downvote.setIcon(R.drawable.downvote_active);
setUpdateRecord("false");
break;

case 0:
upvote.setIcon(R.drawable.upvote);
downvote.setIcon(R.drawable.downvote);
setUpdateRecord("null");
break;

case 1:
upvote.setIcon(R.drawable.upvote_active);
downvote.setIcon(R.drawable.downvote);
setUpdateRecord("true");
break;
}
break;
case "LOGIN":
global.mRedditData.initiateLogin(ViewRedditActivity.this);
break;
default:
// show error
Toast.makeText(ViewRedditActivity.this, "API Error: " + result, Toast.LENGTH_LONG).show();
break;
}

}
Expand Down
13 changes: 6 additions & 7 deletions reddinator/src/main/res/layout/subredditselect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:orientation="vertical">

<LinearLayout
android:id="@+id/widgetpref"
Expand All @@ -11,7 +11,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#EFF7FF"
android:orientation="horizontal" >
android:orientation="horizontal">

<Button
android:id="@+id/sortselect"
Expand All @@ -38,31 +38,30 @@
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#336699" />

</LinearLayout>
</LinearLayout>

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/srtoolbar"
android:background="#FFF" >
</ListView>
android:background="#FFF"></ListView>

<RelativeLayout
android:id="@+id/srtoolbar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/widgetpref"
android:background="#CEE3F8" >
android:background="#CEE3F8">

<Button
android:id="@+id/addsrbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/add"
android:text="@string/view_all"
android:textSize="16sp" />

<Button
Expand Down
1 change: 1 addition & 0 deletions reddinator/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="nsfw_flag">[NSFW]</string>
<string name="view_all">View All</string>

</resources>

0 comments on commit c9e02f9

Please sign in to comment.