Add a fallback when remote profiles are not working

fix
Thomas 1 year ago
parent be8943163a
commit 3858220937

@ -25,6 +25,7 @@ android {
} }
debug { debug {
applicationIdSuffix '.debug' applicationIdSuffix '.debug'
pseudoLocalesEnabled true
} }
} }
compileOptions { compileOptions {
@ -99,7 +100,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0-beta01' implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

@ -508,7 +508,7 @@ public class CrossActionHelper {
} }
} }
} }
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

@ -133,8 +133,9 @@ public class FragmentMastodonAccount extends Fragment {
if (results != null && results.accounts.size() > 0) { if (results != null && results.accounts.size() > 0) {
remoteAccountId = results.accounts.get(0).id; remoteAccountId = results.accounts.get(0).id;
fetchAccount(firstLoad, remoteAccountId); fetchAccount(firstLoad, remoteAccountId);
} else { } else { //FallBack the app failed to find remote accounts
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); checkRemotely = false;
fetchAccount(firstLoad, accountTimeline != null ? accountTimeline.id : null);
} }
}); });
} else { } else {

@ -1036,15 +1036,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE } else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
routeCommon(direction, fetchingMissing, fetchStatus); routeCommon(direction, fetchingMissing, fetchStatus);
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES } else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
String tempToken; final String[] tempToken = new String[1];
String tempInstance; final String[] tempInstance = new String[1];
String accountId; final String[] accountId = new String[1];
if (checkRemotely) { if (checkRemotely) {
tempToken = null; tempToken[0] = null;
tempInstance = remoteInstance; tempInstance[0] = remoteInstance;
accountId = accountIDInRemoteInstance; accountId[0] = accountIDInRemoteInstance;
if (accountIDInRemoteInstance == null) { if (accountIDInRemoteInstance == null) {
CrossActionHelper.fetchAccountInRemoteInstance(requireActivity(), accountTimeline.acct, tempInstance, new CrossActionHelper.Callback() { CrossActionHelper.fetchAccountInRemoteInstance(requireActivity(), accountTimeline.acct, tempInstance[0], new CrossActionHelper.Callback() {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
} }
@ -1053,8 +1053,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
public void federatedAccount(Account account) { public void federatedAccount(Account account) {
if (account != null && isAdded() && !requireActivity().isFinishing()) { if (account != null && isAdded() && !requireActivity().isFinishing()) {
accountIDInRemoteInstance = account.id; accountIDInRemoteInstance = account.id;
accountsVM.getAccountStatuses(tempInstance, null, accountIDInRemoteInstance, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(tempInstance[0], null, accountIDInRemoteInstance, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(tempInstance, null, accountIDInRemoteInstance, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(tempInstance[0], null, accountIDInRemoteInstance, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), otherStatuses -> { .observe(getViewLifecycleOwner(), otherStatuses -> {
if (otherStatuses != null && otherStatuses.statuses != null) { if (otherStatuses != null && otherStatuses.statuses != null) {
if (pinnedStatuses != null && pinnedStatuses.statuses != null) { if (pinnedStatuses != null && pinnedStatuses.statuses != null) {
@ -1067,47 +1067,25 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
initializeStatusesCommonView(otherStatuses); initializeStatusesCommonView(otherStatuses);
})); }));
} else { } else {
if (isAdded() && !requireActivity().isFinishing()) { tempToken[0] = MainActivity.currentToken;
Toasty.error(requireActivity(), getString(R.string.toast_fetch_error), Toasty.LENGTH_LONG).show(); tempInstance[0] = currentInstance;
} accountId[0] = accountTimeline.id;
displayStatuses(direction, accountId[0], tempInstance[0], tempToken[0], fetchStatus);
} }
} }
}); });
} else { } else {
accountId = accountIDInRemoteInstance; accountId[0] = accountIDInRemoteInstance;
} }
} else { } else {
tempToken = MainActivity.currentToken; tempToken[0] = MainActivity.currentToken;
tempInstance = currentInstance; tempInstance[0] = currentInstance;
accountId = accountTimeline.id; accountId[0] = accountTimeline.id;
}
if (accountId == null) {
accountId = accountTimeline.id;
}
if (direction == null && !checkRemotely) {
if (show_pinned) {
//Fetch pinned statuses to display them at the top
accountsVM.getAccountStatuses(currentInstance, MainActivity.currentToken, accountId, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), otherStatuses -> {
if (otherStatuses != null && otherStatuses.statuses != null && pinnedStatuses != null && pinnedStatuses.statuses != null) {
for (Status status : pinnedStatuses.statuses) {
status.pinned = true;
} }
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses); if (accountId[0] == null) {
initializeStatusesCommonView(otherStatuses); accountId[0] = accountTimeline.id;
}
}));
} else {
accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
}
} else if (direction == DIRECTION.BOTTOM) {
accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else {
flagLoading = false;
} }
displayStatuses(direction, accountId[0], tempInstance[0], tempToken[0], fetchStatus);
} else if (search != null) { } else if (search != null) {
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
if (direction == null) { if (direction == null) {
@ -1189,7 +1167,42 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
flagLoading = false; flagLoading = false;
} }
} }
}
/**
* FallBack when remote profile is enabled
*
* @param direction - DIRECTION
* @param accountId - String account id
* @param tempInstance - Used instance
* @param tempToken - Token
* @param fetchStatus - Status fetched
*/
private void displayStatuses(DIRECTION direction, String accountId, String tempInstance, String tempToken, Status fetchStatus) {
if (direction == null && !checkRemotely) {
if (show_pinned) {
//Fetch pinned statuses to display them at the top
accountsVM.getAccountStatuses(currentInstance, MainActivity.currentToken, accountId, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), otherStatuses -> {
if (otherStatuses != null && otherStatuses.statuses != null && pinnedStatuses != null && pinnedStatuses.statuses != null) {
for (Status status : pinnedStatuses.statuses) {
status.pinned = true;
}
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses);
initializeStatusesCommonView(otherStatuses);
}
}));
} else {
accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
}
} else if (direction == DIRECTION.BOTTOM) {
accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else {
flagLoading = false;
}
} }
/** /**

Loading…
Cancel
Save