aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/User/ParseUserData.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseUserData.java (renamed from app/src/main/java/User/ParseUserData.java)19
1 files changed, 10 insertions, 9 deletions
diff --git a/app/src/main/java/User/ParseUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseUserData.java
index b6a7a39c..12402f03 100644
--- a/app/src/main/java/User/ParseUserData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseUserData.java
@@ -1,4 +1,4 @@
-package User;
+package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.util.Log;
@@ -6,15 +6,15 @@ import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
-import ml.docilealligator.infinityforreddit.JSONUtils;
+import User.UserData;
public class ParseUserData {
interface ParseUserDataListener {
- void onParseUserDataSuccess(User user);
+ void onParseUserDataSuccess(UserData userData);
void onParseUserDataFail();
}
- static void parseMyInfo(String response, ParseUserDataListener parseUserDataListener) {
+ static void parseUserData(String response, ParseUserDataListener parseUserDataListener) {
new ParseUserDataAsyncTask(response, parseUserDataListener).execute();
}
@@ -23,15 +23,16 @@ public class ParseUserData {
private ParseUserDataListener parseUserDataListener;
private boolean parseFailed;
- private User user;
+ private UserData userData;
ParseUserDataAsyncTask(String response, ParseUserDataListener parseUserDataListener){
try {
+ Log.i("response", response);
jsonResponse = new JSONObject(response);
this.parseUserDataListener = parseUserDataListener;
parseFailed = false;
} catch (JSONException e) {
- Log.i("user data json error", e.getMessage());
+ Log.i("userdata json error", e.getMessage());
parseUserDataListener.onParseUserDataFail();
}
}
@@ -43,7 +44,7 @@ public class ParseUserData {
String userName = jsonResponse.getString(JSONUtils.NAME_KEY);
String iconImageUrl = jsonResponse.getString(JSONUtils.ICON_IMG_KEY);
String bannerImageUrl = "";
- if(!jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) {
+ if(jsonResponse.has(JSONUtils.SUBREDDIT_KEY) && !jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) {
bannerImageUrl = jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY);
}
int linkKarma = jsonResponse.getInt(JSONUtils.LINK_KARMA_KEY);
@@ -52,7 +53,7 @@ public class ParseUserData {
boolean isGold = jsonResponse.getBoolean(JSONUtils.IS_GOLD_KEY);
boolean isFriend = jsonResponse.getBoolean(JSONUtils.IS_FRIEND_KEY);
- user = new User(userName, iconImageUrl, bannerImageUrl, karma, isGold, isFriend);
+ userData = new UserData(userName, iconImageUrl, bannerImageUrl, karma, isGold, isFriend);
} catch (JSONException e) {
parseFailed = true;
Log.i("parse user data error", e.getMessage());
@@ -63,7 +64,7 @@ public class ParseUserData {
@Override
protected void onPostExecute(Void aVoid) {
if(!parseFailed) {
- parseUserDataListener.onParseUserDataSuccess(user);
+ parseUserDataListener.onParseUserDataSuccess(userData);
} else {
parseUserDataListener.onParseUserDataFail();
}