Fix messages/notifications not in the right order
This commit is contained in:
parent
6c59e5f32e
commit
da5ff2320d
|
@ -70,28 +70,35 @@ public class CacheActivity extends BaseActivity {
|
|||
|
||||
|
||||
new Thread(() -> {
|
||||
List<BaseAccount> accounts = new Account(CacheActivity.this).getPushNotificationAccounts();
|
||||
List<BaseAccount> accounts;
|
||||
cacheAccounts = new ArrayList<>();
|
||||
for (BaseAccount baseAccount : accounts) {
|
||||
CacheAccount cacheAccount = new CacheAccount();
|
||||
cacheAccount.account = baseAccount;
|
||||
try {
|
||||
cacheAccount.home_cache_count = new StatusCache(CacheActivity.this).countHome(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
accounts = new Account(CacheActivity.this).getAll();
|
||||
for (BaseAccount baseAccount : accounts) {
|
||||
CacheAccount cacheAccount = new CacheAccount();
|
||||
cacheAccount.account = baseAccount;
|
||||
try {
|
||||
cacheAccount.home_cache_count = new StatusCache(CacheActivity.this).countHome(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
cacheAccount.other_cache_count = new StatusCache(CacheActivity.this).countOther(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
cacheAccount.draft_count = new StatusDraft(CacheActivity.this).count(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cacheAccounts.add(cacheAccount);
|
||||
}
|
||||
try {
|
||||
cacheAccount.other_cache_count = new StatusCache(CacheActivity.this).countOther(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
cacheAccount.draft_count = new StatusDraft(CacheActivity.this).count(baseAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cacheAccounts.add(cacheAccount);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
cacheAdapter = new CacheAdapter(cacheAccounts);
|
||||
|
|
|
@ -759,7 +759,7 @@ public class StatusCache {
|
|||
Pagination pagination = new Pagination();
|
||||
if (notificationList != null && notificationList.size() > 0) {
|
||||
//Status list is inverted, it happens for min_id due to ASC ordering
|
||||
if (notificationList.get(0).id.compareTo(notificationList.get(notificationList.size() - 1).id) < 0) {
|
||||
if (Helper.compareTo(notificationList.get(0).id, notificationList.get(notificationList.size() - 1).id) < 0) {
|
||||
Collections.reverse(notificationList);
|
||||
notifications.notifications = notificationList;
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ public class StatusCache {
|
|||
Pagination pagination = new Pagination();
|
||||
if (conversationList != null && conversationList.size() > 0) {
|
||||
//Status list is inverted, it happens for min_id due to ASC ordering
|
||||
if (conversationList.get(0).id.compareTo(conversationList.get(conversationList.size() - 1).id) < 0) {
|
||||
if (Helper.compareTo(conversationList.get(0).id, conversationList.get(conversationList.size() - 1).id) < 0) {
|
||||
Collections.reverse(conversationList);
|
||||
conversations.conversations = conversationList;
|
||||
}
|
||||
|
@ -806,7 +806,7 @@ public class StatusCache {
|
|||
Pagination pagination = new Pagination();
|
||||
if (statusList != null && statusList.size() > 0) {
|
||||
//Status list is inverted, it happens for min_id due to ASC ordering
|
||||
if (statusList.get(0).id.compareTo(statusList.get(statusList.size() - 1).id) < 0) {
|
||||
if (Helper.compareTo(statusList.get(0).id, statusList.get(statusList.size() - 1).id) < 0) {
|
||||
Collections.reverse(statusList);
|
||||
statuses.statuses = statusList;
|
||||
}
|
||||
|
|
|
@ -1882,6 +1882,15 @@ public class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
public static int compareTo(String value1, String value2) {
|
||||
try {
|
||||
long val1 = Long.parseLong(value1);
|
||||
long val2 = Long.parseLong(value2);
|
||||
return Long.compare(val1, val2);
|
||||
} catch (Exception e) {
|
||||
return value1.compareTo(value2);
|
||||
}
|
||||
}
|
||||
|
||||
//Enum that described actions to replace inside a toot content
|
||||
public enum PatternType {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class NotificationsHelper {
|
|||
final List<Notification> notifications = new ArrayList<>();
|
||||
int pos = 0;
|
||||
for (Notification notif : notificationsReceived) {
|
||||
if (max_id == null || notif.id.compareTo(max_id) > 0) {
|
||||
if (max_id == null || Helper.compareTo(notif.id, max_id) > 0) {
|
||||
notifications.add(pos, notif);
|
||||
pos++;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ public class NotificationsHelper {
|
|||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
|
||||
if (lastNotif == null || notification.id.compareTo(lastNotif) > 0) {
|
||||
if (lastNotif == null || Helper.compareTo(notification.id, lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
since_ids.put(account.user_id + "@" + account.instance, lastNotif);
|
||||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||
|
@ -353,7 +353,7 @@ public class NotificationsHelper {
|
|||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
|
||||
if (lastNotif == null || notification.id.compareTo(lastNotif) > 0) {
|
||||
if (lastNotif == null || Helper.compareTo(notification.id, lastNotif) > 0) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||
editor.apply();
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package app.fedilab.android.helper;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
public class ZoomOutPageTransformer implements ViewPager2.PageTransformer {
|
||||
private static final float MIN_SCALE = 0.85f;
|
||||
private static final float MIN_ALPHA = 0.5f;
|
||||
|
||||
public void transformPage(View view, float position) {
|
||||
int pageWidth = view.getWidth();
|
||||
int pageHeight = view.getHeight();
|
||||
|
||||
if (position < -1) { // [-Infinity,-1)
|
||||
// This page is way off-screen to the left.
|
||||
view.setAlpha(0f);
|
||||
|
||||
} else if (position <= 1) { // [-1,1]
|
||||
// Modify the default slide transition to shrink the page as well
|
||||
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
|
||||
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
|
||||
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
|
||||
if (position < 0) {
|
||||
view.setTranslationX(horzMargin - vertMargin / 2);
|
||||
} else {
|
||||
view.setTranslationX(-horzMargin + vertMargin / 2);
|
||||
}
|
||||
|
||||
// Scale the page down (between MIN_SCALE and 1)
|
||||
view.setScaleX(scaleFactor);
|
||||
view.setScaleY(scaleFactor);
|
||||
|
||||
// Fade the page relative to its size.
|
||||
view.setAlpha(MIN_ALPHA +
|
||||
(scaleFactor - MIN_SCALE) /
|
||||
(1 - MIN_SCALE) * (1 - MIN_ALPHA));
|
||||
|
||||
} else { // (1,+Infinity]
|
||||
// This page is way off-screen to the right.
|
||||
view.setAlpha(0f);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -140,7 +140,7 @@ public class FragmentAdminAccount extends Fragment {
|
|||
binding.recyclerView.setLayoutManager(mLayoutManager);
|
||||
binding.recyclerView.setAdapter(adminAccountAdapter);
|
||||
//Fetch the relationship
|
||||
if (max_id == null || (adminAccounts.pagination.max_id != null && adminAccounts.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (adminAccounts.pagination.max_id != null && Helper.compareTo(adminAccounts.pagination.max_id, max_id) < 0)) {
|
||||
max_id = adminAccounts.pagination.max_id;
|
||||
}
|
||||
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
@ -190,7 +190,7 @@ public class FragmentAdminAccount extends Fragment {
|
|||
}
|
||||
int position = this.adminAccounts.size();
|
||||
this.adminAccounts.addAll(adminAccounts.adminAccounts);
|
||||
if (max_id == null || (adminAccounts.pagination.max_id != null && adminAccounts.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (adminAccounts.pagination.max_id != null && Helper.compareTo(adminAccounts.pagination.max_id, max_id) < 0)) {
|
||||
max_id = adminAccounts.pagination.max_id;
|
||||
}
|
||||
adminAccountAdapter.notifyItemRangeInserted(startId, adminAccounts.adminAccounts.size());
|
||||
|
|
|
@ -131,10 +131,10 @@ public class FragmentAdminReport extends Fragment {
|
|||
|
||||
this.adminReports.addAll(adminReports.adminReports);
|
||||
|
||||
if (max_id == null || (adminReports.pagination.max_id != null && adminReports.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (adminReports.pagination.max_id != null && Helper.compareTo(adminReports.pagination.max_id, max_id) < 0)) {
|
||||
max_id = adminReports.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (adminReports.pagination.max_id != null && adminReports.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (adminReports.pagination.max_id != null && Helper.compareTo(adminReports.pagination.min_id, min_id) > 0)) {
|
||||
min_id = adminReports.pagination.min_id;
|
||||
}
|
||||
|
||||
|
@ -190,10 +190,10 @@ public class FragmentAdminReport extends Fragment {
|
|||
int startId = adminReports.size();
|
||||
adminReports.addAll(admReports.adminReports);
|
||||
statusAdapter.notifyItemRangeInserted(startId, admReports.adminReports.size());
|
||||
if (max_id == null || (admReports.pagination.max_id != null && admReports.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (admReports.pagination.max_id != null && Helper.compareTo(admReports.pagination.max_id, max_id) < 0)) {
|
||||
max_id = admReports.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (admReports.pagination.min_id != null && admReports.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (admReports.pagination.min_id != null && Helper.compareTo(admReports.pagination.min_id, min_id) > 0)) {
|
||||
min_id = admReports.pagination.min_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class FragmentMediaProfile extends Fragment {
|
|||
flagLoading = statuses.pagination.max_id == null;
|
||||
binding.recyclerView.setVisibility(View.VISIBLE);
|
||||
|
||||
if (max_id == null || (statuses.pagination.max_id != null && statuses.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (statuses.pagination.max_id != null && Helper.compareTo(statuses.pagination.max_id, max_id) < 0)) {
|
||||
max_id = statuses.pagination.max_id;
|
||||
}
|
||||
GridLayoutManager gvLayout = new GridLayoutManager(requireActivity(), 3);
|
||||
|
@ -180,7 +180,7 @@ public class FragmentMediaProfile extends Fragment {
|
|||
imageAdapter.notifyItemRangeInserted(this.mediaStatuses.size() - added, this.mediaStatuses.size());
|
||||
if (fetched_statuses.pagination.max_id == null) {
|
||||
flagLoading = true;
|
||||
} else if (max_id == null || fetched_statuses.pagination.max_id.compareTo(max_id) < 0) {
|
||||
} else if (max_id == null || Helper.compareTo(fetched_statuses.pagination.max_id, max_id) < 0) {
|
||||
max_id = fetched_statuses.pagination.max_id;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -40,6 +40,7 @@ import app.fedilab.android.client.entities.app.StatusCache;
|
|||
import app.fedilab.android.client.entities.app.Timeline;
|
||||
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
||||
import app.fedilab.android.exception.DBException;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.MastodonHelper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.drawer.ConversationAdapter;
|
||||
|
@ -276,10 +277,10 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
|||
}
|
||||
conversationList.addAll(conversations.conversations);
|
||||
|
||||
if (max_id == null || (conversations.pagination.max_id != null && conversations.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (conversations.pagination.max_id != null && Helper.compareTo(conversations.pagination.max_id, max_id) < 0)) {
|
||||
max_id = conversations.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (conversations.pagination.min_id != null && conversations.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (conversations.pagination.min_id != null && Helper.compareTo(conversations.pagination.min_id, min_id) > 0)) {
|
||||
min_id = conversations.pagination.min_id;
|
||||
}
|
||||
|
||||
|
@ -384,10 +385,10 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
|||
if (!fetchingMissing) {
|
||||
if (fetched_conversations.pagination.max_id == null) {
|
||||
flagLoading = true;
|
||||
} else if (max_id == null || fetched_conversations.pagination.max_id.compareTo(max_id) < 0) {
|
||||
} else if (max_id == null || Helper.compareTo(fetched_conversations.pagination.max_id, max_id) < 0) {
|
||||
max_id = fetched_conversations.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (fetched_conversations.pagination.min_id != null && fetched_conversations.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (fetched_conversations.pagination.min_id != null && Helper.compareTo(fetched_conversations.pagination.min_id, min_id) > 0)) {
|
||||
min_id = fetched_conversations.pagination.min_id;
|
||||
}
|
||||
}
|
||||
|
@ -435,7 +436,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
|||
for (Conversation conversationsAlreadyPresent : conversationList) {
|
||||
//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
|
||||
if (conversationReceived.id.compareTo(conversationsAlreadyPresent.id) > 0) {
|
||||
if (Helper.compareTo(conversationReceived.id, conversationsAlreadyPresent.id) > 0) {
|
||||
if (!conversationList.contains(conversationReceived)) {
|
||||
conversationList.add(position, conversationReceived);
|
||||
conversationAdapter.notifyItemInserted(position);
|
||||
|
|
|
@ -269,10 +269,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
|||
}
|
||||
notificationList.addAll(notifications.notifications);
|
||||
|
||||
if (max_id == null || (notifications.pagination.max_id != null && notifications.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (notifications.pagination.max_id != null && Helper.compareTo(notifications.pagination.max_id, max_id) < 0)) {
|
||||
max_id = notifications.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (notifications.pagination.min_id != null && notifications.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (notifications.pagination.min_id != null && Helper.compareTo(notifications.pagination.min_id, min_id) > 0)) {
|
||||
min_id = notifications.pagination.min_id;
|
||||
}
|
||||
|
||||
|
@ -565,10 +565,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
|||
if (!fetchingMissing) {
|
||||
if (fetched_notifications.pagination.max_id == null) {
|
||||
flagLoading = true;
|
||||
} else if (max_id == null || fetched_notifications.pagination.max_id.compareTo(max_id) < 0) {
|
||||
} else if (max_id == null || Helper.compareTo(fetched_notifications.pagination.max_id, max_id) < 0) {
|
||||
max_id = fetched_notifications.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (fetched_notifications.pagination.min_id != null && fetched_notifications.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (fetched_notifications.pagination.min_id != null && Helper.compareTo(fetched_notifications.pagination.min_id, min_id) > 0)) {
|
||||
min_id = fetched_notifications.pagination.min_id;
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
|||
for (Notification notificationsAlreadyPresent : notificationList) {
|
||||
//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
|
||||
if (notificationReceived.id.compareTo(notificationsAlreadyPresent.id) > 0) {
|
||||
if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) {
|
||||
if (!notificationList.contains(notificationReceived)) {
|
||||
notificationList.add(position, notificationReceived);
|
||||
notificationAdapter.notifyItemInserted(position);
|
||||
|
|
|
@ -393,10 +393,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
if (!fetchingMissing) {
|
||||
if (fetched_statuses.pagination.max_id == null) {
|
||||
flagLoading = true;
|
||||
} else if (max_id == null || fetched_statuses.pagination.max_id.compareTo(max_id) < 0) {
|
||||
} else if (max_id == null || Helper.compareTo(fetched_statuses.pagination.max_id, max_id) < 0) {
|
||||
max_id = fetched_statuses.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (fetched_statuses.pagination.min_id != null && fetched_statuses.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (fetched_statuses.pagination.min_id != null && Helper.compareTo(fetched_statuses.pagination.min_id, min_id) > 0)) {
|
||||
min_id = fetched_statuses.pagination.min_id;
|
||||
}
|
||||
}
|
||||
|
@ -474,10 +474,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
timelineStatuses.add(statusReport);
|
||||
}
|
||||
timelineStatuses.addAll(statuses.statuses);
|
||||
if (max_id == null || (statuses.pagination.max_id != null && statuses.pagination.max_id.compareTo(max_id) < 0)) {
|
||||
if (max_id == null || (statuses.pagination.max_id != null && Helper.compareTo(statuses.pagination.max_id, max_id) < 0)) {
|
||||
max_id = statuses.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (statuses.pagination.min_id != null && statuses.pagination.min_id.compareTo(min_id) > 0)) {
|
||||
if (min_id == null || (statuses.pagination.min_id != null && Helper.compareTo(statuses.pagination.min_id, min_id) > 0)) {
|
||||
min_id = statuses.pagination.min_id;
|
||||
}
|
||||
statusAdapter = new StatusAdapter(timelineStatuses, timelineType, minified, canBeFederated);
|
||||
|
@ -548,7 +548,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
for (Status statusAlreadyPresent : timelineStatuses) {
|
||||
//We compare the id of each status and we only add status having an id greater than the another, it is inserted at this position
|
||||
//Pinned messages are ignored because their date can be older
|
||||
if (statusReceived.id.compareTo(statusAlreadyPresent.id) > 0 && !statusAlreadyPresent.pinned) {
|
||||
if (Helper.compareTo(statusReceived.id, statusAlreadyPresent.id) > 0 && !statusAlreadyPresent.pinned) {
|
||||
//We add the status to a list of id - thus we know it is already in the timeline
|
||||
if (!timelineStatuses.contains(statusReceived)) {
|
||||
timelineStatuses.add(position, statusReceived);
|
||||
|
|
Loading…
Reference in New Issue