aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-22 11:49:50 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-22 11:49:50 +0000
commit97079663ff8e6fdae31d168df79f6e8329c8766e (patch)
tree18626dd7a1f827f131eed55e68f54a0f29cb07dc /app
parent80058ff6ab192b830b39566ee07a5903c450cf6c (diff)
downloadinfinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar.gz
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar.bz2
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar.lz
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar.xz
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.tar.zst
infinity-for-reddit-97079663ff8e6fdae31d168df79f6e8329c8766e.zip
Correctly handle the case that the value of SELFTEXT_HTML or BODY_HTML_KEY is null. Delete the constraint that only when all the subscribed subreddits and users data have been inserted can the two RecyclerViews update their data in order to avoid the newly fetched data cannot be observed by observers and make the RecyclerView getting the new data impossible.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java1
3 files changed, 15 insertions, 21 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index b462006e..09024906 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -54,7 +54,6 @@ public class MainActivity extends AppCompatActivity {
private String mBannerImageUrl;
private String mKarma;
private boolean mFetchUserInfoSuccess;
- private boolean mIsInserting;
private boolean mInsertSuccess;
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
@@ -153,15 +152,13 @@ public class MainActivity extends AppCompatActivity {
mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, new Observer<List<SubscribedSubredditData>>() {
@Override
public void onChanged(@Nullable final List<SubscribedSubredditData> subscribedSubredditData) {
- if(!mIsInserting) {
- if(subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
- subscriptionsLabelTextView.setVisibility(View.GONE);
- } else {
- subscriptionsLabelTextView.setVisibility(View.VISIBLE);
- }
-
- subredditadapter.setSubscribedSubreddits(subscribedSubredditData);
+ if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
+ subscriptionsLabelTextView.setVisibility(View.GONE);
+ } else {
+ subscriptionsLabelTextView.setVisibility(View.VISIBLE);
}
+
+ subredditadapter.setSubscribedSubreddits(subscribedSubredditData);
}
});
@@ -171,15 +168,12 @@ public class MainActivity extends AppCompatActivity {
mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, new Observer<List<SubscribedUserData>>() {
@Override
public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) {
- if(!mIsInserting) {
- Log.i("view", "observed");
- if(subscribedUserData == null || subscribedUserData.size() == 0) {
- followingLabelTextView.setVisibility(View.GONE);
- } else {
- followingLabelTextView.setVisibility(View.VISIBLE);
- }
- userAdapter.setSubscribedUsers(subscribedUserData);
+ if (subscribedUserData == null || subscribedUserData.size() == 0) {
+ followingLabelTextView.setVisibility(View.GONE);
+ } else {
+ followingLabelTextView.setVisibility(View.VISIBLE);
}
+ userAdapter.setSubscribedUsers(subscribedUserData);
}
});
}
@@ -240,7 +234,6 @@ public class MainActivity extends AppCompatActivity {
public void onFetchSubscribedSubredditsSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
ArrayList<SubscribedUserData> subscribedUserData,
ArrayList<SubredditData> subredditData) {
- mIsInserting = true;
new InsertSubscribedThingsAsyncTask(
SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this),
SubscribedUserRoomDatabase.getDatabase(MainActivity.this),
@@ -251,7 +244,6 @@ public class MainActivity extends AppCompatActivity {
new InsertSubscribedThingsAsyncTask.InsertSubscribedThingListener() {
@Override
public void insertSuccess() {
- mIsInserting = false;
mInsertSuccess = true;
}
}).execute();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index 4f3781b0..8b623b76 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -72,7 +72,10 @@ class ParseComment {
String fullName = data.getString(JSONUtils.LINK_ID);
String author = data.getString(JSONUtils.AUTHOR_KEY);
boolean isSubmitter = data.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
- String commentContent = data.getString(JSONUtils.BODY_HTML_KEY);
+ String commentContent = "";
+ if(!data.isNull(JSONUtils.BODY_HTML_KEY)) {
+ commentContent = data.getString(JSONUtils.BODY_HTML_KEY);
+ }
String permalink = data.getString(JSONUtils.PERMALINK_KEY);
int score = data.getInt(JSONUtils.SCORE_KEY);
long submitTime = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index b2fbb420..caebd825 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -135,7 +135,6 @@ class ParsePost {
} else {
postData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
}
- postData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
bestPostData.add(postData);
} else {
//No preview link post