From 0cbf0bfbd47d405764a82247d500813a1db695d9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 16 Dec 2022 17:15:46 +0100 Subject: [PATCH] Some fixes --- .../app/fedilab/android/BaseMainActivity.java | 10 +++++ .../android/helper/TimelineHelper.java | 39 +++++++++++-------- .../timeline/FragmentMastodonTimeline.java | 27 ++++++++++++- .../viewmodel/mastodon/NotificationsVM.java | 2 +- .../viewmodel/mastodon/TimelinesVM.java | 4 +- 5 files changed, 62 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 681cf173..0ebb6a3b 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -761,6 +761,16 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt //Fetch some db values to initialize data new Thread(() -> { try { + if (currentAccount == null) { + if (currentToken == null || currentToken.trim().isEmpty()) { + currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); + } + try { + currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); + } catch (DBException e) { + e.printStackTrace(); + } + } MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount); if (mutedAccounts != null && mutedAccounts.accounts != null) { filteredAccounts = mutedAccounts.accounts; diff --git a/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java index 66b01ba8..589528a8 100644 --- a/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java @@ -137,6 +137,8 @@ public class TimelineHelper { if (m.find()) { status.filteredByApp = filter; continue; + } else { + status.filteredByApp = null; } if (status.spoiler_text != null) { String spoilerText; @@ -147,24 +149,29 @@ public class TimelineHelper { Matcher ms = p.matcher(spoilerText); if (ms.find()) { status.filteredByApp = filter; - continue; + } else { + status.filteredByApp = null; } } - - if (filterTimeLineType == Timeline.TimeLineEnum.HOME) { - if (filteredAccounts != null && filteredAccounts.size() > 0) { - for (Account account : filteredAccounts) { - if (account.acct.equals(status.account.acct) || (status.reblog != null && account.acct.equals(status.reblog.account.acct))) { - Filter filterCustom = new Filter(); - filterCustom.filter_action = "hide"; - ArrayList contextCustom = new ArrayList<>(); - contextCustom.add("home"); - filterCustom.title = "Fedilab"; - filterCustom.context = contextCustom; - status.filteredByApp = filterCustom; - } - } - } + } + } + } + } + if (filterTimeLineType == Timeline.TimeLineEnum.HOME) { + if (filteredAccounts != null && filteredAccounts.size() > 0) { + for (Status status : statuses) { + if (status.filteredByApp != null) { + continue; + } + for (Account account : filteredAccounts) { + if (account.acct.equals(status.account.acct) || (status.reblog != null && account.acct.equals(status.reblog.account.acct))) { + Filter filterCustom = new Filter(); + filterCustom.filter_action = "hide"; + ArrayList contextCustom = new ArrayList<>(); + contextCustom.add("home"); + filterCustom.title = "Fedilab"; + filterCustom.context = contextCustom; + status.filteredByApp = filterCustom; } } } 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 1ae41045..cdc3462a 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 @@ -177,7 +177,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private String publicTrendsDomain; private int lockForResumeCall; private boolean isNotPinnedTimeline; - + private int extraCalls; //Allow to recreate data when detaching/attaching fragment public void recreate() { initialStatuses = null; @@ -290,6 +290,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. //Only fragment in main view pager should not have the view initialized //AND Only the first fragment will initialize its view flagLoading = false; + extraCalls = -1; } @@ -454,12 +455,34 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. min_id = fetched_statuses.pagination.min_id; } } + int sizeBeforeFilter = 0; + int filteredMessage = 0; + int requestedMessages = MastodonHelper.statusesPerCall(requireActivity()); + sizeBeforeFilter = fetched_statuses.statuses.size(); + for (Status status : fetched_statuses.statuses) { + if (status.filteredByApp != null) { + filteredMessage++; + } + } + //TODO: keep for an improvement in beta + /* + int displayedMessages = sizeBeforeFilter - filteredMessage; + if(displayedMessages < 5 && extraCalls < 8) { + router(direction); + if(extraCalls == -1) { + extraCalls = 1; + } else { + extraCalls++; + } + }*/ } else if (direction == DIRECTION.BOTTOM) { flagLoading = true; } if (direction == DIRECTION.SCROLL_TOP) { binding.recyclerView.scrollToPosition(0); } + + } /** @@ -568,6 +591,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. flagLoading = true; binding.loadingNextElements.setVisibility(View.VISIBLE); router(DIRECTION.BOTTOM); + extraCalls = -1; } } else { binding.loadingNextElements.setVisibility(View.GONE); @@ -577,6 +601,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. flagLoading = true; binding.loadingNextElements.setVisibility(View.VISIBLE); router(DIRECTION.TOP); + extraCalls = -1; } } } diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java index cb9d624c..d7ee2dd4 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java @@ -74,7 +74,7 @@ public class NotificationsVM extends AndroidViewModel { sortDesc(notificationList); if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { //When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole - if (notificationList.get(notificationList.size() - 1).id.compareToIgnoreCase(timelineNotifications.get(0).id) > 0) { + if (!timelineNotifications.contains(notificationList.get(notificationList.size() - 1))) { notificationList.get(notificationList.size() - 1).isFetchMore = true; notificationList.get(notificationList.size() - 1).positionFetchMore = Notification.PositionFetchMore.TOP; } 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 4b98de70..a40ddaa1 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 @@ -105,7 +105,7 @@ public class TimelinesVM extends AndroidViewModel { sortDesc(statusList); if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { //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) { + if (!timelineStatuses.contains(statusList.get(statusList.size() - 1))) { statusList.get(statusList.size() - 1).isFetchMore = true; statusList.get(statusList.size() - 1).positionFetchMore = Status.PositionFetchMore.TOP; } @@ -128,7 +128,7 @@ public class TimelinesVM extends AndroidViewModel { sortDescConv(conversationList); if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { //When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole - if (conversationList.get(conversationList.size() - 1).id.compareToIgnoreCase(timelineConversations.get(0).id) > 0) { + if (!timelineConversations.contains(conversationList.get(conversationList.size() - 1))) { conversationList.get(conversationList.size() - 1).isFetchMore = true; conversationList.get(conversationList.size() - 1).positionFetchMore = Conversation.PositionFetchMore.TOP; }