Revert "feat: add remote lookups to the PaginatedAccountListFragment"

This reverts commit 74f2bb4707.
This commit is contained in:
LucasGGamerM 2023-04-16 14:13:25 -03:00
parent 74f2bb4707
commit fb02689c30
5 changed files with 12 additions and 143 deletions

View File

@ -6,7 +6,6 @@ import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.requests.accounts.GetAccountFollowers;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Status;
public class FollowerListFragment extends AccountRelatedAccountListFragment{
@ -16,22 +15,8 @@ public class FollowerListFragment extends AccountRelatedAccountListFragment{
setSubtitle(getResources().getQuantityString(R.plurals.x_followers, (int)(account.followersCount%1000), account.followersCount));
}
@Override
public Account getTargetAccount(){
return account;
}
@Override
public Status getTargetStatus(){
return null;
}
@Override
public HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count){
return new GetAccountFollowers(account.id, maxID, count);
}
@Override
public HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count){
return new GetAccountFollowers(id, maxID, count);
}
}

View File

@ -6,7 +6,6 @@ import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.requests.accounts.GetAccountFollowing;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Status;
public class FollowingListFragment extends AccountRelatedAccountListFragment{
@ -15,22 +14,9 @@ public class FollowingListFragment extends AccountRelatedAccountListFragment{
super.onCreate(savedInstanceState);
setSubtitle(getResources().getQuantityString(R.plurals.x_following, (int)(account.followingCount%1000), account.followingCount));
}
@Override
public Account getTargetAccount(){
return account;
}
@Override
public Status getTargetStatus(){
return null;
}
@Override
public HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count){
return new GetAccountFollowing(account.id, maxID, count);
}
@Override
public HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count){
return new GetAccountFollowing(id, maxID, count);
}
}

View File

@ -1,106 +1,33 @@
package org.joinmastodon.android.fragments.account_list;
import android.app.Activity;
import android.widget.Toast;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.requests.search.GetSearchResults;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.model.SearchResults;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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{
private String nextMaxID;
public abstract Status getTargetStatus();
public abstract Account getTargetAccount();
public abstract HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count);
public abstract HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count);
@Override
protected void doLoadData(int offset, int count){
if(!GlobalUserPreferences.relocatePublishButton){
currentRequest=onCreateRequest(offset==0 ? null : nextMaxID, count)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(HeaderPaginationList<Account> 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);
} else {
Status targetStatus = getTargetStatus();
Account targetAccount = getTargetAccount();
if(targetAccount != null){
UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> {
Pattern pattern = Pattern.compile("(?<=\\/\\/)([^\\/]+)(?=\\/@)");
Matcher matcher = pattern.matcher(account.url);
String domain = null;
if(matcher.find()){
domain = matcher.group(1);
currentRequest=onCreateRequest(offset==0 ? null : nextMaxID, count)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(HeaderPaginationList<Account> 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);
}
currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count)
.setCallback(new SimpleCallback<>(this) {
@Override
public void onSuccess(HeaderPaginationList<Account> 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);
}
}).execNoAuth(domain);
});
return;
}
if(targetStatus != null){
UiUtils.lookupRemoteStatus(getContext(), targetStatus, accountID, null, status -> {
Pattern pattern = Pattern.compile("(?<=\\/\\/)([^\\/]+)(?=\\/@)");
Matcher matcher = pattern.matcher(status.url);
String domain = null;
if(matcher.find()){
domain = matcher.group(1);
}
currentRequest=onCreateRemoteRequest(status.id, offset==0 ? null : nextMaxID, count)
.setCallback(new SimpleCallback<>(this) {
@Override
public void onSuccess(HeaderPaginationList<Account> 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);
}
}).execNoAuth(domain);
});
}
}
})
.exec(accountID);
}
@Override

View File

@ -6,7 +6,6 @@ import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.requests.statuses.GetStatusFavorites;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Status;
public class StatusFavoritesListFragment extends StatusRelatedAccountListFragment{
@Override
@ -15,22 +14,8 @@ public class StatusFavoritesListFragment extends StatusRelatedAccountListFragmen
setTitle(getResources().getQuantityString(R.plurals.x_favorites, (int)(status.favouritesCount%1000), status.favouritesCount));
}
@Override
public Account getTargetAccount(){
return null;
}
@Override
public Status getTargetStatus(){
return status;
}
@Override
public HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count){
return new GetStatusFavorites(status.id, maxID, count);
}
@Override
public HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count){
return new GetStatusFavorites(id, maxID, count);
}
}

View File

@ -6,7 +6,6 @@ import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.requests.statuses.GetStatusReblogs;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Status;
public class StatusReblogsListFragment extends StatusRelatedAccountListFragment{
@Override
@ -15,21 +14,8 @@ public class StatusReblogsListFragment extends StatusRelatedAccountListFragment{
setTitle(getResources().getQuantityString(R.plurals.x_reblogs, (int)(status.reblogsCount%1000), status.reblogsCount));
}
@Override
public Account getTargetAccount(){
return null;
}
@Override
public Status getTargetStatus(){
return status;
}
@Override
public HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count){
return new GetStatusReblogs(status.id, maxID, count);
}
@Override
public HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count){
return new GetStatusReblogs(id, maxID, count);
}
}