Browse Source

Fixes for inconsistency detected bug

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
1284b7c64e
  1. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 18
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  4. 38
      app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java

3
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -303,8 +303,5 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
boardAdapter.notifyDataSetChanged(); boardAdapter.notifyDataSetChanged();
isLoadingMore = false; isLoadingMore = false;
} }
} }
} }

18
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -10,7 +10,6 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
@ -49,6 +48,7 @@ import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.utils.CustomLinearLayoutManager;
import gr.thmmy.mthmmy.utils.ParseHelpers; import gr.thmmy.mthmmy.utils.ParseHelpers;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
@ -168,7 +168,17 @@ public class TopicActivity extends BaseActivity {
recyclerView = (RecyclerView) findViewById(R.id.topic_recycler_view); recyclerView = (RecyclerView) findViewById(R.id.topic_recycler_view);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); recyclerView.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return topicTask != null && topicTask.getStatus() == AsyncTask.Status.RUNNING;
}
}
);
//LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(
getApplicationContext(), loadedPageUrl);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
topicAdapter = new TopicAdapter(this, postsList, topicTask); topicAdapter = new TopicAdapter(this, postsList, topicTask);
recyclerView.setAdapter(topicAdapter); recyclerView.setAdapter(topicAdapter);
@ -551,6 +561,7 @@ public class TopicActivity extends BaseActivity {
} }
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
if (replyPageUrl == null) { if (replyPageUrl == null) {
replyFAB.hide(); replyFAB.hide();
topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); topicAdapter.customNotifyDataSetChanged(new TopicTask(), false);
@ -636,6 +647,9 @@ public class TopicActivity extends BaseActivity {
} }
postsList.clear(); postsList.clear();
int oldSize = postsList.size();
topicAdapter.notifyItemRangeRemoved(0, oldSize);
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
postsList.addAll(TopicParser.parseTopic(topic, language)); postsList.addAll(TopicParser.parseTopic(topic, language));
} }

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

@ -172,7 +172,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@SuppressLint({"SetJavaScriptEnabled", "SetTextI18n"}) @SuppressLint({"SetJavaScriptEnabled", "SetTextI18n"})
@Override @Override
public void onBindViewHolder(final RecyclerView.ViewHolder currentHolder, final int position) { public void onBindViewHolder(final RecyclerView.ViewHolder currentHolder,
final int position) {
if (currentHolder instanceof PostViewHolder) { if (currentHolder instanceof PostViewHolder) {
final Post currentPost = postsList.get(position); final Post currentPost = postsList.get(position);
final PostViewHolder holder = (PostViewHolder) currentHolder; final PostViewHolder holder = (PostViewHolder) currentHolder;
@ -478,7 +479,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
//Initializes properties, array's values will be false by default //Initializes properties, array's values will be false by default
viewProperties.add(new boolean[3]); viewProperties.add(new boolean[3]);
} }
notifyDataSetChanged(); notifyItemRangeInserted(0, postsList.size());
//notifyDataSetChanged();
} }
@Override @Override

38
app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java

@ -0,0 +1,38 @@
package gr.thmmy.mthmmy.utils;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import timber.log.Timber;
public class CustomLinearLayoutManager extends LinearLayoutManager {
private String pageUrl;
public CustomLinearLayoutManager(Context context, String pageUrl) {
super(context);
this.pageUrl = pageUrl;
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (IndexOutOfBoundsException e) {
Timber.wtf(e, "Inconsistency detected: topic_requested = \"" + pageUrl + "\"");
Log.d("CustomLinearLayoutMan", "Inconsistency detected: topic_requested = \""
+ pageUrl + "\"", e);
}
}
/**
* Disable predictive animations. There is a bug in RecyclerView which causes views that
* are being reloaded to pull invalid ViewHolders from the internal recycler stack if the
* adapter size has decreased since the ViewHolder was recycled.
*/
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
}
Loading…
Cancel
Save