diff --git a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java index 74d125fdd..3d8a431cf 100644 --- a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.activities; * see . */ +import static app.fedilab.android.helper.PinnedTimelineHelper.sortListPositionAsc; + import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; @@ -43,6 +45,7 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.MastodonList; +import app.fedilab.android.client.entities.app.PinnedTimeline; import app.fedilab.android.client.entities.app.Timeline; import app.fedilab.android.databinding.ActivityListBinding; import app.fedilab.android.databinding.PopupAddListBinding; @@ -53,6 +56,7 @@ import app.fedilab.android.ui.drawer.AccountListAdapter; import app.fedilab.android.ui.drawer.MastodonListAdapter; import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; import app.fedilab.android.viewmodel.mastodon.AccountsVM; +import app.fedilab.android.viewmodel.mastodon.ReorderVM; import app.fedilab.android.viewmodel.mastodon.TimelinesVM; import es.dmoral.toasty.Toasty; @@ -91,16 +95,33 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd timelinesVM = new ViewModelProvider(MastodonListActivity.this).get(TimelinesVM.class); timelinesVM.getLists(BaseMainActivity.currentInstance, BaseMainActivity.currentToken) .observe(MastodonListActivity.this, mastodonLists -> { - if (mastodonLists != null && mastodonLists.size() > 0) { - mastodonListList = new ArrayList<>(mastodonLists); - mastodonListAdapter = new MastodonListAdapter(mastodonListList); - mastodonListAdapter.actionOnList = this; - binding.notContent.setVisibility(View.GONE); - binding.recyclerView.setAdapter(mastodonListAdapter); - binding.recyclerView.setLayoutManager(new LinearLayoutManager(MastodonListActivity.this)); - } else { - binding.notContent.setVisibility(View.VISIBLE); - } + ReorderVM reorderVM = new ViewModelProvider(MastodonListActivity.this).get(ReorderVM.class); + reorderVM.getPinned().observe(MastodonListActivity.this, pinned -> { + if (mastodonLists != null && mastodonLists.size() > 0) { + mastodonListList = new ArrayList<>(mastodonLists); + if (pinned != null) { + if (pinned.pinnedTimelines != null && pinned.pinnedTimelines.size() > 0) { + for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { + if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) { + for (MastodonList mastodonList : mastodonLists) { + if (mastodonList.id.equalsIgnoreCase(pinnedTimeline.mastodonList.id)) { + mastodonList.position = pinnedTimeline.position; + } + } + } + } + } + } + sortListPositionAsc(mastodonListList); + mastodonListAdapter = new MastodonListAdapter(mastodonListList); + mastodonListAdapter.actionOnList = this; + binding.notContent.setVisibility(View.GONE); + binding.recyclerView.setAdapter(mastodonListAdapter); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(MastodonListActivity.this)); + } else { + binding.notContent.setVisibility(View.VISIBLE); + } + }); }); } diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/MastodonList.java b/app/src/main/java/app/fedilab/android/client/entities/api/MastodonList.java index 32cb8bd4c..1491b35f2 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/MastodonList.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/MastodonList.java @@ -26,4 +26,6 @@ public class MastodonList implements Serializable { public String title; @SerializedName("replies_policy") public String replies_policy; + @SerializedName("position") + public int position; } diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 7d482c228..5cfce39da 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -64,6 +64,11 @@ public class PinnedTimelineHelper { Collections.sort(pinnedTimelineList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position)); } + public static void sortListPositionAsc(List mastodonLists) { + //noinspection ComparatorCombinators + Collections.sort(mastodonLists, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position)); + } + public static void sortMenuItem(List menuItemList) { //noinspection ComparatorCombinators Collections.sort(menuItemList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));