aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-22 09:16:31 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-22 09:16:31 +0000
commitd864ec6d7fa92d18a5d4482fb50907c03f7731a5 (patch)
tree8bf3e79fde80f3ff9c4d8b131de5b81ba49ddd22 /app/src/main
parentd4fc671605df4d7e25a84a47fcc12d3a1d7423e3 (diff)
downloadinfinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar.gz
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar.bz2
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar.lz
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar.xz
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.tar.zst
infinity-for-reddit-d864ec6d7fa92d18a5d4482fb50907c03f7731a5.zip
Fixed bug that updating wrong post when PostFragment receives PostUpdateEventToPostList.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java2
2 files changed, 14 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 8ffbfe3a..cade1c5a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -25,6 +25,7 @@ import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
+import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
@@ -437,16 +438,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
- Post post = mAdapter.getCurrentList().get(event.positionInList);
- if(post != null) {
- post.setTitle(event.post.getTitle());
- post.setVoteType(event.post.getVoteType());
- post.setScore(event.post.getScore());
- post.setNSFW(event.post.isNSFW());
- post.setSpoiler(event.post.isSpoiler());
- post.setFlair(event.post.getFlair());
- post.setSaved(event.post.isSaved());
- mAdapter.notifyItemChanged(event.positionInList);
+ PagedList<Post> posts = mAdapter.getCurrentList();
+ if (posts != null && event.positionInList >= 0 && event.positionInList < posts.size()) {
+ Post post = posts.get(event.positionInList);
+ if (post != null && post.getFullName().equals(event.post.getFullName())) {
+ post.setTitle(event.post.getTitle());
+ post.setVoteType(event.post.getVoteType());
+ post.setScore(event.post.getScore());
+ post.setNSFW(event.post.isNSFW());
+ post.setSpoiler(event.post.isSpoiler());
+ post.setFlair(event.post.getFlair());
+ post.setSaved(event.post.isSaved());
+ mAdapter.notifyItemChanged(event.positionInList);
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 08cad105..9659d620 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -6,7 +6,6 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -300,7 +299,6 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mPost = getIntent().getParcelableExtra(EXTRA_POST_DATA);
}
- Log.i("asdfasdfadfadf", "" + mPost.isSaved());
if(mPost == null) {
fetchPostAndCommentsById(getIntent().getStringExtra(EXTRA_POST_ID));
} else {