diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java index f0623ea29..9484f599b 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java @@ -98,7 +98,6 @@ public class Status implements Serializable, Cloneable { public boolean isExpended = false; public boolean isTruncated = true; public boolean isFetchMore = false; - public boolean isFetchMoreHidden = false; public boolean isMediaDisplayed = false; public boolean isMediaObfuscated = true; public boolean isChecked = false; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ContextAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ContextAdapter.java index a176902a7..b0c7fbea9 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ContextAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ContextAdapter.java @@ -72,7 +72,7 @@ public class ContextAdapter extends RecyclerView.Adapter notificationList) { @@ -81,9 +79,6 @@ public class NotificationAdapter extends RecyclerView.Adapter { - if (position + 1 < notificationList.size()) { - //We hide the button - notification.isFetchMoreHidden = true; + if (notification.isFetchMore && fetchMoreCallBack != null) { + holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); + holderFollow.binding.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { + notification.isFetchMore = false; notifyItemChanged(position); - fetchMoreCallBack.onClickMin(notificationList.get(position + 1).id, notification.id); - } - }); - holder.bindingFetchMore.fetchMoreMax.setOnClickListener(v -> { - if (position - 1 >= 0) { + fetchMoreCallBack.onClickMinId(notification.id); + }); + holderFollow.binding.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { //We hide the button - notification.isFetchMoreHidden = true; + notification.isFetchMore = false; notifyItemChanged(position); - fetchMoreCallBack.onClickMax(notificationList.get(position - 1).id, notification.id); - } - }); + fetchMoreCallBack.onClickMaxId(notification.id); + }); + } else { + holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); + } } else { StatusAdapter.StatusViewHolder holderStatus = (StatusAdapter.StatusViewHolder) viewHolder; holderStatus.bindingNotification.status.typeOfNotification.setVisibility(View.VISIBLE); @@ -202,7 +191,7 @@ public class NotificationAdapter extends RecyclerView.Adapter public static final int STATUS_HIDDEN = 0; public static final int STATUS_VISIBLE = 1; public static final int STATUS_ART = 2; - public static final int STATUS_FETCH_MORE = 3; private final List statusList; private final boolean minified; private final Timeline.TimeLineEnum timelineType; @@ -322,7 +321,8 @@ public class StatusAdapter extends RecyclerView.Adapter List statusList, Status status, Timeline.TimeLineEnum timelineType, - boolean minified, boolean canBeFederated) { + boolean minified, boolean canBeFederated, + FetchMoreCallBack fetchMoreCallBack) { if (status == null) { return; } @@ -1868,6 +1868,51 @@ public class StatusAdapter extends RecyclerView.Adapter holder.bindingReport.checkbox.setOnClickListener(v -> status.isChecked = !status.isChecked); } + if (status.isFetchMore && fetchMoreCallBack != null) { + holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); + holder.binding.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { + status.isFetchMore = false; + adapter.notifyItemChanged(holder.getBindingAdapterPosition()); + fetchMoreCallBack.onClickMinId(status.id); + if (!remote) { + new Thread(() -> { + StatusCache statusCache = new StatusCache(); + statusCache.instance = BaseMainActivity.currentInstance; + statusCache.user_id = BaseMainActivity.currentUserID; + statusCache.status = status; + statusCache.status_id = status.id; + try { + new StatusCache(context).updateIfExists(statusCache); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } + }); + holder.binding.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { + //We hide the button + status.isFetchMore = false; + adapter.notifyItemChanged(holder.getBindingAdapterPosition()); + if (!remote) { + new Thread(() -> { + StatusCache statusCache = new StatusCache(); + statusCache.instance = BaseMainActivity.currentInstance; + statusCache.user_id = BaseMainActivity.currentUserID; + statusCache.status = status; + statusCache.status_id = status.id; + try { + new StatusCache(context).updateIfExists(statusCache); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } + fetchMoreCallBack.onClickMaxId(status.id); + }); + } else { + holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); + } + } private static boolean mediaObfuscated(Status status) { @@ -1911,8 +1956,6 @@ public class StatusAdapter extends RecyclerView.Adapter public int getItemViewType(int position) { if (timelineType == Timeline.TimeLineEnum.ART) { return STATUS_ART; - } else if (statusList.get(position).isFetchMore) { - return STATUS_FETCH_MORE; } else { return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN; } @@ -1928,9 +1971,6 @@ public class StatusAdapter extends RecyclerView.Adapter } else if (viewType == STATUS_ART) { //Art statuses DrawerStatusArtBinding itemBinding = DrawerStatusArtBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); return new StatusViewHolder(itemBinding); - } else if (viewType == STATUS_FETCH_MORE) { //Fetch more button - DrawerFetchMoreBinding itemBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); } else { //Classic statuses if (!minified) { DrawerStatusBinding itemBinding = DrawerStatusBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); @@ -1966,7 +2006,7 @@ public class StatusAdapter extends RecyclerView.Adapter StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); - statusManagement(context, statusesVM, searchVM, holder, this, statusList, status, timelineType, minified, canBeFederated); + statusManagement(context, statusesVM, searchVM, holder, this, statusList, status, timelineType, minified, canBeFederated, fetchMoreCallBack); } else if (viewHolder.getItemViewType() == STATUS_ART) { StatusViewHolder holder = (StatusViewHolder) viewHolder; MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account); @@ -2007,25 +2047,6 @@ public class StatusAdapter extends RecyclerView.Adapter intent.putExtra(Helper.ARG_STATUS, status); context.startActivity(intent); }); - } else if (viewHolder.getItemViewType() == STATUS_FETCH_MORE) { - StatusViewHolder holder = (StatusViewHolder) viewHolder; - holder.bindingFetchMore.fetchMoreContainer.setEnabled(!status.isFetchMoreHidden); - holder.bindingFetchMore.fetchMoreMin.setOnClickListener(v -> { - if (position + 1 < statusList.size()) { - //We hide the button - status.isFetchMoreHidden = true; - notifyItemChanged(position); - fetchMoreCallBack.onClickMinId(statusList.get(position + 1).id, status.id); - } - }); - holder.bindingFetchMore.fetchMoreMax.setOnClickListener(v -> { - if (position - 1 >= 0) { - //We hide the button - status.isFetchMoreHidden = true; - notifyItemChanged(position); - fetchMoreCallBack.onClickMaxId(statusList.get(position - 1).id, status.id); - } - }); } } @@ -2040,9 +2061,9 @@ public class StatusAdapter extends RecyclerView.Adapter } public interface FetchMoreCallBack { - void onClickMinId(String min_id, String fetchmoreId); + void onClickMinId(String min_id); - void onClickMaxId(String max_id, String fetchmoreId); + void onClickMaxId(String max_id); } public static class StatusViewHolder extends RecyclerView.ViewHolder { @@ -2075,10 +2096,6 @@ public class StatusAdapter extends RecyclerView.Adapter bindingHidden = itemView; } - StatusViewHolder(DrawerFetchMoreBinding itemView) { - super(itemView.getRoot()); - bindingFetchMore = itemView; - } StatusViewHolder(DrawerStatusArtBinding itemView) { super(itemView.getRoot()); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index 74e989c9e..f13584c49 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -48,10 +48,11 @@ import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.MastodonHelper; import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.ui.drawer.NotificationAdapter; +import app.fedilab.android.ui.drawer.StatusAdapter; import app.fedilab.android.viewmodel.mastodon.NotificationsVM; -public class FragmentMastodonNotification extends Fragment implements NotificationAdapter.FetchMoreCallBack { +public class FragmentMastodonNotification extends Fragment implements StatusAdapter.FetchMoreCallBack { private static final int NOTIFICATION_PRESENT = -1; @@ -86,7 +87,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati }; private String max_id, min_id, min_id_fetch_more, max_id_fetch_more; private LinearLayoutManager mLayoutManager; - private String instance, user_id; private ArrayList idOfAddedNotifications; private NotificationTypeEnum notificationType; private List excludeType; @@ -115,8 +115,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati ViewGroup container, Bundle savedInstanceState) { flagLoading = false; - instance = BaseMainActivity.currentInstance; - user_id = BaseMainActivity.currentUserID; idOfAddedNotifications = new ArrayList<>(); binding = FragmentPaginationBinding.inflate(inflater, container, false); View root = binding.getRoot(); @@ -456,43 +454,18 @@ public class FragmentMastodonNotification extends Fragment implements Notificati super.onPause(); } + @Override - public void onClickMin(String min_id, String id) { + public void onClickMinId(String min_id) { //Fetch more has been pressed min_id_fetch_more = min_id; - Notification notification = null; - int position = 0; - for (Notification currentNotification : this.notificationList) { - if (currentNotification.id.compareTo(id) == 0) { - notification = currentNotification; - break; - } - position++; - } - if (notification != null) { - this.notificationList.remove(position); - notificationAdapter.notifyItemRemoved(position); - } route(FragmentMastodonTimeline.DIRECTION.TOP, true); } @Override - public void onClickMax(String max_id, String id) { + public void onClickMaxId(String max_id) { //Fetch more has been pressed max_id_fetch_more = max_id; - Notification notification = null; - int position = 0; - for (Notification currentNotification : this.notificationList) { - if (currentNotification.id.compareTo(id) == 0) { - notification = currentNotification; - break; - } - position++; - } - if (notification != null) { - this.notificationList.remove(position); - notificationAdapter.notifyItemRemoved(position); - } route(FragmentMastodonTimeline.DIRECTION.BOTTOM, true); } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 16b58c578..892427bcf 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -829,41 +829,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } @Override - public void onClickMinId(String min_id, String id) { + public void onClickMinId(String min_id) { //Fetch more has been pressed min_id_fetch_more = min_id; - Status status = null; - int position = 0; - for (Status currentStatus : timelineStatuses) { - if (currentStatus.id.compareTo(id) == 0) { - status = currentStatus; - break; - } - position++; - } - if (status != null) { - timelineStatuses.remove(position); - statusAdapter.notifyItemRemoved(position); - } route(DIRECTION.TOP, true); } @Override - public void onClickMaxId(String max_id, String id) { + public void onClickMaxId(String max_id) { max_id_fetch_more = max_id; - Status status = null; - int position = 0; - for (Status currentStatus : timelineStatuses) { - if (currentStatus.id.compareTo(id) == 0) { - status = currentStatus; - break; - } - position++; - } - if (status != null) { - timelineStatuses.remove(position); - statusAdapter.notifyItemRemoved(position); - } route(DIRECTION.BOTTOM, true); } diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index 72c74937d..98f96a323 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -346,24 +346,15 @@ public class TimelinesVM extends AndroidViewModel { if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP) { //When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole if (statusList.get(statusList.size() - 1).id.compareToIgnoreCase(timelineStatuses.get(0).id) > 0) { - Status statusFetchMore = new Status(); - statusFetchMore.isFetchMore = true; - statusFetchMore.id = Helper.generateString(); - statusList.add(statusFetchMore); + statusList.get(statusList.size() - 1).isFetchMore = true; } } else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.TOP && timelineParams.fetchingMissing) { if (!timelineStatuses.contains(statusList.get(0))) { - Status statusFetchMore = new Status(); - statusFetchMore.isFetchMore = true; - statusFetchMore.id = Helper.generateString(); - statusList.add(0, statusFetchMore); + statusList.get(0).isFetchMore = true; } } else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.BOTTOM && timelineParams.fetchingMissing) { if (!timelineStatuses.contains(statusList.get(statusList.size() - 1))) { - Status statusFetchMore = new Status(); - statusFetchMore.isFetchMore = true; - statusFetchMore.id = Helper.generateString(); - statusList.add(statusFetchMore); + statusList.get(statusList.size() - 1).isFetchMore = true; } } } diff --git a/app/src/main/res/layout/drawer_follow.xml b/app/src/main/res/layout/drawer_follow.xml index 6a7c31c3d..3d17f2b2c 100644 --- a/app/src/main/res/layout/drawer_follow.xml +++ b/app/src/main/res/layout/drawer_follow.xml @@ -117,6 +117,12 @@ + + diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index be56c4a01..e97591b1a 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -648,6 +648,11 @@ +