diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java index cfdf431..02069ad 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java @@ -130,7 +130,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter 0) { + int previousPosition = this.accounts.size(); int currentPosition = this.accounts.size(); this.accounts.addAll(accounts); - accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size()); + if (previousPosition == 0) { + accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts); + accountsListAdapter.allAccountsRemoved = this; + lv_accounts.setAdapter(accountsListAdapter); + } else + accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size()); } swipeRefreshLayout.setRefreshing(false); firstLoad = false; @@ -206,7 +204,6 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda accounts = new ArrayList<>(); firstLoad = true; flag_loading = true; - swiped = true; swipeRefreshLayout.setRefreshing(true); AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class); viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, null).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts); diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayChannelsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayChannelsFragment.java index c4a9e10..8b59547 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayChannelsFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayChannelsFragment.java @@ -63,7 +63,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; private SwipeRefreshLayout swipeRefreshLayout; private String name; - private boolean swiped; private RecyclerView lv_channels; private View rootView; private FloatingActionButton action_button; @@ -83,7 +82,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap myChannels = bundle.getBoolean("myChannels", true); } - swiped = false; swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); @@ -165,26 +163,25 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap if (apiResponse.getError() != null) { Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); - swiped = false; return; } List channels = apiResponse.getChannels(); - if (!swiped && (channels == null || channels.size() == 0)) + if ((channels == null || channels.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); else textviewNoAction.setVisibility(View.GONE); - if (swiped) { - channelListAdapter = new ChannelListAdapter(this.channels, myChannels); - channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this; - channelListAdapter.editAlertDialog = DisplayChannelsFragment.this; - lv_channels.setAdapter(channelListAdapter); - swiped = false; - } if (channels != null && channels.size() > 0) { int currentPosition = this.channels.size(); this.channels.addAll(channels); - channelListAdapter.notifyItemRangeChanged(currentPosition, channels.size()); + if (currentPosition == 0) { + channelListAdapter = new ChannelListAdapter(this.channels, myChannels); + channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this; + channelListAdapter.editAlertDialog = DisplayChannelsFragment.this; + lv_channels.setAdapter(channelListAdapter); + } else { + channelListAdapter.notifyItemRangeChanged(currentPosition, channels.size()); + } } swipeRefreshLayout.setRefreshing(false); } @@ -192,7 +189,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap public void pullToRefresh() { channels = new ArrayList<>(); - swiped = true; swipeRefreshLayout.setRefreshing(true); ChannelsVM viewModel = new ViewModelProvider(this).get(ChannelsVM.class); if (name != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java index 933f3d8..0d3dbcf 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java @@ -72,9 +72,9 @@ public class DisplayNotificationsFragment extends Fragment { private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; private boolean firstLoad; private SwipeRefreshLayout swipeRefreshLayout; - private boolean swiped; private RecyclerView lv_notifications; private View rootView; + private NotificationsVM viewModel; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -86,10 +86,10 @@ public class DisplayNotificationsFragment extends Fragment { max_id = "0"; firstLoad = true; flag_loading = true; - swiped = false; swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); + viewModel = new ViewModelProvider(this).get(NotificationsVM.class); lv_notifications = rootView.findViewById(R.id.lv_elements); lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); @@ -115,7 +115,6 @@ public class DisplayNotificationsFragment extends Fragment { if (firstVisibleItem + visibleItemCount == totalItemCount) { if (!flag_loading) { flag_loading = true; - NotificationsVM viewModel = new ViewModelProvider(DisplayNotificationsFragment.this).get(NotificationsVM.class); viewModel.getNotifications(null, max_id).observe(DisplayNotificationsFragment.this.requireActivity(), apiResponse -> manageVIewNotifications(apiResponse)); nextElementLoader.setVisibility(View.VISIBLE); } @@ -127,8 +126,7 @@ public class DisplayNotificationsFragment extends Fragment { }); swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh); - NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class); - viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); + viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); return rootView; } @@ -138,9 +136,22 @@ public class DisplayNotificationsFragment extends Fragment { rootView = null; } + + @Override + public void onPause() { + super.onPause(); + if (swipeRefreshLayout != null) { + swipeRefreshLayout.setEnabled(false); + swipeRefreshLayout.setRefreshing(false); + swipeRefreshLayout.clearAnimation(); + } + } + + @Override public void onResume() { super.onResume(); + swipeRefreshLayout.setEnabled(true); if (getActivity() != null && getActivity() != null) { View action_button = getActivity().findViewById(R.id.action_button); if (action_button != null) { @@ -172,15 +183,15 @@ public class DisplayNotificationsFragment extends Fragment { public void pullToRefresh() { - max_id = "0"; + int size = notifications.size(); + notifications.clear(); notifications = new ArrayList<>(); + max_id = "0"; + peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, size); firstLoad = true; flag_loading = true; - swiped = true; swipeRefreshLayout.setRefreshing(true); - NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class); - viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); - + viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); } private void manageVIewNotifications(APIResponse apiResponse) { @@ -190,28 +201,25 @@ public class DisplayNotificationsFragment extends Fragment { Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); flag_loading = false; swipeRefreshLayout.setRefreshing(false); - swiped = false; return; } int previousPosition = notifications.size(); max_id = String.valueOf(Integer.parseInt(max_id) + 20); List notifications = apiResponse.getPeertubeNotifications(); - if (!swiped && firstLoad && (notifications == null || notifications.size() == 0)) + if (firstLoad && (notifications == null || notifications.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); else textviewNoAction.setVisibility(View.GONE); - if (swiped) { - if (previousPosition > 0) { - this.notifications.subList(0, previousPosition).clear(); - peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, previousPosition); - } - swiped = false; - } + if (notifications != null && notifications.size() > 0) { this.notifications.addAll(notifications); - peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); + if (previousPosition == 0) { + peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications); + lv_notifications.setAdapter(peertubeNotificationsListAdapter); + } else + peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); } else { if (firstLoad) textviewNoAction.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java index 2bca763..9703835 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java @@ -245,6 +245,12 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta return rootView; } + @Override + public void onResume() { + super.onResume(); + swipeRefreshLayout.setEnabled(true); + } + @Override public void onPause() { @@ -434,11 +440,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta rootView = null; } - @Override - public void onResume() { - super.onResume(); - swipeRefreshLayout.setEnabled(true); - } public void scrollToTop() {