From 2db6fb8aca4bb0484cfcfbccbb9834101ee0a2e5 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 19 Nov 2020 00:33:36 +0800 Subject: Fix search user error. --- .../infinityforreddit/user/ParseUserData.java | 17 +++++++++++------ .../infinityforreddit/user/UserListingDataSource.java | 6 +----- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'app') 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 new FetchUserData.FetchUserListingDataListener() { @Override public void onFetchUserListingDataSuccess(ArrayList 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); -- cgit v1.2.3