diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index c95971b0..0df26fb0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -540,6 +540,8 @@ public class TopicActivity extends BaseActivity { private static final int OTHER_ERROR = 2; private static final int SAME_PAGE = 3; + ArrayList localPostsList; + @Override protected void onPreExecute() { progressBar.setVisibility(ProgressBar.VISIBLE); @@ -593,7 +595,7 @@ public class TopicActivity extends BaseActivity { try { Response response = client.newCall(request).execute(); document = Jsoup.parse(response.body().string()); - parse(document); + localPostsList = parse(document); return SUCCESS; } catch (IOException e) { Timber.i(e, "IO Exception"); @@ -623,12 +625,19 @@ public class TopicActivity extends BaseActivity { invalidateOptionsMenu(); } + if (!(postsList.isEmpty() || postsList.size() == 0)){ + recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug + postsList.clear(); + topicAdapter.notifyItemRangeRemoved(0, postsList.size()-1); + } + postsList.addAll(localPostsList); + topicAdapter.notifyItemRangeInserted(0, postsList.size()); progressBar.setVisibility(ProgressBar.INVISIBLE); - recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug + if (replyPageUrl == null) { replyFAB.hide(); - topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); - } else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); + topicAdapter.resetTopic(new TopicTask(), false); + } else topicAdapter.resetTopic(new TopicTask(), true); if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); @@ -645,8 +654,8 @@ public class TopicActivity extends BaseActivity { progressBar.setVisibility(ProgressBar.INVISIBLE); if (replyPageUrl == null) { replyFAB.hide(); - topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); - } else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); + topicAdapter.resetTopic(new TopicTask(), false); + } else topicAdapter.resetTopic(new TopicTask(), true); if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); paginationEnabled(true); Toast.makeText(TopicActivity.this, "That's the same page.", Toast.LENGTH_SHORT).show(); @@ -667,7 +676,7 @@ public class TopicActivity extends BaseActivity { * @param topic {@link Document} object containing this topic's source code * @see org.jsoup.Jsoup Jsoup */ - private void parse(Document topic) { + private ArrayList parse(Document topic) { ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); //Finds topic's tree, mods and users viewing @@ -709,10 +718,7 @@ public class TopicActivity extends BaseActivity { } } - postsList.clear(); - topicAdapter.notifyItemRangeRemoved(0, postsList.size()); - recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug - postsList.addAll(TopicParser.parseTopic(topic, language)); + return TopicParser.parseTopic(topic, language); } private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 6fd1a57c..55663d9d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -471,7 +471,7 @@ class TopicAdapter extends RecyclerView.Adapter { } } - void customNotifyDataSetChanged(TopicActivity.TopicTask topicTask, boolean canReply) { + void resetTopic(TopicActivity.TopicTask topicTask, boolean canReply) { this.topicTask = topicTask; this.canReply = canReply; viewProperties.clear(); @@ -479,8 +479,6 @@ class TopicAdapter extends RecyclerView.Adapter { //Initializes properties, array's values will be false by default viewProperties.add(new boolean[3]); } - notifyItemRangeInserted(0, postsList.size()); - //notifyDataSetChanged(); } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java index 0d336ae3..d82e349b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -34,8 +34,8 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 - && dyUnconsumed < 40)) && child.getVisibility() == View.VISIBLE) { + if (child.getVisibility() == View.VISIBLE && (dyConsumed > 0 + || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed > 50))) { child.hide(new FloatingActionButton.OnVisibilityChangedListener() { @Override public void onHidden(FloatingActionButton fab) { @@ -43,7 +43,8 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior int dxUnconsumed, int dyUnconsumed, int type) { super.onNestedScroll(coordinatorLayout, bottomNavBar, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type); - if ((dyConsumed > 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 - && dyUnconsumed < 40)) && bottomNavBar.getVisibility() == View.VISIBLE) { + if (bottomNavBar.getVisibility() == View.VISIBLE && (dyConsumed > 0 + || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed > 50))) { hide(bottomNavBar); - } else if (dyConsumed < 0 && bottomNavBar.getVisibility() != View.VISIBLE) { + } else if (bottomNavBar.getVisibility() == View.INVISIBLE && (dyConsumed < 0 + || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed < -50))) { show(bottomNavBar); } }