遅れて追加されたアイテムをUIに反映できるように

This commit is contained in:
r-ca 2024-01-20 23:49:13 +09:00
parent aaff0be438
commit 12ba9234a4
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -15,6 +15,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -23,6 +24,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject; import javax.inject.Inject;
@ -67,18 +69,6 @@ public class HomeTopFragment extends Fragment {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home_top, container, false); View view = inflater.inflate(R.layout.fragment_home_top, container, false);
ArrayList<ListItem> recentDocument = lacertaLibrary.getRecentDocument(10);
Log.d("docs", Integer.toString(recentDocument.size()));
RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ListItemAdapter listItemAdapter = new ListItemAdapter(recentDocument);
recyclerView.setAdapter(listItemAdapter);
return view; return view;
} }
@ -86,6 +76,18 @@ public class HomeTopFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view);
recyclerView.setItemAnimator(new DefaultItemAnimator());
ListItemAdapter listItemAdapter = new ListItemAdapter();
recyclerView.setAdapter(listItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
lacertaLibrary.getRecentDocument(10).thenAccept(listItems -> {
listItemAdapter.setListItems(listItems);
getActivity().runOnUiThread(listItemAdapter::notifyDataSetChanged);
});
CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar); CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
Toolbar toolbar = view.findViewById(R.id.toolbar); Toolbar toolbar = view.findViewById(R.id.toolbar);