Rewriting the custom local timelines

This commit is contained in:
LucasGGamerM 2023-02-20 11:49:48 -03:00
parent 6f37eb9625
commit b5844a5f8c
4 changed files with 113 additions and 3 deletions

View File

@ -0,0 +1,70 @@
package org.joinmastodon.android.fragments;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.utils.StatusFilterPredicate;
import java.util.List;
import java.util.stream.Collectors;
import me.grishka.appkit.api.SimpleCallback;
public class CustomLocalTimelineFragment extends PinnableStatusListFragment {
// private String name;
private String domain;
private String maxID;
@Override
protected boolean withComposeButton() {
return false;
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
domain=getArguments().getString("domain");
updateTitle(domain);
setHasOptionsMenu(true);
}
private void updateTitle(String domain) {
this.domain = domain;
setTitle(this.domain);
}
@Override
protected TimelineDefinition makeTimelineDefinition() {
return TimelineDefinition.ofCustomLocalTimeline(domain);
}
@Override
protected void doLoadData(int offset, int count){
currentRequest=new GetPublicTimeline(true, false, refreshing ? null : maxID, count)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){
if(!result.isEmpty())
maxID=result.get(result.size()-1).id;
if (getActivity() == null) return;
result=result.stream().filter(new StatusFilterPredicate(accountID, Filter.FilterContext.PUBLIC)).collect(Collectors.toList());
onDataLoaded(result, !result.isEmpty());
}
})
.execNoAuth(domain);
}
@Override
protected void onShown(){
super.onShown();
if(!getArguments().getBoolean("noAutoLoad") && !loaded && !dataLoading)
loadData();
}
}

View File

@ -30,6 +30,7 @@ import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.lists.GetLists; import org.joinmastodon.android.api.requests.lists.GetLists;
import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags; import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags;
import org.joinmastodon.android.model.CustomLocalTimeline;
import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.model.ListTimeline; import org.joinmastodon.android.model.ListTimeline;
@ -60,6 +61,7 @@ public class EditTimelinesFragment extends BaseRecyclerFragment<TimelineDefiniti
private final Map<MenuItem, TimelineDefinition> timelineByMenuItem = new HashMap<>(); private final Map<MenuItem, TimelineDefinition> timelineByMenuItem = new HashMap<>();
private final List<ListTimeline> listTimelines = new ArrayList<>(); private final List<ListTimeline> listTimelines = new ArrayList<>();
private final List<Hashtag> hashtags = new ArrayList<>(); private final List<Hashtag> hashtags = new ArrayList<>();
private final List<CustomLocalTimeline> localTimelines = new ArrayList<>();
public EditTimelinesFragment() { public EditTimelinesFragment() {
super(10); super(10);
@ -160,6 +162,8 @@ public class EditTimelinesFragment extends BaseRecyclerFragment<TimelineDefiniti
listsMenu.getItem().setIcon(R.drawable.ic_fluent_people_24_regular); listsMenu.getItem().setIcon(R.drawable.ic_fluent_people_24_regular);
SubMenu hashtagsMenu = menu.addSubMenu(R.string.sk_hashtag); SubMenu hashtagsMenu = menu.addSubMenu(R.string.sk_hashtag);
hashtagsMenu.getItem().setIcon(R.drawable.ic_fluent_number_symbol_24_regular); hashtagsMenu.getItem().setIcon(R.drawable.ic_fluent_number_symbol_24_regular);
// SubMenu hashtagsMenu = menu.addSubMenu(R.string.sk_hashtag);
// hashtagsMenu.getItem().setIcon(R.drawable.ic_fluent_number_symbol_24_regular);
makeBackItem(timelinesMenu); makeBackItem(timelinesMenu);
makeBackItem(listsMenu); makeBackItem(listsMenu);

View File

@ -0,0 +1,19 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
import java.util.List;
@Parcel
public class CustomLocalTimeline extends BaseModel{
@RequiredField
public String domain;
@Override
public String toString(){
return "Hashtag{"+
", url='"+domain+'\''+
'}';
}
}

View File

@ -10,6 +10,7 @@ import androidx.annotation.StringRes;
import org.joinmastodon.android.BuildConfig; import org.joinmastodon.android.BuildConfig;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.CustomLocalTimelineFragment;
import org.joinmastodon.android.fragments.HashtagTimelineFragment; import org.joinmastodon.android.fragments.HashtagTimelineFragment;
import org.joinmastodon.android.fragments.HomeTimelineFragment; import org.joinmastodon.android.fragments.HomeTimelineFragment;
import org.joinmastodon.android.fragments.ListTimelineFragment; import org.joinmastodon.android.fragments.ListTimelineFragment;
@ -27,7 +28,7 @@ public class TimelineDefinition {
private @Nullable String listId; private @Nullable String listId;
private @Nullable String listTitle; private @Nullable String listTitle;
private @Nullable String domain;
private @Nullable String hashtagName; private @Nullable String hashtagName;
public static TimelineDefinition ofList(String listId, String listTitle) { public static TimelineDefinition ofList(String listId, String listTitle) {
@ -47,6 +48,12 @@ public class TimelineDefinition {
return def; return def;
} }
public static TimelineDefinition ofCustomLocalTimeline(String domain) {
TimelineDefinition def = new TimelineDefinition(TimelineType.CUSTOM_LOCAL_TIMELINE);
def.domain = domain;
return def;
}
public static TimelineDefinition ofHashtag(Hashtag hashtag) { public static TimelineDefinition ofHashtag(Hashtag hashtag) {
return ofHashtag(hashtag.name); return ofHashtag(hashtag.name);
} }
@ -78,6 +85,7 @@ public class TimelineDefinition {
case POST_NOTIFICATIONS -> ctx.getString(R.string.sk_timeline_posts); case POST_NOTIFICATIONS -> ctx.getString(R.string.sk_timeline_posts);
case LIST -> listTitle; case LIST -> listTitle;
case HASHTAG -> hashtagName; case HASHTAG -> hashtagName;
case CUSTOM_LOCAL_TIMELINE -> domain;
}; };
} }
@ -89,6 +97,7 @@ public class TimelineDefinition {
case POST_NOTIFICATIONS -> Icon.POST_NOTIFICATIONS; case POST_NOTIFICATIONS -> Icon.POST_NOTIFICATIONS;
case LIST -> Icon.LIST; case LIST -> Icon.LIST;
case HASHTAG -> Icon.HASHTAG; case HASHTAG -> Icon.HASHTAG;
case CUSTOM_LOCAL_TIMELINE -> Icon.CUSTOM_LOCAL_TIMELINE;
}; };
} }
@ -100,6 +109,7 @@ public class TimelineDefinition {
case LIST -> new ListTimelineFragment(); case LIST -> new ListTimelineFragment();
case HASHTAG -> new HashtagTimelineFragment(); case HASHTAG -> new HashtagTimelineFragment();
case POST_NOTIFICATIONS -> new NotificationsListFragment(); case POST_NOTIFICATIONS -> new NotificationsListFragment();
case CUSTOM_LOCAL_TIMELINE -> new CustomLocalTimelineFragment();
}; };
} }
@ -125,6 +135,7 @@ public class TimelineDefinition {
if (type != that.type) return false; if (type != that.type) return false;
if (type == TimelineType.LIST) return Objects.equals(listId, that.listId); if (type == TimelineType.LIST) return Objects.equals(listId, that.listId);
if (type == TimelineType.HASHTAG) return Objects.equals(hashtagName.toLowerCase(), that.hashtagName.toLowerCase()); if (type == TimelineType.HASHTAG) return Objects.equals(hashtagName.toLowerCase(), that.hashtagName.toLowerCase());
if (type == TimelineType.CUSTOM_LOCAL_TIMELINE) return Objects.equals(domain.toLowerCase(), that.domain.toLowerCase());
return true; return true;
} }
@ -133,6 +144,8 @@ public class TimelineDefinition {
int result = type.ordinal(); int result = type.ordinal();
result = 31 * result + (listId != null ? listId.hashCode() : 0); result = 31 * result + (listId != null ? listId.hashCode() : 0);
result = 31 * result + (hashtagName.toLowerCase() != null ? hashtagName.toLowerCase().hashCode() : 0); result = 31 * result + (hashtagName.toLowerCase() != null ? hashtagName.toLowerCase().hashCode() : 0);
result = 31 * result + (domain.toLowerCase() != null ? domain.toLowerCase().hashCode() : 0);
return result; return result;
} }
@ -142,6 +155,7 @@ public class TimelineDefinition {
def.listId = listId; def.listId = listId;
def.listTitle = listTitle; def.listTitle = listTitle;
def.hashtagName = hashtagName; def.hashtagName = hashtagName;
def.domain = domain;
def.icon = icon == null ? null : Icon.values()[icon.ordinal()]; def.icon = icon == null ? null : Icon.values()[icon.ordinal()];
return def; return def;
} }
@ -152,11 +166,13 @@ public class TimelineDefinition {
args.putString("listID", listId); args.putString("listID", listId);
} else if (type == TimelineType.HASHTAG) { } else if (type == TimelineType.HASHTAG) {
args.putString("hashtag", hashtagName); args.putString("hashtag", hashtagName);
} else if (type == TimelineType.CUSTOM_LOCAL_TIMELINE) {
args.putString("domain", domain);
} }
return args; return args;
} }
public enum TimelineType { HOME, LOCAL, FEDERATED, POST_NOTIFICATIONS, LIST, HASHTAG } public enum TimelineType { HOME, LOCAL, FEDERATED, POST_NOTIFICATIONS, LIST, HASHTAG, CUSTOM_LOCAL_TIMELINE }
public enum Icon { public enum Icon {
HEART(R.drawable.ic_fluent_heart_24_regular, R.string.sk_icon_heart), HEART(R.drawable.ic_fluent_heart_24_regular, R.string.sk_icon_heart),
@ -219,7 +235,8 @@ public class TimelineDefinition {
FEDERATED(R.drawable.ic_fluent_earth_24_regular, R.string.sk_timeline_federated, true), FEDERATED(R.drawable.ic_fluent_earth_24_regular, R.string.sk_timeline_federated, true),
POST_NOTIFICATIONS(R.drawable.ic_fluent_chat_24_regular, R.string.sk_timeline_posts, true), POST_NOTIFICATIONS(R.drawable.ic_fluent_chat_24_regular, R.string.sk_timeline_posts, true),
LIST(R.drawable.ic_fluent_people_24_regular, R.string.sk_list, true), LIST(R.drawable.ic_fluent_people_24_regular, R.string.sk_list, true),
HASHTAG(R.drawable.ic_fluent_number_symbol_24_regular, R.string.sk_hashtag, true); HASHTAG(R.drawable.ic_fluent_number_symbol_24_regular, R.string.sk_hashtag, true),
CUSTOM_LOCAL_TIMELINE(R.drawable.ic_fluent_people_community_24_regular, R.string.sk_timeline_local, true);
public final int iconRes, nameRes; public final int iconRes, nameRes;
public final boolean hidden; public final boolean hidden;