Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
merge: rename ListTimeline to FollowList
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed Nov 27, 2023
1 parent 93624a5 commit 06c4671
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.joinmastodon.android.api.requests.lists;

import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;

public class CreateList extends MastodonAPIRequest<ListTimeline> {
public CreateList(String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
super(HttpMethod.POST, "/lists", ListTimeline.class);
public class CreateList extends MastodonAPIRequest<FollowList> {
public CreateList(String title, boolean exclusive, FollowList.RepliesPolicy repliesPolicy) {
super(HttpMethod.POST, "/lists", FollowList.class);
Request req = new Request();
req.title = title;
req.exclusive = exclusive;
Expand All @@ -16,6 +16,6 @@ public CreateList(String title, boolean exclusive, ListTimeline.RepliesPolicy re
public static class Request {
public String title;
public boolean exclusive;
public ListTimeline.RepliesPolicy repliesPolicy;
public FollowList.RepliesPolicy repliesPolicy;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.joinmastodon.android.api.requests.lists;

import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ListTimeline;

public class DeleteList extends MastodonAPIRequest<Object> {
public DeleteList(String id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.joinmastodon.android.api.requests.lists;

import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;

public class GetList extends MastodonAPIRequest<ListTimeline> {
public class GetList extends MastodonAPIRequest<FollowList> {
public GetList(String id) {
super(HttpMethod.GET, "/lists/" + id, ListTimeline.class);
super(HttpMethod.GET, "/lists/" + id, FollowList.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import com.google.gson.reflect.TypeToken;

import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;

import java.util.List;

public class GetLists extends MastodonAPIRequest<List<ListTimeline>>{
public GetLists() {
super(HttpMethod.GET, "/lists", new TypeToken<>(){});
}
public GetLists(String accountID) {
super(HttpMethod.GET, "/accounts/"+accountID+"/lists", new TypeToken<>(){});
}
}
public class GetLists extends MastodonAPIRequest<List<FollowList>>{
public GetLists(){
super(HttpMethod.GET, "/lists", new TypeToken<>(){});
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.joinmastodon.android.api.requests.lists;

import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;

public class UpdateList extends MastodonAPIRequest<ListTimeline> {
public UpdateList(String id, String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
super(HttpMethod.PUT, "/lists/" + id, ListTimeline.class);
public class UpdateList extends MastodonAPIRequest<FollowList> {
public UpdateList(String id, String title, boolean exclusive, FollowList.RepliesPolicy repliesPolicy) {
super(HttpMethod.PUT, "/lists/" + id, FollowList.class);
CreateList.Request req = new CreateList.Request();
req.title = title;
req.exclusive = exclusive;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.joinmastodon.android.events;

import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;

public class ListUpdatedCreatedEvent {
public final String id;
public final String title;
public final ListTimeline.RepliesPolicy repliesPolicy;
public final FollowList.RepliesPolicy repliesPolicy;
public final boolean exclusive;

public ListUpdatedCreatedEvent(String id, String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
public ListUpdatedCreatedEvent(String id, String title, boolean exclusive, FollowList.RepliesPolicy repliesPolicy) {
this.id = id;
this.title = title;
this.exclusive = exclusive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags;
import org.joinmastodon.android.api.session.AccountLocalPreferences;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.FollowList;
import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.ui.DividerItemDecoration;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
Expand All @@ -67,7 +67,7 @@ public class EditTimelinesFragment extends MastodonRecyclerFragment<TimelineDefi
private Menu optionsMenu;
private boolean updated;
private final Map<MenuItem, TimelineDefinition> timelineByMenuItem=new HashMap<>();
private final List<ListTimeline> listTimelines=new ArrayList<>();
private final List<FollowList> followLists =new ArrayList<>();
private final List<Hashtag> hashtags=new ArrayList<>();
private MenuItem addHashtagItem;

Expand All @@ -86,8 +86,8 @@ public void onCreate(Bundle savedInstanceState){

new GetLists().setCallback(new Callback<>(){
@Override
public void onSuccess(List<ListTimeline> result){
listTimelines.addAll(result);
public void onSuccess(List<FollowList> result){
followLists.addAll(result);
updateOptionsMenu();
}

Expand Down Expand Up @@ -189,7 +189,7 @@ private void updateOptionsMenu(){
makeBackItem(hashtagsMenu);

TimelineDefinition.getAllTimelines(accountID).stream().forEach(tl->addTimelineToOptions(tl, timelinesMenu));
listTimelines.stream().map(TimelineDefinition::ofList).forEach(tl->addTimelineToOptions(tl, listsMenu));
followLists.stream().map(TimelineDefinition::ofList).forEach(tl->addTimelineToOptions(tl, listsMenu));
addHashtagItem=addOptionsItem(hashtagsMenu, getContext().getString(R.string.sk_timelines_add), R.drawable.ic_fluent_add_24_regular);
hashtags.stream().map(TimelineDefinition::ofHashtag).forEach(tl->addTimelineToOptions(tl, hashtagsMenu));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
import org.joinmastodon.android.events.SelfUpdateStateChangedEvent;
import org.joinmastodon.android.fragments.settings.SettingsMainFragment;
import org.joinmastodon.android.model.Announcement;
import org.joinmastodon.android.model.FollowList;
import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.ui.SimpleViewHolder;
import org.joinmastodon.android.ui.utils.UiUtils;
Expand Down Expand Up @@ -95,7 +95,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
private ImageView collapsedChevron;
private TextView timelineTitle;
private PopupMenu switcherPopup;
private final Map<Integer, ListTimeline> listItems = new HashMap<>();
private final Map<Integer, FollowList> listItems = new HashMap<>();
private final Map<Integer, Hashtag> hashtagsItems = new HashMap<>();
private List<TimelineDefinition> timelinesList;
private int count;
Expand Down Expand Up @@ -266,7 +266,7 @@ public void onPageSelected(int position){

new GetLists().setCallback(new Callback<>() {
@Override
public void onSuccess(List<ListTimeline> lists) {
public void onSuccess(List<FollowList> lists) {
updateList(lists, listItems);
}

Expand Down Expand Up @@ -508,7 +508,7 @@ public boolean onOptionsItemSelected(MenuItem item){
Bundle args=new Bundle();
args.putString("account", accountID);
int id = item.getItemId();
ListTimeline list;
FollowList list;
Hashtag hashtag;

if (item.getItemId() == R.id.menu_back) {
Expand Down Expand Up @@ -697,7 +697,7 @@ public void onListDeletedEvent(ListDeletedEvent event) {
@Subscribe
public void onListUpdatedCreatedEvent(ListUpdatedCreatedEvent event) {
handleListEvent(listItems, l -> l.id.equals(event.id), true, () -> {
ListTimeline list = new ListTimeline();
FollowList list = new FollowList();
list.id = event.id;
list.title = event.title;
list.repliesPolicy = event.repliesPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.joinmastodon.android.events.ListDeletedEvent;
import org.joinmastodon.android.events.ListUpdatedCreatedEvent;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
Expand All @@ -39,7 +39,7 @@ public class ListTimelineFragment extends PinnableStatusListFragment {
private String listID;
private String listTitle;
@Nullable
private ListTimeline.RepliesPolicy repliesPolicy;
private FollowList.RepliesPolicy repliesPolicy;
private boolean exclusive;

@Override
Expand All @@ -54,19 +54,19 @@ public void onAttach(Activity activity){
listID = args.getString("listID");
listTitle = args.getString("listTitle");
exclusive = args.getBoolean("listIsExclusive");
repliesPolicy = ListTimeline.RepliesPolicy.values()[args.getInt("repliesPolicy", 0)];
repliesPolicy = FollowList.RepliesPolicy.values()[args.getInt("repliesPolicy", 0)];

setTitle(listTitle);
setHasOptionsMenu(true);

new GetList(listID).setCallback(new Callback<>() {
@Override
public void onSuccess(ListTimeline listTimeline) {
public void onSuccess(FollowList followList) {
if(getActivity()==null) return;
// TODO: save updated info
if (!listTimeline.title.equals(listTitle)) setTitle(listTimeline.title);
if (listTimeline.repliesPolicy != null && !listTimeline.repliesPolicy.equals(repliesPolicy)) {
repliesPolicy = listTimeline.repliesPolicy;
if (!followList.title.equals(listTitle)) setTitle(followList.title);
if (followList.repliesPolicy != null && !followList.repliesPolicy.equals(repliesPolicy)) {
repliesPolicy = followList.repliesPolicy;
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
setTitle(newTitle);
new UpdateList(listID, newTitle, editor.isExclusive(), editor.getRepliesPolicy()).setCallback(new Callback<>() {
@Override
public void onSuccess(ListTimeline list) {
public void onSuccess(FollowList list) {
if(getActivity()==null) return;
setTitle(list.title);
listTitle = list.title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.joinmastodon.android.api.requests.lists.RemoveAccountsFromList;
import org.joinmastodon.android.events.ListDeletedEvent;
import org.joinmastodon.android.events.ListUpdatedCreatedEvent;
import org.joinmastodon.android.model.ListTimeline;
import org.joinmastodon.android.model.FollowList;
import org.joinmastodon.android.ui.DividerItemDecoration;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.views.ListEditor;
Expand All @@ -42,7 +42,7 @@
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.views.UsableRecyclerView;

public class ListsFragment extends MastodonRecyclerFragment<ListTimeline> implements ScrollableToTop, ProvidesAssistContent.ProvidesWebUri {
public class ListsFragment extends MastodonRecyclerFragment<FollowList> implements ScrollableToTop, ProvidesAssistContent.ProvidesWebUri {
private String accountID;
private String profileAccountId;
private final HashMap<String, Boolean> userInListBefore = new HashMap<>();
Expand Down Expand Up @@ -99,7 +99,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
.setPositiveButton(R.string.sk_create, (d, which) ->
new CreateList(editor.getTitle(), editor.isExclusive(), editor.getRepliesPolicy()).setCallback(new Callback<>() {
@Override
public void onSuccess(ListTimeline list) {
public void onSuccess(FollowList list) {
data.add(0, list);
adapter.notifyItemRangeInserted(0, 1);
E.post(new ListUpdatedCreatedEvent(list.id, list.title, list.exclusive, list.repliesPolicy));
Expand Down Expand Up @@ -139,19 +139,19 @@ protected void doLoadData(int offset, int count){
currentRequest=(profileAccountId != null ? new GetLists(profileAccountId) : new GetLists())
.setCallback(new SimpleCallback<>(this) {
@Override
public void onSuccess(List<ListTimeline> lists) {
public void onSuccess(List<FollowList> lists) {
if(getActivity()==null) return;
for (ListTimeline l : lists) userInListBefore.put(l.id, true);
for (FollowList l : lists) userInListBefore.put(l.id, true);
userInList.putAll(userInListBefore);
if (profileAccountId == null || !lists.isEmpty()) onDataLoaded(lists, false);
if (profileAccountId == null) return;

currentRequest=new GetLists().setCallback(new SimpleCallback<>(ListsFragment.this) {
@Override
public void onSuccess(List<ListTimeline> allLists) {
public void onSuccess(List<FollowList> allLists) {
if(getActivity()==null) return;
List<ListTimeline> newLists = new ArrayList<>();
for (ListTimeline l : allLists) {
List<FollowList> newLists = new ArrayList<>();
for (FollowList l : allLists) {
if (lists.stream().noneMatch(e -> e.id.equals(l.id))) newLists.add(l);
if (!userInListBefore.containsKey(l.id)) {
userInListBefore.put(l.id, false);
Expand All @@ -169,7 +169,7 @@ public void onSuccess(List<ListTimeline> allLists) {
@Subscribe
public void onListDeletedEvent(ListDeletedEvent event) {
for (int i = 0; i < data.size(); i++) {
ListTimeline item = data.get(i);
FollowList item = data.get(i);
if (item.id.equals(event.id)) {
data.remove(i);
adapter.notifyItemRemoved(i);
Expand All @@ -181,7 +181,7 @@ public void onListDeletedEvent(ListDeletedEvent event) {
@Subscribe
public void onListUpdatedCreatedEvent(ListUpdatedCreatedEvent event) {
for (int i = 0; i < data.size(); i++) {
ListTimeline item = data.get(i);
FollowList item = data.get(i);
if (item.id.equals(event.id)) {
item.title = event.title;
item.repliesPolicy = event.repliesPolicy;
Expand Down Expand Up @@ -230,7 +230,7 @@ public int getItemCount() {
}
}

private class ListViewHolder extends BindableViewHolder<ListTimeline> implements UsableRecyclerView.Clickable{
private class ListViewHolder extends BindableViewHolder<FollowList> implements UsableRecyclerView.Clickable{
private final TextView title;
private final CheckBox listToggle;

Expand All @@ -241,7 +241,7 @@ public ListViewHolder(){
}

@Override
public void onBind(ListTimeline item) {
public void onBind(FollowList item) {
title.setText(item.title);
title.setCompoundDrawablesRelativeWithIntrinsicBounds(itemView.getContext().getDrawable(
item.exclusive ? R.drawable.ic_fluent_rss_24_regular : R.drawable.ic_fluent_people_24_regular
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.joinmastodon.android.model;

import com.google.gson.annotations.SerializedName;

import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.joinmastodon.android.api.ObjectValidationException;
import org.parceler.Parcel;

// Called like this to avoid conflict with java.util.List
@AllFieldsAreRequired
@Parcel
public class FollowList extends BaseModel{
public String id;
public String title;
public RepliesPolicy repliesPolicy=RepliesPolicy.LIST;
public boolean exclusive;

@Override
public String toString(){
return "FollowList{"+
"id='"+id+'\''+
", title='"+title+'\''+
", repliesPolicy="+repliesPolicy+
", exclusive="+exclusive+
'}';
}

@Override
public void postprocess() throws ObjectValidationException{
if(repliesPolicy==null)
repliesPolicy=RepliesPolicy.LIST;
super.postprocess();
}

public enum RepliesPolicy{
@SerializedName("followed")
FOLLOWED,
@SerializedName("list")
LIST,
@SerializedName("none")
NONE
}
}
Loading

0 comments on commit 06c4671

Please sign in to comment.