2023-01-22 15:22:59 +01:00
|
|
|
package app.fedilab.android.mastodon.ui.fragment.timeline;
|
2022-04-27 15:20:42 +02:00
|
|
|
/* Copyright 2021 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Fedilab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
2024-01-11 17:05:35 +01:00
|
|
|
import static app.fedilab.android.BaseMainActivity.currentAccount;
|
|
|
|
|
2022-05-06 17:36:10 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
2023-03-13 18:09:48 +01:00
|
|
|
import android.os.Handler;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2022-11-02 18:37:29 +01:00
|
|
|
import androidx.annotation.Nullable;
|
2023-12-12 16:07:48 +01:00
|
|
|
import androidx.core.content.ContextCompat;
|
2022-04-27 15:20:42 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2022-12-13 16:28:26 +01:00
|
|
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import app.fedilab.android.BaseMainActivity;
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
2023-01-22 15:22:59 +01:00
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Notification;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Notifications;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Status;
|
2024-01-19 14:30:29 +01:00
|
|
|
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
2024-01-11 17:05:35 +01:00
|
|
|
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
|
2023-01-22 15:22:59 +01:00
|
|
|
import app.fedilab.android.mastodon.client.entities.app.StatusCache;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.Timeline;
|
|
|
|
import app.fedilab.android.mastodon.exception.DBException;
|
|
|
|
import app.fedilab.android.mastodon.helper.Helper;
|
|
|
|
import app.fedilab.android.mastodon.helper.MastodonHelper;
|
|
|
|
import app.fedilab.android.mastodon.ui.drawer.NotificationAdapter;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.NotificationsVM;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
|
2022-09-29 17:59:53 +02:00
|
|
|
public class FragmentMastodonNotification extends Fragment implements NotificationAdapter.FetchMoreCallBack {
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
private FragmentPaginationBinding binding;
|
|
|
|
private NotificationsVM notificationsVM;
|
|
|
|
private boolean flagLoading;
|
2022-06-19 19:24:42 +02:00
|
|
|
private List<Notification> notificationList;
|
2022-04-27 15:20:42 +02:00
|
|
|
private NotificationAdapter notificationAdapter;
|
2023-07-27 14:47:22 +02:00
|
|
|
private boolean isViewInitialized;
|
|
|
|
private Notifications initialNotifications;
|
|
|
|
private String max_id, min_id, min_id_fetch_more, max_id_fetch_more;
|
2022-05-06 17:36:10 +02:00
|
|
|
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2024-01-11 17:05:35 +01:00
|
|
|
Bundle args = intent.getExtras();
|
|
|
|
if (args != null) {
|
|
|
|
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
|
|
|
|
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
|
|
|
|
Status receivedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS_ACTION);
|
|
|
|
String delete_all_for_account_id = bundle.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID);
|
|
|
|
boolean refreshNotifications = bundle.getBoolean(Helper.ARG_REFRESH_NOTFICATION, false);
|
|
|
|
if (refreshNotifications) {
|
|
|
|
scrollToTop();
|
|
|
|
} else if (receivedStatus != null && notificationAdapter != null) {
|
|
|
|
int position = getPosition(receivedStatus);
|
|
|
|
if (position >= 0) {
|
|
|
|
if (notificationList.get(position).status != null) {
|
|
|
|
notificationList.get(position).status.reblog = receivedStatus.reblog;
|
|
|
|
notificationList.get(position).status.reblogged = receivedStatus.reblogged;
|
|
|
|
notificationList.get(position).status.favourited = receivedStatus.favourited;
|
|
|
|
notificationList.get(position).status.bookmarked = receivedStatus.bookmarked;
|
|
|
|
notificationList.get(position).status.favourites_count = receivedStatus.favourites_count;
|
|
|
|
notificationList.get(position).status.reblogs_count = receivedStatus.reblogs_count;
|
|
|
|
notificationAdapter.notifyItemChanged(position);
|
|
|
|
}
|
2022-05-06 17:36:10 +02:00
|
|
|
}
|
2024-01-11 17:05:35 +01:00
|
|
|
} else if (delete_all_for_account_id != null) {
|
|
|
|
List<Notification> toRemove = new ArrayList<>();
|
|
|
|
if (notificationList != null) {
|
|
|
|
for (int position = 0; position < notificationList.size(); position++) {
|
|
|
|
if (notificationList.get(position).account.id.equals(delete_all_for_account_id)) {
|
|
|
|
toRemove.add(notificationList.get(position));
|
|
|
|
}
|
2022-11-06 18:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-11 17:05:35 +01:00
|
|
|
if (toRemove.size() > 0) {
|
|
|
|
for (int i = 0; i < toRemove.size(); i++) {
|
|
|
|
int position = getPosition(toRemove.get(i));
|
|
|
|
notificationList.remove(position);
|
|
|
|
notificationAdapter.notifyItemRemoved(position);
|
|
|
|
}
|
2022-11-06 18:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-11 17:05:35 +01:00
|
|
|
});
|
2022-05-06 17:36:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-06-19 19:24:42 +02:00
|
|
|
private LinearLayoutManager mLayoutManager;
|
2022-05-24 10:12:04 +02:00
|
|
|
private NotificationTypeEnum notificationType;
|
|
|
|
private boolean aggregateNotification;
|
2023-03-13 18:09:48 +01:00
|
|
|
|
2023-01-22 15:22:59 +01:00
|
|
|
private final BroadcastReceiver receive_refresh = new BroadcastReceiver() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (notificationType != null && notificationType == NotificationTypeEnum.ALL) {
|
|
|
|
if (notificationList != null && notificationList.size() > 0) {
|
|
|
|
route(FragmentMastodonTimeline.DIRECTION.FETCH_NEW, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-05-06 17:36:10 +02:00
|
|
|
|
2022-11-14 18:47:14 +01:00
|
|
|
//Allow to recreate data when detaching/attaching fragment
|
|
|
|
public void recreate() {
|
|
|
|
initialNotifications = null;
|
|
|
|
if (notificationList != null && notificationList.size() > 0) {
|
|
|
|
int count = notificationList.size();
|
|
|
|
notificationList.clear();
|
|
|
|
notificationList = new ArrayList<>();
|
|
|
|
if (notificationAdapter != null) {
|
|
|
|
notificationAdapter.notifyItemRangeRemoved(0, count);
|
|
|
|
max_id = null;
|
|
|
|
flagLoading = false;
|
|
|
|
route(null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 17:36:10 +02:00
|
|
|
/**
|
|
|
|
* Return the position of the status in the ArrayList
|
|
|
|
*
|
|
|
|
* @param status - Status to fetch
|
|
|
|
* @return position or -1 if not found
|
|
|
|
*/
|
|
|
|
private int getPosition(Status status) {
|
|
|
|
int position = 0;
|
|
|
|
boolean found = false;
|
2022-06-19 19:24:42 +02:00
|
|
|
for (Notification _notification : notificationList) {
|
2022-05-06 17:36:10 +02:00
|
|
|
if (_notification.status != null && _notification.status.id.compareTo(status.id) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
|
|
|
return found ? position : -1;
|
|
|
|
}
|
|
|
|
|
2022-09-30 12:19:01 +02:00
|
|
|
/**
|
|
|
|
* Return the position of the notification in the ArrayList
|
|
|
|
*
|
|
|
|
* @param notification - Notification to fetch
|
|
|
|
* @return position or -1 if not found
|
|
|
|
*/
|
|
|
|
private int getPosition(Notification notification) {
|
|
|
|
int position = 0;
|
|
|
|
boolean found = false;
|
|
|
|
for (Notification _notification : notificationList) {
|
2022-09-30 18:54:01 +02:00
|
|
|
if (_notification != null && _notification.id.compareTo(notification.id) == 0) {
|
2022-09-30 12:19:01 +02:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
|
|
|
return found ? position : -1;
|
|
|
|
}
|
|
|
|
|
2022-11-02 18:37:29 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
notificationsVM = new ViewModelProvider(FragmentMastodonNotification.this).get(NotificationsVM.class);
|
|
|
|
binding.loader.setVisibility(View.VISIBLE);
|
|
|
|
binding.recyclerView.setVisibility(View.GONE);
|
|
|
|
max_id = null;
|
2022-11-07 14:53:48 +01:00
|
|
|
initialNotifications = null;
|
2022-11-20 15:37:09 +01:00
|
|
|
|
2022-11-02 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
flagLoading = false;
|
2022-11-09 10:59:49 +01:00
|
|
|
isViewInitialized = false;
|
2022-04-27 15:20:42 +02:00
|
|
|
binding = FragmentPaginationBinding.inflate(inflater, container, false);
|
2023-12-21 18:11:51 +01:00
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
|
|
|
boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false);
|
|
|
|
binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar);
|
2022-04-27 15:20:42 +02:00
|
|
|
View root = binding.getRoot();
|
|
|
|
if (getArguments() != null) {
|
|
|
|
notificationType = (NotificationTypeEnum) getArguments().get(Helper.ARG_NOTIFICATION_TYPE);
|
|
|
|
}
|
2022-05-21 17:45:23 +02:00
|
|
|
aggregateNotification = false;
|
2022-11-02 18:37:29 +01:00
|
|
|
|
2023-12-12 16:07:48 +01:00
|
|
|
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
|
|
|
|
ContextCompat.registerReceiver(requireActivity(), receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
|
2022-09-30 10:07:23 +02:00
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> getExcludeType() {
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
|
|
|
String excludedCategories = sharedpreferences.getString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null);
|
|
|
|
List<String> excludeType = new ArrayList<>();
|
2022-04-27 15:20:42 +02:00
|
|
|
excludeType.add("follow");
|
|
|
|
excludeType.add("favourite");
|
|
|
|
excludeType.add("reblog");
|
|
|
|
excludeType.add("poll");
|
|
|
|
excludeType.add("follow_request");
|
|
|
|
excludeType.add("mention");
|
|
|
|
excludeType.add("update");
|
|
|
|
excludeType.add("status");
|
2022-11-20 15:37:09 +01:00
|
|
|
excludeType.add("admin.sign_up");
|
|
|
|
excludeType.add("admin.report");
|
2023-01-06 16:27:26 +01:00
|
|
|
excludeType.add("pleroma:emoji_reaction");
|
2022-04-27 15:20:42 +02:00
|
|
|
if (notificationType == NotificationTypeEnum.ALL) {
|
2022-05-21 17:45:23 +02:00
|
|
|
aggregateNotification = sharedpreferences.getBoolean(getString(R.string.SET_AGGREGATE_NOTIFICATION), true);
|
2022-04-27 15:20:42 +02:00
|
|
|
if (excludedCategories != null) {
|
|
|
|
excludeType = new ArrayList<>();
|
|
|
|
String[] categoriesArray = excludedCategories.split("\\|");
|
|
|
|
Collections.addAll(excludeType, categoriesArray);
|
|
|
|
} else {
|
|
|
|
excludeType = null;
|
|
|
|
}
|
|
|
|
} else if (notificationType == NotificationTypeEnum.MENTIONS) {
|
|
|
|
excludeType.remove("mention");
|
|
|
|
} else if (notificationType == NotificationTypeEnum.FAVOURITES) {
|
|
|
|
excludeType.remove("favourite");
|
|
|
|
} else if (notificationType == NotificationTypeEnum.REBLOGS) {
|
|
|
|
excludeType.remove("reblog");
|
|
|
|
} else if (notificationType == NotificationTypeEnum.POLLS) {
|
|
|
|
excludeType.remove("poll");
|
2022-11-17 11:42:06 +01:00
|
|
|
} else if (notificationType == NotificationTypeEnum.UPDATES) {
|
|
|
|
excludeType.remove("update");
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (notificationType == NotificationTypeEnum.TOOTS) {
|
|
|
|
excludeType.remove("status");
|
2022-11-20 15:37:09 +01:00
|
|
|
} else if (notificationType == NotificationTypeEnum.ADMIN_SIGNUP) {
|
|
|
|
excludeType.remove("admin.sign_up");
|
|
|
|
} else if (notificationType == NotificationTypeEnum.ADMIN_REPORT) {
|
|
|
|
excludeType.remove("admin.report");
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (notificationType == NotificationTypeEnum.FOLLOWS) {
|
|
|
|
excludeType.remove("follow");
|
|
|
|
excludeType.remove("follow_request");
|
|
|
|
}
|
2022-09-30 10:07:23 +02:00
|
|
|
return excludeType;
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-11-02 18:37:29 +01:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
/**
|
|
|
|
* Intialize the view for notifications
|
|
|
|
*
|
2022-05-24 10:12:04 +02:00
|
|
|
* @param notifications {@link Notifications}
|
2022-04-27 15:20:42 +02:00
|
|
|
*/
|
|
|
|
private void initializeNotificationView(final Notifications notifications) {
|
2022-06-20 10:57:02 +02:00
|
|
|
flagLoading = false;
|
2022-10-21 16:47:39 +02:00
|
|
|
if (!isViewInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-25 19:35:12 +02:00
|
|
|
if (binding == null || !isAdded() || getActivity() == null) {
|
2022-06-20 10:57:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-12-13 16:28:26 +01:00
|
|
|
RecyclerView.ItemAnimator animator = binding.recyclerView.getItemAnimator();
|
|
|
|
if (animator instanceof SimpleItemAnimator) {
|
|
|
|
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.loader.setVisibility(View.GONE);
|
2022-06-20 10:57:02 +02:00
|
|
|
binding.noAction.setVisibility(View.GONE);
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.swipeContainer.setRefreshing(false);
|
2022-06-20 10:57:02 +02:00
|
|
|
binding.swipeContainer.setOnRefreshListener(() -> {
|
|
|
|
binding.swipeContainer.setRefreshing(true);
|
|
|
|
flagLoading = false;
|
|
|
|
route(FragmentMastodonTimeline.DIRECTION.REFRESH, true);
|
|
|
|
});
|
2022-06-14 19:17:35 +02:00
|
|
|
if (notifications == null || notifications.notifications == null || notifications.notifications.size() == 0) {
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.noActionText.setText(R.string.no_notifications);
|
|
|
|
binding.noAction.setVisibility(View.VISIBLE);
|
|
|
|
binding.recyclerView.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
binding.noAction.setVisibility(View.GONE);
|
|
|
|
binding.recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2022-09-30 18:54:01 +02:00
|
|
|
|
2022-05-28 18:02:30 +02:00
|
|
|
flagLoading = notifications.pagination.max_id == null;
|
2022-05-21 17:45:23 +02:00
|
|
|
if (aggregateNotification) {
|
2022-11-03 12:14:06 +01:00
|
|
|
notifications.notifications = aggregateNotifications(notifications.notifications, false);
|
2022-05-21 17:45:23 +02:00
|
|
|
}
|
2022-09-30 14:49:43 +02:00
|
|
|
if (notificationAdapter != null && notificationList != null) {
|
|
|
|
int size = notificationList.size();
|
|
|
|
notificationList.clear();
|
|
|
|
notificationList = new ArrayList<>();
|
2022-04-27 15:20:42 +02:00
|
|
|
notificationAdapter.notifyItemRangeRemoved(0, size);
|
|
|
|
}
|
2022-09-30 14:49:43 +02:00
|
|
|
if (notificationList == null) {
|
|
|
|
notificationList = new ArrayList<>();
|
2022-06-20 10:57:02 +02:00
|
|
|
}
|
2022-09-30 14:49:43 +02:00
|
|
|
notificationList.addAll(notifications.notifications);
|
2022-06-20 10:57:02 +02:00
|
|
|
|
2022-11-10 16:02:56 +01:00
|
|
|
if (max_id == null || (notifications.pagination.max_id != null && Helper.compareTo(notifications.pagination.max_id, max_id) < 0)) {
|
2022-06-20 10:57:02 +02:00
|
|
|
max_id = notifications.pagination.max_id;
|
|
|
|
}
|
2022-11-10 16:02:56 +01:00
|
|
|
if (min_id == null || (notifications.pagination.min_id != null && Helper.compareTo(notifications.pagination.min_id, min_id) > 0)) {
|
2022-06-20 10:57:02 +02:00
|
|
|
min_id = notifications.pagination.min_id;
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:49:43 +02:00
|
|
|
notificationAdapter = new NotificationAdapter(notificationList);
|
2022-06-19 19:46:01 +02:00
|
|
|
notificationAdapter.fetchMoreCallBack = this;
|
2022-06-19 19:24:42 +02:00
|
|
|
mLayoutManager = new LinearLayoutManager(requireActivity());
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.recyclerView.setLayoutManager(mLayoutManager);
|
|
|
|
binding.recyclerView.setAdapter(notificationAdapter);
|
|
|
|
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
2022-06-19 19:24:42 +02:00
|
|
|
if (requireActivity() instanceof BaseMainActivity) {
|
|
|
|
if (dy < 0 && !((BaseMainActivity) requireActivity()).getFloatingVisibility())
|
|
|
|
((BaseMainActivity) requireActivity()).manageFloatingButton(true);
|
|
|
|
if (dy > 0 && ((BaseMainActivity) requireActivity()).getFloatingVisibility())
|
|
|
|
((BaseMainActivity) requireActivity()).manageFloatingButton(false);
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (dy > 0) {
|
|
|
|
int visibleItemCount = mLayoutManager.getChildCount();
|
|
|
|
int totalItemCount = mLayoutManager.getItemCount();
|
2022-09-30 14:49:43 +02:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
|
|
|
if (!flagLoading) {
|
|
|
|
flagLoading = true;
|
|
|
|
binding.loadingNextElements.setVisibility(View.VISIBLE);
|
2022-06-20 10:57:02 +02:00
|
|
|
route(FragmentMastodonTimeline.DIRECTION.BOTTOM, false);
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
binding.loadingNextElements.setVisibility(View.GONE);
|
|
|
|
}
|
2022-06-19 19:24:42 +02:00
|
|
|
} else if (firstVisibleItem == 0) { //Scroll top and item is zero
|
|
|
|
if (!flagLoading) {
|
|
|
|
flagLoading = true;
|
|
|
|
binding.loadingNextElements.setVisibility(View.VISIBLE);
|
2022-06-20 10:57:02 +02:00
|
|
|
route(FragmentMastodonTimeline.DIRECTION.TOP, false);
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
|
2022-10-21 16:47:39 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2022-11-09 10:59:49 +01:00
|
|
|
if (!isViewInitialized) {
|
2022-10-21 16:47:39 +02:00
|
|
|
isViewInitialized = true;
|
2022-11-09 10:59:49 +01:00
|
|
|
if (initialNotifications != null) {
|
|
|
|
initializeNotificationView(initialNotifications);
|
2022-11-14 18:47:14 +01:00
|
|
|
} else {
|
2022-11-20 15:37:09 +01:00
|
|
|
route(null, false);
|
2022-11-09 10:59:49 +01:00
|
|
|
}
|
2022-10-21 16:47:39 +02:00
|
|
|
}
|
2022-12-12 17:30:23 +01:00
|
|
|
if (notificationList != null && notificationList.size() > 0) {
|
|
|
|
route(FragmentMastodonTimeline.DIRECTION.FETCH_NEW, true);
|
|
|
|
}
|
2022-10-21 16:47:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
/**
|
|
|
|
* Router for timelines
|
|
|
|
*
|
|
|
|
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
|
|
|
|
*/
|
|
|
|
private void route(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing) {
|
2022-09-29 17:59:53 +02:00
|
|
|
route(direction, fetchingMissing, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Router for timelines
|
|
|
|
*
|
|
|
|
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
|
|
|
|
*/
|
|
|
|
private void route(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, Notification notificationToUpdate) {
|
2022-06-25 19:35:12 +02:00
|
|
|
if (binding == null || !isAdded() || getActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-25 11:23:08 +02:00
|
|
|
if (!isAdded()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-29 17:59:53 +02:00
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
|
|
|
boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);
|
|
|
|
|
2023-02-08 17:42:27 +01:00
|
|
|
TimelinesVM.TimelineParams timelineParams = new TimelinesVM.TimelineParams(requireActivity(), Timeline.TimeLineEnum.NOTIFICATION, direction, null);
|
2022-09-29 17:59:53 +02:00
|
|
|
timelineParams.limit = MastodonHelper.notificationsPerCall(requireActivity());
|
|
|
|
if (direction == FragmentMastodonTimeline.DIRECTION.REFRESH || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP) {
|
|
|
|
timelineParams.maxId = null;
|
|
|
|
timelineParams.minId = null;
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
|
|
|
timelineParams.maxId = fetchingMissing ? max_id_fetch_more : max_id;
|
|
|
|
timelineParams.minId = null;
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.TOP) {
|
|
|
|
timelineParams.minId = fetchingMissing ? min_id_fetch_more : min_id;
|
|
|
|
timelineParams.maxId = null;
|
|
|
|
} else {
|
|
|
|
timelineParams.maxId = max_id;
|
|
|
|
}
|
2022-09-30 10:07:23 +02:00
|
|
|
timelineParams.excludeType = getExcludeType();
|
2022-09-29 17:59:53 +02:00
|
|
|
timelineParams.fetchingMissing = fetchingMissing;
|
2023-02-08 17:42:27 +01:00
|
|
|
|
2022-12-04 18:25:10 +01:00
|
|
|
if (useCache && direction != FragmentMastodonTimeline.DIRECTION.SCROLL_TOP && direction != FragmentMastodonTimeline.DIRECTION.FETCH_NEW) {
|
2022-09-29 17:59:53 +02:00
|
|
|
getCachedNotifications(direction, fetchingMissing, timelineParams);
|
|
|
|
} else {
|
|
|
|
getLiveNotifications(direction, fetchingMissing, timelineParams, notificationToUpdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getCachedNotifications(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams) {
|
|
|
|
|
|
|
|
if (direction == null) {
|
|
|
|
notificationsVM.getNotificationCache(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsCached -> {
|
|
|
|
if (notificationsCached == null || notificationsCached.notifications == null || notificationsCached.notifications.size() == 0) {
|
|
|
|
getLiveNotifications(null, fetchingMissing, timelineParams, null);
|
|
|
|
} else {
|
2022-10-21 16:47:39 +02:00
|
|
|
initialNotifications = notificationsCached;
|
2022-09-29 17:59:53 +02:00
|
|
|
initializeNotificationView(notificationsCached);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
|
|
|
notificationsVM.getNotificationCache(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsBottom -> {
|
|
|
|
if (notificationsBottom == null || notificationsBottom.notifications == null || notificationsBottom.notifications.size() == 0) {
|
|
|
|
getLiveNotifications(FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, timelineParams, null);
|
|
|
|
} else {
|
|
|
|
dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.TOP) {
|
|
|
|
notificationsVM.getNotificationCache(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsTop -> {
|
|
|
|
if (notificationsTop == null || notificationsTop.notifications == null || notificationsTop.notifications.size() == 0) {
|
2022-09-30 14:49:43 +02:00
|
|
|
getLiveNotifications(FragmentMastodonTimeline.DIRECTION.TOP, fetchingMissing, timelineParams, null);
|
2022-09-29 17:59:53 +02:00
|
|
|
} else {
|
|
|
|
dealWithPagination(notificationsTop, FragmentMastodonTimeline.DIRECTION.TOP, fetchingMissing, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.REFRESH) {
|
|
|
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsRefresh -> {
|
2022-12-04 18:25:10 +01:00
|
|
|
if (notificationsRefresh == null || notificationsRefresh.notifications == null || notificationsRefresh.notifications.size() == 0) {
|
|
|
|
getLiveNotifications(direction, fetchingMissing, timelineParams, null);
|
2022-09-29 17:59:53 +02:00
|
|
|
} else {
|
2022-12-04 18:25:10 +01:00
|
|
|
if (notificationAdapter != null) {
|
|
|
|
dealWithPagination(notificationsRefresh, FragmentMastodonTimeline.DIRECTION.REFRESH, true, null);
|
|
|
|
} else {
|
|
|
|
initializeNotificationView(notificationsRefresh);
|
|
|
|
}
|
2022-09-29 17:59:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getLiveNotifications(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Notification notificationToUpdate) {
|
2022-09-25 11:23:08 +02:00
|
|
|
if (direction == null) {
|
2022-09-29 17:59:53 +02:00
|
|
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
2022-10-21 16:47:39 +02:00
|
|
|
.observe(getViewLifecycleOwner(), notifications -> {
|
|
|
|
initialNotifications = notifications;
|
|
|
|
initializeNotificationView(notifications);
|
|
|
|
});
|
2022-09-25 11:23:08 +02:00
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
2022-09-29 17:59:53 +02:00
|
|
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsBottom -> dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, notificationToUpdate));
|
2022-09-25 11:23:08 +02:00
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.TOP) {
|
2022-09-29 17:59:53 +02:00
|
|
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
|
|
|
.observe(getViewLifecycleOwner(), notificationsTop -> dealWithPagination(notificationsTop, FragmentMastodonTimeline.DIRECTION.TOP, fetchingMissing, notificationToUpdate));
|
2023-03-13 18:09:48 +01:00
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.REFRESH || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) {
|
2022-09-29 17:59:53 +02:00
|
|
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
2022-09-25 11:23:08 +02:00
|
|
|
.observe(getViewLifecycleOwner(), notificationsRefresh -> {
|
|
|
|
if (notificationAdapter != null) {
|
2023-03-13 18:09:48 +01:00
|
|
|
dealWithPagination(notificationsRefresh, direction, true, notificationToUpdate);
|
2022-09-25 11:23:08 +02:00
|
|
|
} else {
|
|
|
|
initializeNotificationView(notificationsRefresh);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
|
|
|
|
2022-11-03 12:14:06 +01:00
|
|
|
/***
|
|
|
|
* Allow to aggregate notifications
|
|
|
|
* @param notifications - List<Notification> to aggregate
|
|
|
|
* @param update - boolean - if true the adapter will be updated to remove notification that have been aggregated
|
|
|
|
* @return List<Notification> that has been aggregated
|
|
|
|
*/
|
|
|
|
private List<Notification> aggregateNotifications(@NonNull List<Notification> notifications, boolean update) {
|
2022-05-21 17:45:23 +02:00
|
|
|
List<Notification> notificationList = new ArrayList<>();
|
2022-11-03 12:14:06 +01:00
|
|
|
List<Notification> notificationsToRemove = new ArrayList<>();
|
2022-05-21 17:45:23 +02:00
|
|
|
int refPosition = 0;
|
|
|
|
for (int i = 0; i < notifications.size(); i++) {
|
|
|
|
if (i != refPosition) {
|
2022-11-03 12:14:06 +01:00
|
|
|
//Loop through notifications, only fav and boost will be aggregated if they are just bellow
|
2022-10-26 09:45:31 +02:00
|
|
|
if (notifications.get(i).type != null && notifications.get(refPosition).type != null && notifications.get(i).type.equals(notifications.get(refPosition).type)
|
2022-11-17 11:42:06 +01:00
|
|
|
&& (notifications.get(i).type.equals("favourite") || notifications.get(i).type.equals("reblog") || notifications.get(i).type.equals("update"))
|
2022-06-06 11:06:38 +02:00
|
|
|
&& notifications.get(i).status != null && notifications.get(refPosition).status != null && notifications.get(i).status.id.equals(notifications.get(refPosition).status.id)
|
2022-05-21 19:04:07 +02:00
|
|
|
) {
|
2022-05-21 17:45:23 +02:00
|
|
|
if (notificationList.size() > 0) {
|
|
|
|
if (notificationList.get(notificationList.size() - 1).relatedNotifications == null) {
|
|
|
|
notificationList.get(notificationList.size() - 1).relatedNotifications = new ArrayList<>();
|
|
|
|
}
|
2022-11-03 12:14:06 +01:00
|
|
|
if (!notificationList.get(notificationList.size() - 1).relatedNotifications.contains(notifications.get(i))) {
|
|
|
|
notificationList.get(notificationList.size() - 1).relatedNotifications.add(notifications.get(i));
|
|
|
|
}
|
|
|
|
notificationsToRemove.add(notifications.get(i));
|
2022-05-21 17:45:23 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
notificationList.add(notifications.get(i));
|
|
|
|
refPosition = i;
|
|
|
|
}
|
2022-05-24 10:27:17 +02:00
|
|
|
} else {
|
|
|
|
notificationList.add(notifications.get(i));
|
2022-05-21 17:45:23 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-03 12:14:06 +01:00
|
|
|
if (notificationsToRemove.size() > 0 && update) {
|
|
|
|
for (Notification notification : notificationsToRemove) {
|
|
|
|
int position = getPosition(notification);
|
|
|
|
this.notificationList.remove(position);
|
|
|
|
notificationAdapter.notifyItemRemoved(position);
|
|
|
|
}
|
|
|
|
}
|
2022-05-21 17:45:23 +02:00
|
|
|
return notificationList;
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
public void scrollToTop() {
|
2023-03-13 18:09:48 +01:00
|
|
|
if (binding != null) {
|
|
|
|
binding.swipeContainer.setRefreshing(true);
|
|
|
|
flagLoading = false;
|
|
|
|
route(FragmentMastodonTimeline.DIRECTION.SCROLL_TOP, true);
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
|
2024-01-19 14:30:29 +01:00
|
|
|
private void storeMarker(BaseAccount connectedAccount) {
|
2022-10-05 17:26:15 +02:00
|
|
|
if (mLayoutManager != null) {
|
|
|
|
int position = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (notificationList != null && notificationList.size() > position) {
|
|
|
|
try {
|
|
|
|
if (notificationType == NotificationTypeEnum.ALL) {
|
|
|
|
Notification notification = notificationList.get(position);
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2024-01-19 14:30:29 +01:00
|
|
|
editor.putString(getString(R.string.SET_INNER_MARKER) + connectedAccount.user_id + connectedAccount.instance + Timeline.TimeLineEnum.NOTIFICATION, notification.id);
|
2022-10-05 17:26:15 +02:00
|
|
|
editor.apply();
|
|
|
|
TimelinesVM timelinesVM = new ViewModelProvider(FragmentMastodonNotification.this).get(TimelinesVM.class);
|
2024-01-19 14:30:29 +01:00
|
|
|
timelinesVM.addMarker(connectedAccount.instance, connectedAccount.token, null, notification.id);
|
2022-10-05 17:26:15 +02:00
|
|
|
}
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-30 12:19:01 +02:00
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
/**
|
|
|
|
* Update view and pagination when scrolling down
|
|
|
|
*
|
|
|
|
* @param fetched_notifications Notifications
|
|
|
|
*/
|
2022-09-29 17:59:53 +02:00
|
|
|
private synchronized void dealWithPagination(Notifications fetched_notifications, FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, Notification notificationToUpdate) {
|
2022-06-25 19:35:12 +02:00
|
|
|
if (binding == null || !isAdded() || getActivity() == null) {
|
2022-06-19 19:24:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
binding.swipeContainer.setRefreshing(false);
|
|
|
|
binding.loadingNextElements.setVisibility(View.GONE);
|
|
|
|
flagLoading = false;
|
|
|
|
if (notificationList != null && fetched_notifications != null && fetched_notifications.notifications != null && fetched_notifications.notifications.size() > 0) {
|
2022-10-26 17:08:40 +02:00
|
|
|
|
2022-11-03 12:14:06 +01:00
|
|
|
/* if (aggregateNotification) {
|
2022-10-26 17:08:40 +02:00
|
|
|
fetched_notifications.notifications = aggregateNotifications(fetched_notifications.notifications);
|
2022-11-03 12:14:06 +01:00
|
|
|
}*/
|
2022-09-30 12:19:01 +02:00
|
|
|
try {
|
|
|
|
if (notificationToUpdate != null) {
|
|
|
|
new Thread(() -> {
|
|
|
|
StatusCache statusCache = new StatusCache();
|
|
|
|
statusCache.instance = BaseMainActivity.currentInstance;
|
|
|
|
statusCache.user_id = BaseMainActivity.currentUserID;
|
2022-09-30 18:54:01 +02:00
|
|
|
notificationToUpdate.isFetchMore = false;
|
2022-09-30 12:19:01 +02:00
|
|
|
statusCache.notification = notificationToUpdate;
|
|
|
|
statusCache.status_id = notificationToUpdate.id;
|
|
|
|
try {
|
|
|
|
new StatusCache(requireActivity()).updateIfExists(statusCache);
|
|
|
|
} catch (DBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2022-06-19 19:24:42 +02:00
|
|
|
flagLoading = fetched_notifications.pagination.max_id == null;
|
|
|
|
binding.noAction.setVisibility(View.GONE);
|
|
|
|
//Update the timeline with new statuses
|
2022-10-03 17:48:12 +02:00
|
|
|
int insertedStatus = updateNotificationListWith(fetched_notifications.notifications);
|
|
|
|
if (insertedStatus >= 0 && FragmentNotificationContainer.update != null && notificationType == NotificationTypeEnum.ALL && (direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW || direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || direction == FragmentMastodonTimeline.DIRECTION.REFRESH)) {
|
2022-10-03 18:51:41 +02:00
|
|
|
FragmentNotificationContainer.update.onUpdateNotification(insertedStatus);
|
2022-10-03 17:48:12 +02:00
|
|
|
}
|
2022-09-30 12:19:01 +02:00
|
|
|
if (direction == FragmentMastodonTimeline.DIRECTION.TOP && fetchingMissing) {
|
|
|
|
binding.recyclerView.scrollToPosition(getPosition(fetched_notifications.notifications.get(fetched_notifications.notifications.size() - 1)) + 1);
|
|
|
|
}
|
2022-10-26 17:08:40 +02:00
|
|
|
if (aggregateNotification && notificationList != null && notificationList.size() > 0) {
|
2022-11-03 12:14:06 +01:00
|
|
|
aggregateNotifications(notificationList, true);
|
2022-10-26 17:08:40 +02:00
|
|
|
}
|
2022-06-19 19:24:42 +02:00
|
|
|
if (!fetchingMissing) {
|
|
|
|
if (fetched_notifications.pagination.max_id == null) {
|
|
|
|
flagLoading = true;
|
2022-11-10 16:02:56 +01:00
|
|
|
} else if (max_id == null || Helper.compareTo(fetched_notifications.pagination.max_id, max_id) < 0) {
|
2022-06-19 19:24:42 +02:00
|
|
|
max_id = fetched_notifications.pagination.max_id;
|
|
|
|
}
|
2022-11-10 16:02:56 +01:00
|
|
|
if (min_id == null || (fetched_notifications.pagination.min_id != null && Helper.compareTo(fetched_notifications.pagination.min_id, min_id) > 0)) {
|
2022-06-19 19:24:42 +02:00
|
|
|
min_id = fetched_notifications.pagination.min_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
|
|
|
flagLoading = true;
|
|
|
|
}
|
2022-09-30 14:49:43 +02:00
|
|
|
if (direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP) {
|
2023-03-13 18:09:48 +01:00
|
|
|
new Handler().postDelayed(() -> binding.recyclerView.scrollToPosition(0), 200);
|
2022-09-30 14:49:43 +02:00
|
|
|
}
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the timeline with received statuses
|
|
|
|
*
|
|
|
|
* @param notificationsReceived - List<Notification> Notifications received
|
|
|
|
*/
|
2022-10-03 17:48:12 +02:00
|
|
|
private int updateNotificationListWith(List<Notification> notificationsReceived) {
|
|
|
|
int insertedNotifications = 0;
|
2022-06-19 19:24:42 +02:00
|
|
|
if (notificationsReceived != null && notificationsReceived.size() > 0) {
|
|
|
|
for (Notification notificationReceived : notificationsReceived) {
|
2022-09-30 12:19:01 +02:00
|
|
|
int position = 0;
|
|
|
|
//We loop through messages already in the timeline
|
2022-09-30 14:49:43 +02:00
|
|
|
if (notificationList != null) {
|
|
|
|
notificationAdapter.notifyItemRangeChanged(0, notificationList.size());
|
|
|
|
for (Notification notificationsAlreadyPresent : notificationList) {
|
2022-09-30 12:19:01 +02:00
|
|
|
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
|
|
|
|
//Pinned messages are ignored because their date can be older
|
2022-11-23 12:13:24 +01:00
|
|
|
if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) {
|
2022-09-30 16:57:49 +02:00
|
|
|
if (!notificationList.contains(notificationReceived)) {
|
|
|
|
notificationList.add(position, notificationReceived);
|
|
|
|
notificationAdapter.notifyItemInserted(position);
|
2022-10-03 17:48:12 +02:00
|
|
|
if (!notificationReceived.cached) {
|
|
|
|
insertedNotifications++;
|
|
|
|
}
|
2022-09-30 16:57:49 +02:00
|
|
|
}
|
2022-09-30 12:19:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
2022-09-30 12:19:01 +02:00
|
|
|
//Statuses added at the bottom, we flag them by position = -2 for not dealing with them and fetch more
|
|
|
|
if (position == notificationList.size() && !notificationList.contains(notificationReceived)) {
|
|
|
|
notificationList.add(position, notificationReceived);
|
|
|
|
notificationAdapter.notifyItemInserted(position);
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-03 17:48:12 +02:00
|
|
|
return insertedNotifications;
|
2022-06-19 19:24:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
2023-12-17 17:41:17 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
requireActivity().unregisterReceiver(receive_action);
|
|
|
|
requireActivity().unregisterReceiver(receive_refresh);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-10-05 17:26:15 +02:00
|
|
|
if (isAdded()) {
|
2024-01-19 14:30:29 +01:00
|
|
|
storeMarker(currentAccount);
|
2022-10-05 17:26:15 +02:00
|
|
|
}
|
2022-07-10 17:46:14 +02:00
|
|
|
super.onDestroyView();
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
2024-01-19 14:30:29 +01:00
|
|
|
storeMarker(currentAccount);
|
2022-06-19 19:24:42 +02:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2022-09-27 18:01:06 +02:00
|
|
|
|
2022-06-21 17:09:34 +02:00
|
|
|
@Override
|
2022-09-29 17:59:53 +02:00
|
|
|
public void onClickMinId(String min_id, Notification notificationToUpdate) {
|
2022-06-21 17:09:34 +02:00
|
|
|
//Fetch more has been pressed
|
|
|
|
min_id_fetch_more = min_id;
|
2022-09-29 17:59:53 +02:00
|
|
|
route(FragmentMastodonTimeline.DIRECTION.TOP, true, notificationToUpdate);
|
2022-06-21 17:09:34 +02:00
|
|
|
}
|
|
|
|
|
2022-07-08 19:02:18 +02:00
|
|
|
@Override
|
2022-09-29 17:59:53 +02:00
|
|
|
public void onClickMaxId(String max_id, Notification notificationToUpdate) {
|
2022-07-08 19:02:18 +02:00
|
|
|
//Fetch more has been pressed
|
|
|
|
max_id_fetch_more = max_id;
|
2022-09-29 17:59:53 +02:00
|
|
|
route(FragmentMastodonTimeline.DIRECTION.BOTTOM, true, notificationToUpdate);
|
2022-07-08 19:02:18 +02:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
public enum NotificationTypeEnum {
|
|
|
|
@SerializedName("ALL")
|
|
|
|
ALL("ALL"),
|
|
|
|
@SerializedName("MENTIONS")
|
|
|
|
MENTIONS("MENTIONS"),
|
|
|
|
@SerializedName("FAVOURITES")
|
|
|
|
FAVOURITES("FAVOURITES"),
|
|
|
|
@SerializedName("REBLOGS")
|
2022-11-17 11:42:06 +01:00
|
|
|
UPDATES("UPDATES"),
|
|
|
|
@SerializedName("UPDATES")
|
2022-04-27 15:20:42 +02:00
|
|
|
REBLOGS("REBLOGS"),
|
|
|
|
@SerializedName("POLLS")
|
|
|
|
POLLS("POLLS"),
|
2022-11-20 15:37:09 +01:00
|
|
|
@SerializedName("ADMIN_SIGNUP")
|
|
|
|
ADMIN_SIGNUP("ADMIN_SIGNUP"),
|
|
|
|
@SerializedName("ADMIN_REPORT")
|
|
|
|
ADMIN_REPORT("ADMIN_REPORT"),
|
2022-04-27 15:20:42 +02:00
|
|
|
@SerializedName("TOOTS")
|
|
|
|
TOOTS("TOOTS"),
|
|
|
|
@SerializedName("FOLLOWS")
|
|
|
|
FOLLOWS("FOLLOWS");
|
|
|
|
|
|
|
|
private final String value;
|
|
|
|
|
|
|
|
NotificationTypeEnum(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
2022-10-03 17:48:12 +02:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|