Browse Source

Fixes for inconsistency bug and reply disappearing in small topics

pull/24/head
Apostolos Fanakis 7 years ago
parent
commit
521ce49103
  1. 28
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 7
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java
  4. 7
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java

28
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<Post> 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<Post> 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) {

4
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -471,7 +471,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
}
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<RecyclerView.ViewHolder> {
//Initializes properties, array's values will be false by default
viewProperties.add(new boolean[3]);
}
notifyItemRangeInserted(0, postsList.size());
//notifyDataSetChanged();
}
@Override

7
app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java

@ -34,8 +34,8 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior<FloatingA
final int dxUnconsumed, final int dyUnconsumed, int type) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
dyUnconsumed, type);
if ((dyConsumed > 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<FloatingA
fab.setVisibility(View.INVISIBLE);
}
});
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
} else if (child.getVisibility() == View.INVISIBLE && (dyConsumed < 0
|| (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed < -50))) {
child.show();
}
}

7
app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java

@ -37,10 +37,11 @@ public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior<View>
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);
}
}

Loading…
Cancel
Save