feat: add remote follower and following lookup
Clicking the regenerated accounts wont do anything for now though
This commit is contained in:
parent
fb02689c30
commit
7c8698521d
|
@ -53,6 +53,7 @@ public class GlobalUserPreferences{
|
|||
public static boolean confirmBeforeReblog;
|
||||
public static boolean replyLineAboveHeader;
|
||||
public static boolean swapBookmarkWithBoostAction;
|
||||
public static boolean loadRemoteAccountFollowers;
|
||||
public static String publishButtonText;
|
||||
public static ThemePreference theme;
|
||||
public static ColorPreference color;
|
||||
|
@ -120,6 +121,7 @@ public class GlobalUserPreferences{
|
|||
compactReblogReplyLine=prefs.getBoolean("compactReblogReplyLine", true);
|
||||
confirmBeforeReblog=prefs.getBoolean("confirmBeforeReblog", false);
|
||||
swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false);
|
||||
loadRemoteAccountFollowers=prefs.getBoolean("loadRemoteAccountFollowers", true);
|
||||
publishButtonText=prefs.getString("publishButtonText", "");
|
||||
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
|
||||
recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>());
|
||||
|
@ -178,6 +180,7 @@ public class GlobalUserPreferences{
|
|||
.putBoolean("replyLineAboveHeader", replyLineAboveHeader)
|
||||
.putBoolean("confirmBeforeReblog", confirmBeforeReblog)
|
||||
.putBoolean("swapBookmarkWithBoostAction", swapBookmarkWithBoostAction)
|
||||
.putBoolean("loadRemoteAccountFollowers", loadRemoteAccountFollowers)
|
||||
.putInt("theme", theme.ordinal())
|
||||
.putString("color", color.name())
|
||||
.putString("recentLanguages", gson.toJson(recentLanguages))
|
||||
|
|
|
@ -12,6 +12,7 @@ public class FollowerListFragment extends AccountRelatedAccountListFragment{
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
targetAccount = account;
|
||||
setSubtitle(getResources().getQuantityString(R.plurals.x_followers, (int)(account.followersCount%1000), account.followersCount));
|
||||
}
|
||||
|
||||
|
@ -19,4 +20,9 @@ public class FollowerListFragment extends AccountRelatedAccountListFragment{
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public class FollowingListFragment extends AccountRelatedAccountListFragment{
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
targetAccount = account;
|
||||
setSubtitle(getResources().getQuantityString(R.plurals.x_following, (int)(account.followingCount%1000), account.followingCount));
|
||||
}
|
||||
|
||||
|
@ -19,4 +20,9 @@ public class FollowingListFragment extends AccountRelatedAccountListFragment{
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
package org.joinmastodon.android.fragments.account_list;
|
||||
|
||||
import android.app.VoiceInteractor;
|
||||
|
||||
import org.joinmastodon.android.GlobalUserPreferences;
|
||||
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.HeaderPaginationList;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.grishka.appkit.api.SimpleCallback;
|
||||
|
@ -11,23 +17,66 @@ import me.grishka.appkit.api.SimpleCallback;
|
|||
public abstract class PaginatedAccountListFragment extends BaseAccountListFragment{
|
||||
private String nextMaxID;
|
||||
|
||||
protected Account targetAccount;
|
||||
|
||||
public abstract HeaderPaginationRequest<Account> onCreateRequest(String maxID, int count);
|
||||
|
||||
public abstract HeaderPaginationRequest<Account> onCreateRemoteRequest(String id, String maxID, int count);
|
||||
|
||||
@Override
|
||||
protected void doLoadData(int offset, int count){
|
||||
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);
|
||||
if(GlobalUserPreferences.loadRemoteAccountFollowers){
|
||||
if ((this instanceof FollowingListFragment || this instanceof FollowerListFragment) && targetAccount != null){
|
||||
UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> {
|
||||
if(account != 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;
|
||||
result.stream().forEach(account1 -> {
|
||||
account1.reloadWhenClicked = true;
|
||||
});
|
||||
if (getActivity() == null) return;
|
||||
onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false);
|
||||
}
|
||||
})
|
||||
.execNoAuth(targetAccount.getDomain());
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
})
|
||||
.exec(accountID);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,4 +18,9 @@ public class StatusFavoritesListFragment extends StatusRelatedAccountListFragmen
|
|||
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 null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,4 +18,9 @@ public class StatusReblogsListFragment extends StatusRelatedAccountListFragment{
|
|||
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 null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,8 +134,9 @@ public class Account extends BaseModel implements Searchable{
|
|||
public Instant muteExpiresAt;
|
||||
|
||||
public List<Role> roles;
|
||||
public boolean reloadWhenClicked;
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getQuery() {
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -1127,7 +1127,19 @@ public class UiUtils {
|
|||
return;
|
||||
}
|
||||
|
||||
new GetSearchResults(query.getQuery(), type, false).setCallback(new Callback<>() {
|
||||
Pattern patternForQuery = Pattern.compile("https?:\\/\\/[^\\/]+\\/@(\\w+)");
|
||||
Matcher matcherForQuery = patternForQuery.matcher(query.getQuery());
|
||||
String trimmedQuery = null;
|
||||
|
||||
if(matcherForQuery.find()){
|
||||
trimmedQuery = matcherForQuery.group(1);
|
||||
}
|
||||
|
||||
if(trimmedQuery == null){
|
||||
return;
|
||||
}
|
||||
|
||||
new GetSearchResults(trimmedQuery, type, false).setCallback(new Callback<>() {
|
||||
@Override
|
||||
public void onSuccess(SearchResults results) {
|
||||
Optional<T> result = extractResult.apply(results);
|
||||
|
|
Loading…
Reference in New Issue