Resume時に更新されるように

This commit is contained in:
r-ca 2024-01-23 04:27:20 +09:00
parent 09c6d47a47
commit 06771d2e74
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -51,6 +51,8 @@ public class HomeTopFragment extends Fragment {
@Inject @Inject
LacertaLibrary lacertaLibrary; LacertaLibrary lacertaLibrary;
private ListItemAdapter listItemAdapter;
public HomeTopFragment() { public HomeTopFragment() {
// Required empty public constructor // Required empty public constructor
} }
@ -85,7 +87,7 @@ public class HomeTopFragment extends Fragment {
Toolbar toolbar = view.findViewById(R.id.home_toolbar); Toolbar toolbar = view.findViewById(R.id.home_toolbar);
toolbarSetup(toolbar, false, "ホーム"); toolbarSetup(toolbar, false, "ホーム");
ListItemAdapter listItemAdapter = new ListItemAdapter(new DocumentSelectListener() { this.listItemAdapter = new ListItemAdapter(new DocumentSelectListener() {
@Override @Override
public void onDocumentSelect(String documentId, String documentName) { public void onDocumentSelect(String documentId, String documentName) {
Intent intent = new Intent(getContext(), ViewerMainActivity.class); Intent intent = new Intent(getContext(), ViewerMainActivity.class);
@ -98,18 +100,29 @@ public class HomeTopFragment extends Fragment {
recyclerView.setAdapter(listItemAdapter); recyclerView.setAdapter(listItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
updateList();
}
@Override
public void onResume() {
super.onResume();
updateList();
}
private void updateList() {
lacertaLibrary.getRecentDocument(10).thenAccept(listItems -> { lacertaLibrary.getRecentDocument(10).thenAccept(listItems -> {
if (listItems == null) { if (listItems == null) {
return; return;
} }
listItemAdapter.setListItems(listItems); this.listItemAdapter.setListItems(listItems);
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
Log.d("HomeTopFragment", "onViewCreated: " + listItems.size()); Log.d("HomeTopFragment", "onViewCreated: " + listItems.size());
if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) { if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) {
listItemAdapter.notifyDataSetChanged(); this.listItemAdapter.notifyDataSetChanged();
} else { } else {
// IndexOutOfBoundsExceptionを吐くことがあったので いったん // IndexOutOfBoundsExceptionを吐くことがあったので いったん
listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1); this.listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1);
} }
}); });
}); });