diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-11-18 16:33:36 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-11-18 16:33:36 +0000 |
commit | 2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5 (patch) | |
tree | eba8c0ec6d0c949ad8afdee1e0281fec7172a584 /app/src/main | |
parent | 91a979049d7e71a3fd2dd3c1fc46b4967dbaa444 (diff) | |
download | infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar.gz infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar.bz2 infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar.lz infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar.xz infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.tar.zst infinity-for-reddit-2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5.zip |
Fix search user error.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java | 17 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java | 6 |
2 files changed, 12 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java index bc0f1966..8e56b3ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java @@ -19,7 +19,7 @@ public class ParseUserData { new ParseUserListingDataAsyncTask(response, parseUserListingDataListener).execute(); } - private static UserData parseUserDataBase(JSONObject userDataJson) throws JSONException { + private static UserData parseUserDataBase(JSONObject userDataJson, boolean parseFullKarma) throws JSONException { if(userDataJson == null) { return null; } @@ -37,9 +37,14 @@ public class ParseUserData { } int linkKarma = userDataJson.getInt(JSONUtils.LINK_KARMA_KEY); int commentKarma = userDataJson.getInt(JSONUtils.COMMENT_KARMA_KEY); - int awarderKarma = userDataJson.getInt(JSONUtils.AWARDER_KARMA_KEY); - int awardeeKarma = userDataJson.getInt(JSONUtils.AWARDEE_KARMA_KEY); - int totalKarma = userDataJson.getInt(JSONUtils.TOTAL_KARMA_KEY); + int awarderKarma = 0; + int awardeeKarma = 0; + int totalKarma = linkKarma + commentKarma; + if (parseFullKarma) { + awarderKarma = userDataJson.getInt(JSONUtils.AWARDER_KARMA_KEY); + awardeeKarma = userDataJson.getInt(JSONUtils.AWARDEE_KARMA_KEY); + totalKarma = userDataJson.getInt(JSONUtils.TOTAL_KARMA_KEY); + } long cakeday = userDataJson.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; boolean isGold = userDataJson.getBoolean(JSONUtils.IS_GOLD_KEY); boolean isFriend = userDataJson.getBoolean(JSONUtils.IS_FRIEND_KEY); @@ -83,7 +88,7 @@ public class ParseUserData { @Override protected Void doInBackground(Void... voids) { try { - userData = parseUserDataBase(jsonResponse); + userData = parseUserDataBase(jsonResponse, true); } catch (JSONException e) { parseFailed = true; e.printStackTrace(); @@ -130,7 +135,7 @@ public class ParseUserData { after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); for (int i = 0; i < children.length(); i++) { - userDataArrayList.add(parseUserDataBase(children.getJSONObject(i))); + userDataArrayList.add(parseUserDataBase(children.getJSONObject(i), false)); } } } catch (JSONException e) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java index 614a0303..bb39001f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java @@ -54,11 +54,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData> new FetchUserData.FetchUserListingDataListener() { @Override public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { - if (UserData.size() == 0) { - hasUserLiveData.postValue(false); - } else { - hasUserLiveData.postValue(true); - } + hasUserLiveData.postValue(UserData.size() != 0); callback.onResult(UserData, null, after); initialLoadStateLiveData.postValue(NetworkState.LOADED); |