mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Don't use layoutManager hack to restore scrolling position of blogs
not needed anymore when posts are cached in viewmodels
This commit is contained in:
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.blog;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -52,13 +51,10 @@ public class BlogFragment extends BaseFragment
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@Nullable
|
||||
private Parcelable layoutManagerState;
|
||||
|
||||
private GroupId groupId;
|
||||
private BlogViewModel viewModel;
|
||||
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
||||
private LayoutManager layoutManager;
|
||||
private BriarRecyclerView list;
|
||||
|
||||
static BlogFragment newInstance(GroupId groupId) {
|
||||
@@ -91,7 +87,7 @@ public class BlogFragment extends BaseFragment
|
||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||
|
||||
list = v.findViewById(R.id.postList);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
LayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
list.setLayoutManager(layoutManager);
|
||||
list.setAdapter(adapter);
|
||||
list.showProgressBar();
|
||||
@@ -104,12 +100,6 @@ public class BlogFragment extends BaseFragment
|
||||
viewModel.getBlogRemoved().observe(getViewLifecycleOwner(), removed -> {
|
||||
if (removed) finish();
|
||||
});
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
layoutManagerState =
|
||||
savedInstanceState.getParcelable("layoutManager");
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -128,15 +118,6 @@ public class BlogFragment extends BaseFragment
|
||||
list.stopPeriodicUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (layoutManager != null) {
|
||||
layoutManagerState = layoutManager.onSaveInstanceState();
|
||||
outState.putParcelable("layoutManager", layoutManagerState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
||||
@@ -208,12 +189,6 @@ public class BlogFragment extends BaseFragment
|
||||
true);
|
||||
}
|
||||
list.showData();
|
||||
if (layoutManagerState == null) {
|
||||
list.scrollToPosition(0);
|
||||
} else {
|
||||
layoutManager.onRestoreInstanceState(
|
||||
layoutManagerState);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.blog;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -48,8 +47,6 @@ public class FeedFragment extends BaseFragment
|
||||
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
||||
private LinearLayoutManager layoutManager;
|
||||
private BriarRecyclerView list;
|
||||
@Nullable
|
||||
private Parcelable layoutManagerState;
|
||||
|
||||
public static FeedFragment newInstance() {
|
||||
FeedFragment f = new FeedFragment();
|
||||
@@ -93,11 +90,6 @@ public class FeedFragment extends BaseFragment
|
||||
.onSuccess(this::onBlogPostsLoaded)
|
||||
);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
layoutManagerState =
|
||||
savedInstanceState.getParcelable("layoutManager");
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -116,15 +108,6 @@ public class FeedFragment extends BaseFragment
|
||||
list.stopPeriodicUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (layoutManager != null) {
|
||||
layoutManagerState = layoutManager.onSaveInstanceState();
|
||||
outState.putParcelable("layoutManager", layoutManagerState);
|
||||
}
|
||||
}
|
||||
|
||||
private void onBlogPostsLoaded(List<BlogPostItem> items) {
|
||||
if (items.isEmpty()) list.showData();
|
||||
else adapter.submitList(items, () -> {
|
||||
|
||||
Reference in New Issue
Block a user