From e4f4ca5392fe4b841769b30c0fc3676538d8e5ab Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 16 Apr 2023 21:13:20 +0200 Subject: [PATCH] refactor: move request to their own methods --- .../PaginatedAccountListFragment.java | 86 +++++++++---------- 1 file changed, 41 insertions(+), 45 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 97da06083..49cc5c6a8 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 @@ -27,59 +27,55 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme if ((this instanceof FollowingListFragment || this instanceof FollowerListFragment) && targetAccount != null){ UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> { if(account != null && account.getDomain() != null){ - currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count) - .setCallback(new SimpleCallback<>(this){ - @Override - public void onSuccess(HeaderPaginationList result){ - if(result.nextPageUri!=null) - nextMaxID=result.nextPageUri.getQueryParameter("max_id"); - else - nextMaxID=null; - result.stream().forEach(remoteAccount -> { - remoteAccount.reloadWhenClicked = true; - if (remoteAccount.getDomain() == null) { - remoteAccount.acct += "@" + Uri.parse(remoteAccount.url).getHost(); - } - }); - if (getActivity() == null) return; - onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false); - } - }) - .execNoAuth(targetAccount.getDomain()); + loadRemoteFollower(offset, count, account); } else { - currentRequest=onCreateRequest(offset==0 ? null : nextMaxID, count) - .setCallback(new SimpleCallback<>(this){ - @Override - public void onSuccess(HeaderPaginationList result){ - if(result.nextPageUri!=null) - nextMaxID=result.nextPageUri.getQueryParameter("max_id"); - else - nextMaxID=null; - if (getActivity() == null) return; - onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), nextMaxID!=null); - } - }) - .exec(accountID); + loadFollower(offset, count); } }); } } else { - currentRequest=onCreateRequest(offset==0 ? null : nextMaxID, count) - .setCallback(new SimpleCallback<>(this){ - @Override - public void onSuccess(HeaderPaginationList result){ - if(result.nextPageUri!=null) - nextMaxID=result.nextPageUri.getQueryParameter("max_id"); - else - nextMaxID=null; - if (getActivity() == null) return; - onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), nextMaxID!=null); - } - }) - .exec(accountID); + loadFollower(offset, count); } } + void loadFollower(int offset, int count) { + currentRequest=onCreateRequest(offset==0 ? null : nextMaxID, count) + .setCallback(new SimpleCallback<>(this){ + @Override + public void onSuccess(HeaderPaginationList result){ + if(result.nextPageUri!=null) + nextMaxID=result.nextPageUri.getQueryParameter("max_id"); + else + nextMaxID=null; + if (getActivity() == null) return; + onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), nextMaxID!=null); + } + }) + .exec(accountID); + } + + private void loadRemoteFollower(int offset, int count, Account account) { + currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count) + .setCallback(new SimpleCallback<>(this){ + @Override + public void onSuccess(HeaderPaginationList result){ + if(result.nextPageUri!=null) + nextMaxID=result.nextPageUri.getQueryParameter("max_id"); + else + nextMaxID=null; + result.stream().forEach(remoteAccount -> { + remoteAccount.reloadWhenClicked = true; + if (remoteAccount.getDomain() == null) { + remoteAccount.acct += "@" + Uri.parse(remoteAccount.url).getHost(); + } + }); + if (getActivity() == null) return; + onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false); + } + }) + .execNoAuth(targetAccount.getDomain()); + } + @Override public void onResume(){ super.onResume();