mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +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.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -52,13 +51,10 @@ public class BlogFragment extends BaseFragment
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@Nullable
|
|
||||||
private Parcelable layoutManagerState;
|
|
||||||
|
|
||||||
private GroupId groupId;
|
private GroupId groupId;
|
||||||
private BlogViewModel viewModel;
|
private BlogViewModel viewModel;
|
||||||
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
||||||
private LayoutManager layoutManager;
|
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
|
|
||||||
static BlogFragment newInstance(GroupId groupId) {
|
static BlogFragment newInstance(GroupId groupId) {
|
||||||
@@ -91,7 +87,7 @@ public class BlogFragment extends BaseFragment
|
|||||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||||
|
|
||||||
list = v.findViewById(R.id.postList);
|
list = v.findViewById(R.id.postList);
|
||||||
layoutManager = new LinearLayoutManager(getActivity());
|
LayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||||
list.setLayoutManager(layoutManager);
|
list.setLayoutManager(layoutManager);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.showProgressBar();
|
list.showProgressBar();
|
||||||
@@ -104,12 +100,6 @@ public class BlogFragment extends BaseFragment
|
|||||||
viewModel.getBlogRemoved().observe(getViewLifecycleOwner(), removed -> {
|
viewModel.getBlogRemoved().observe(getViewLifecycleOwner(), removed -> {
|
||||||
if (removed) finish();
|
if (removed) finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
layoutManagerState =
|
|
||||||
savedInstanceState.getParcelable("layoutManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,15 +118,6 @@ public class BlogFragment extends BaseFragment
|
|||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
if (layoutManager != null) {
|
|
||||||
layoutManagerState = layoutManager.onSaveInstanceState();
|
|
||||||
outState.putParcelable("layoutManager", layoutManagerState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
||||||
@@ -208,12 +189,6 @@ public class BlogFragment extends BaseFragment
|
|||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
list.showData();
|
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.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -48,8 +47,6 @@ public class FeedFragment extends BaseFragment
|
|||||||
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
private final BlogPostAdapter adapter = new BlogPostAdapter(this);
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
@Nullable
|
|
||||||
private Parcelable layoutManagerState;
|
|
||||||
|
|
||||||
public static FeedFragment newInstance() {
|
public static FeedFragment newInstance() {
|
||||||
FeedFragment f = new FeedFragment();
|
FeedFragment f = new FeedFragment();
|
||||||
@@ -93,11 +90,6 @@ public class FeedFragment extends BaseFragment
|
|||||||
.onSuccess(this::onBlogPostsLoaded)
|
.onSuccess(this::onBlogPostsLoaded)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
layoutManagerState =
|
|
||||||
savedInstanceState.getParcelable("layoutManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,15 +108,6 @@ public class FeedFragment extends BaseFragment
|
|||||||
list.stopPeriodicUpdate();
|
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) {
|
private void onBlogPostsLoaded(List<BlogPostItem> items) {
|
||||||
if (items.isEmpty()) list.showData();
|
if (items.isEmpty()) list.showData();
|
||||||
else adapter.submitList(items, () -> {
|
else adapter.submitList(items, () -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user