1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-16 11:47:29 +00:00

Auto fetch more chats if loaded chats don't fill the view

This commit is contained in:
Ammar Githam 2021-01-03 19:19:36 +09:00
parent ff296c3bfc
commit be53864f02

View File

@ -560,8 +560,22 @@ public class DirectMessageThreadFragment extends Fragment {
appStateViewModel.getCurrentUser().observe(getViewLifecycleOwner(), currentUser -> {
viewModel.setCurrentUser(currentUser);
setupItemsAdapter(currentUser);
viewModel.getItems().observe(getViewLifecycleOwner(),
list -> itemsAdapter.submitList(list, () -> itemOrHeaders = itemsAdapter.getList()));
viewModel.getItems().observe(
getViewLifecycleOwner(),
list -> itemsAdapter.submitList(list, () -> {
itemOrHeaders = itemsAdapter.getList();
binding.chats.post(() -> {
final RecyclerView.LayoutManager layoutManager = binding.chats.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
final int position = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
if (position < 0) return;
if (position == itemsAdapter.getItemCount() - 1) {
viewModel.fetchChats();
}
}
});
})
);
});
final NavController navController = NavHostFragment.findNavController(this);
final NavBackStackEntry backStackEntry = navController.getCurrentBackStackEntry();