Browse Source

Avoid autoscrolling downwards when changing from/to some topic pages

pull/70/head
Ezerous 5 years ago
parent
commit
acd1de7769
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 18
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

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

@ -83,6 +83,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE"; public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE";
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private TextView toolbarTitle; private TextView toolbarTitle;
private CustomLinearLayoutManager layoutManager;
private RecyclerView recyclerView; private RecyclerView recyclerView;
//Posts related //Posts related
private TopicAdapter topicAdapter; private TopicAdapter topicAdapter;
@ -181,7 +182,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
recyclerView = findViewById(R.id.topic_recycler_view); recyclerView = findViewById(R.id.topic_recycler_view);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
//LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); //LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager( layoutManager = new CustomLinearLayoutManager(
getApplicationContext(), topicPageUrl); getApplicationContext(), topicPageUrl);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
@ -691,12 +692,19 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
} }
}); });
viewModel.getTopicItems().observe(this, postList -> { viewModel.getTopicItems().observe(this, postList -> {
if (postList == null) progressBar.setVisibility(ProgressBar.VISIBLE); if (postList == null)
progressBar.setVisibility(ProgressBar.VISIBLE);
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
recyclerView.scrollToPosition(0);
topicItems.clear(); topicItems.clear();
topicItems.addAll(postList);
topicAdapter.notifyDataSetChanged(); /* A workaround to avoid automatic scrolling when a new page
page is loaded (it happens sometimes only)*/
recyclerView.setAdapter(topicAdapter);
if (postList != null) {
topicItems.addAll(postList);
topicAdapter.notifyDataSetChanged();
}
}); });
/*viewModel.getFocusedPostIndex().observe(this, focusedPostIndex -> { /*viewModel.getFocusedPostIndex().observe(this, focusedPostIndex -> {
if (focusedPostIndex == null) return; if (focusedPostIndex == null) return;

Loading…
Cancel
Save