Some fixes

This commit is contained in:
Thomas 2022-12-16 17:15:46 +01:00
parent 30f21c035d
commit 0cbf0bfbd4
5 changed files with 62 additions and 20 deletions

View File

@ -761,6 +761,16 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
//Fetch some db values to initialize data //Fetch some db values to initialize data
new Thread(() -> { new Thread(() -> {
try { 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); MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount);
if (mutedAccounts != null && mutedAccounts.accounts != null) { if (mutedAccounts != null && mutedAccounts.accounts != null) {
filteredAccounts = mutedAccounts.accounts; filteredAccounts = mutedAccounts.accounts;

View File

@ -137,6 +137,8 @@ public class TimelineHelper {
if (m.find()) { if (m.find()) {
status.filteredByApp = filter; status.filteredByApp = filter;
continue; continue;
} else {
status.filteredByApp = null;
} }
if (status.spoiler_text != null) { if (status.spoiler_text != null) {
String spoilerText; String spoilerText;
@ -147,12 +149,20 @@ public class TimelineHelper {
Matcher ms = p.matcher(spoilerText); Matcher ms = p.matcher(spoilerText);
if (ms.find()) { if (ms.find()) {
status.filteredByApp = filter; status.filteredByApp = filter;
continue; } else {
status.filteredByApp = null;
}
}
}
}
} }
} }
if (filterTimeLineType == Timeline.TimeLineEnum.HOME) { if (filterTimeLineType == Timeline.TimeLineEnum.HOME) {
if (filteredAccounts != null && filteredAccounts.size() > 0) { if (filteredAccounts != null && filteredAccounts.size() > 0) {
for (Status status : statuses) {
if (status.filteredByApp != null) {
continue;
}
for (Account account : filteredAccounts) { for (Account account : filteredAccounts) {
if (account.acct.equals(status.account.acct) || (status.reblog != null && account.acct.equals(status.reblog.account.acct))) { if (account.acct.equals(status.account.acct) || (status.reblog != null && account.acct.equals(status.reblog.account.acct))) {
Filter filterCustom = new Filter(); Filter filterCustom = new Filter();
@ -168,9 +178,6 @@ public class TimelineHelper {
} }
} }
} }
}
}
}
return statuses; return statuses;
} }

View File

@ -177,7 +177,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private String publicTrendsDomain; private String publicTrendsDomain;
private int lockForResumeCall; private int lockForResumeCall;
private boolean isNotPinnedTimeline; private boolean isNotPinnedTimeline;
private int extraCalls;
//Allow to recreate data when detaching/attaching fragment //Allow to recreate data when detaching/attaching fragment
public void recreate() { public void recreate() {
initialStatuses = null; 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 //Only fragment in main view pager should not have the view initialized
//AND Only the first fragment will initialize its view //AND Only the first fragment will initialize its view
flagLoading = false; flagLoading = false;
extraCalls = -1;
} }
@ -454,12 +455,34 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
min_id = fetched_statuses.pagination.min_id; 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) { } else if (direction == DIRECTION.BOTTOM) {
flagLoading = true; flagLoading = true;
} }
if (direction == DIRECTION.SCROLL_TOP) { if (direction == DIRECTION.SCROLL_TOP) {
binding.recyclerView.scrollToPosition(0); binding.recyclerView.scrollToPosition(0);
} }
} }
/** /**
@ -568,6 +591,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
flagLoading = true; flagLoading = true;
binding.loadingNextElements.setVisibility(View.VISIBLE); binding.loadingNextElements.setVisibility(View.VISIBLE);
router(DIRECTION.BOTTOM); router(DIRECTION.BOTTOM);
extraCalls = -1;
} }
} else { } else {
binding.loadingNextElements.setVisibility(View.GONE); binding.loadingNextElements.setVisibility(View.GONE);
@ -577,6 +601,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
flagLoading = true; flagLoading = true;
binding.loadingNextElements.setVisibility(View.VISIBLE); binding.loadingNextElements.setVisibility(View.VISIBLE);
router(DIRECTION.TOP); router(DIRECTION.TOP);
extraCalls = -1;
} }
} }
} }

View File

@ -74,7 +74,7 @@ public class NotificationsVM extends AndroidViewModel {
sortDesc(notificationList); sortDesc(notificationList);
if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { 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 //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).isFetchMore = true;
notificationList.get(notificationList.size() - 1).positionFetchMore = Notification.PositionFetchMore.TOP; notificationList.get(notificationList.size() - 1).positionFetchMore = Notification.PositionFetchMore.TOP;
} }

View File

@ -105,7 +105,7 @@ public class TimelinesVM extends AndroidViewModel {
sortDesc(statusList); sortDesc(statusList);
if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { 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 //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).isFetchMore = true;
statusList.get(statusList.size() - 1).positionFetchMore = Status.PositionFetchMore.TOP; statusList.get(statusList.size() - 1).positionFetchMore = Status.PositionFetchMore.TOP;
} }
@ -128,7 +128,7 @@ public class TimelinesVM extends AndroidViewModel {
sortDescConv(conversationList); sortDescConv(conversationList);
if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { 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 //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).isFetchMore = true;
conversationList.get(conversationList.size() - 1).positionFetchMore = Conversation.PositionFetchMore.TOP; conversationList.get(conversationList.size() - 1).positionFetchMore = Conversation.PositionFetchMore.TOP;
} }