Filter posts by account when opening a featured hashtag

closes #786
This commit is contained in:
Grishka 2024-03-06 15:39:36 +03:00
parent bd189ae322
commit eee0a40224
7 changed files with 69 additions and 10 deletions

View File

@ -1,5 +1,7 @@
package org.joinmastodon.android.api.requests.accounts;
import android.text.TextUtils;
import com.google.gson.reflect.TypeToken;
import org.joinmastodon.android.api.MastodonAPIRequest;
@ -10,7 +12,7 @@ import java.util.List;
import androidx.annotation.NonNull;
public class GetAccountStatuses extends MastodonAPIRequest<List<Status>>{
public GetAccountStatuses(String id, String maxID, String minID, int limit, @NonNull Filter filter){
public GetAccountStatuses(String id, String maxID, String minID, int limit, @NonNull Filter filter, String hashtag){
super(HttpMethod.GET, "/accounts/"+id+"/statuses", new TypeToken<>(){});
if(maxID!=null)
addQueryParameter("max_id", maxID);
@ -29,6 +31,8 @@ public class GetAccountStatuses extends MastodonAPIRequest<List<Status>>{
case OWN_POSTS_AND_REPLIES -> addQueryParameter("exclude_reblogs", "true");
case PINNED -> addQueryParameter("pinned", "true");
}
if(!TextUtils.isEmpty(hashtag))
addQueryParameter("tagged", hashtag);
}
public enum Filter{

View File

@ -10,7 +10,6 @@ import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.accounts.GetAccountStatuses;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.events.RemoveAccountPostsEvent;
import org.joinmastodon.android.events.StatusCreatedEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.Status;
@ -58,7 +57,7 @@ public class AccountTimelineFragment extends StatusListFragment{
@Override
protected void doLoadData(int offset, int count){
currentRequest=new GetAccountStatuses(user.id, offset>0 ? getMaxID() : null, null, count, filter)
currentRequest=new GetAccountStatuses(user.id, offset>0 ? getMaxID() : null, null, count, filter, null)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){

View File

@ -10,7 +10,6 @@ import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels;
import java.util.Collections;
@ -19,6 +18,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import androidx.recyclerview.widget.RecyclerView;
import me.grishka.appkit.Nav;
public class FeaturedHashtagsListFragment extends BaseStatusListFragment<Hashtag>{
private Account account;
@ -45,7 +45,11 @@ public class FeaturedHashtagsListFragment extends BaseStatusListFragment<Hashtag
@Override
public void onItemClick(String id){
UiUtils.openHashtagTimeline(getActivity(), accountID, Objects.requireNonNull(findItemOfType(id, HashtagStatusDisplayItem.class)).tag);
Bundle args=new Bundle();
args.putParcelable("targetAccount", Parcels.wrap(account));
args.putParcelable("hashtag", Parcels.wrap(Objects.requireNonNull(findItemOfType(id, HashtagStatusDisplayItem.class)).tag));
args.putString("account", accountID);
Nav.go(getActivity(), HashtagFeaturedTimelineFragment.class, args);
}
@Override

View File

@ -0,0 +1,47 @@
package org.joinmastodon.android.fragments;
import android.os.Bundle;
import org.joinmastodon.android.api.requests.accounts.GetAccountStatuses;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.model.Status;
import org.parceler.Parcels;
import java.util.List;
import me.grishka.appkit.api.SimpleCallback;
// The difference between this and HashtagTimelineFragment is that this opens from the featured hashtags
// and only shows posts by that account.
public class HashtagFeaturedTimelineFragment extends StatusListFragment{
private Account targetAccount;
private Hashtag hashtag;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
targetAccount=Parcels.unwrap(getArguments().getParcelable("targetAccount"));
hashtag=Parcels.unwrap(getArguments().getParcelable("hashtag"));
setTitle("#"+hashtag.name);
loadData();
}
@Override
protected void doLoadData(int offset, int count){
currentRequest=new GetAccountStatuses(targetAccount.id, offset>0 ? getMaxID() : null, null, count, GetAccountStatuses.Filter.DEFAULT, hashtag.name)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){
if(getActivity()==null)
return;
boolean empty=result.isEmpty();
AccountSessionManager.get(accountID).filterStatuses(result, FilterContext.ACCOUNT);
onDataLoaded(result, !empty);
}
})
.exec(accountID);
}
}

View File

@ -25,7 +25,7 @@ public class PinnedPostsListFragment extends StatusListFragment{
@Override
protected void doLoadData(int offset, int count){
new GetAccountStatuses(account.id, null, null, 100, GetAccountStatuses.Filter.PINNED)
new GetAccountStatuses(account.id, null, null, 100, GetAccountStatuses.Filter.PINNED, null)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){

View File

@ -18,7 +18,6 @@ import org.joinmastodon.android.ui.displayitems.FooterStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.SectionHeaderStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels;
import java.util.ArrayList;
@ -93,7 +92,13 @@ public class ProfileFeaturedFragment extends BaseStatusListFragment<SearchResult
args.putParcelable("profileAccount", Parcels.wrap(res.account));
Nav.go(getActivity(), ProfileFragment.class, args);
}
case HASHTAG -> UiUtils.openHashtagTimeline(getActivity(), accountID, res.hashtag);
case HASHTAG -> {
Bundle args=new Bundle();
args.putParcelable("targetAccount", Parcels.wrap(profileAccount));
args.putParcelable("hashtag", Parcels.wrap(res.hashtag));
args.putString("account", accountID);
Nav.go(getActivity(), HashtagFeaturedTimelineFragment.class, args);
}
case STATUS -> {
Status status=res.status.getContentStatus();
Bundle args=new Bundle();
@ -109,7 +114,7 @@ public class ProfileFeaturedFragment extends BaseStatusListFragment<SearchResult
@Override
protected void doLoadData(int offset, int count){
if(!statusesLoaded){
new GetAccountStatuses(profileAccount.id, null, null, 2, GetAccountStatuses.Filter.PINNED)
new GetAccountStatuses(profileAccount.id, null, null, 2, GetAccountStatuses.Filter.PINNED, null)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){

View File

@ -81,7 +81,7 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{
@Override
protected void doLoadData(int offset, int count){
currentRequest=new GetAccountStatuses(reportAccount.id, offset>0 ? getMaxID() : null, null, count, GetAccountStatuses.Filter.OWN_POSTS_AND_REPLIES)
currentRequest=new GetAccountStatuses(reportAccount.id, offset>0 ? getMaxID() : null, null, count, GetAccountStatuses.Filter.OWN_POSTS_AND_REPLIES, null)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){