diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index 46a452d5..f8cc7ba2 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -15,6 +15,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -23,6 +24,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -67,18 +69,6 @@ public class HomeTopFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home_top, container, false); - ArrayList 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; } @@ -86,6 +76,18 @@ public class HomeTopFragment extends Fragment { public void onViewCreated(View view, Bundle 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); Toolbar toolbar = view.findViewById(R.id.toolbar);