From c3c76126a388e2e110a0d42c318629dfc4d4761d Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 16 Apr 2023 21:32:26 +0200 Subject: [PATCH] feat(follower): show own domain accounts as username --- .../PaginatedAccountListFragment.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/PaginatedAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/PaginatedAccountListFragment.java index 10b265190..67df4cef4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/PaginatedAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/PaginatedAccountListFragment.java @@ -4,12 +4,16 @@ import android.net.Uri; import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.api.requests.HeaderPaginationRequest; +import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.ui.utils.UiUtils; +import java.util.Objects; import java.util.stream.Collectors; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; public abstract class PaginatedAccountListFragment extends BaseAccountListFragment{ @@ -23,10 +27,10 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme @Override protected void doLoadData(int offset, int count){ - if(GlobalUserPreferences.loadRemoteAccountFollowers){ + if(GlobalUserPreferences.loadRemoteAccountFollowers && targetAccount.getDomain() != null){ if ((this instanceof FollowingListFragment || this instanceof FollowerListFragment) && targetAccount != null){ UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> { - if(account != null && account.getDomain() != null){ + if(account != null){ loadRemoteFollower(offset, count, account); } else { loadFollower(offset, count); @@ -54,8 +58,9 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme } private void loadRemoteFollower(int offset, int count, Account account) { + String ownDomain = AccountSessionManager.getInstance().getLastActiveAccount().domain; currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count) - .setCallback(new SimpleCallback<>(this){ + .setCallback(new Callback<>(){ @Override public void onSuccess(HeaderPaginationList result){ if(result.nextPageUri!=null) @@ -66,10 +71,18 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme remoteAccount.reloadWhenClicked = true; if (remoteAccount.getDomain() == null) { remoteAccount.acct += "@" + Uri.parse(remoteAccount.url).getHost(); + } else if (remoteAccount.getDomain().equals(ownDomain)) { + remoteAccount.acct = remoteAccount.username; } }); onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false); } + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + loadFollower(offset, count); + } }) .execNoAuth(targetAccount.getDomain()); }