Fix issue #310
This commit is contained in:
parent
514bc0794e
commit
dad0022e18
|
@ -15,6 +15,8 @@ package app.fedilab.android.activities;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
import static app.fedilab.android.helper.PinnedTimelineHelper.sortListPositionAsc;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -43,6 +45,7 @@ import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.client.entities.api.Account;
|
import app.fedilab.android.client.entities.api.Account;
|
||||||
import app.fedilab.android.client.entities.api.MastodonList;
|
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.client.entities.app.Timeline;
|
||||||
import app.fedilab.android.databinding.ActivityListBinding;
|
import app.fedilab.android.databinding.ActivityListBinding;
|
||||||
import app.fedilab.android.databinding.PopupAddListBinding;
|
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.drawer.MastodonListAdapter;
|
||||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
|
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
|
||||||
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
||||||
|
import app.fedilab.android.viewmodel.mastodon.ReorderVM;
|
||||||
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
|
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
@ -91,8 +95,24 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
|
||||||
timelinesVM = new ViewModelProvider(MastodonListActivity.this).get(TimelinesVM.class);
|
timelinesVM = new ViewModelProvider(MastodonListActivity.this).get(TimelinesVM.class);
|
||||||
timelinesVM.getLists(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
|
timelinesVM.getLists(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
|
||||||
.observe(MastodonListActivity.this, mastodonLists -> {
|
.observe(MastodonListActivity.this, mastodonLists -> {
|
||||||
|
ReorderVM reorderVM = new ViewModelProvider(MastodonListActivity.this).get(ReorderVM.class);
|
||||||
|
reorderVM.getPinned().observe(MastodonListActivity.this, pinned -> {
|
||||||
if (mastodonLists != null && mastodonLists.size() > 0) {
|
if (mastodonLists != null && mastodonLists.size() > 0) {
|
||||||
mastodonListList = new ArrayList<>(mastodonLists);
|
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 = new MastodonListAdapter(mastodonListList);
|
||||||
mastodonListAdapter.actionOnList = this;
|
mastodonListAdapter.actionOnList = this;
|
||||||
binding.notContent.setVisibility(View.GONE);
|
binding.notContent.setVisibility(View.GONE);
|
||||||
|
@ -102,6 +122,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
|
||||||
binding.notContent.setVisibility(View.VISIBLE);
|
binding.notContent.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,4 +26,6 @@ public class MastodonList implements Serializable {
|
||||||
public String title;
|
public String title;
|
||||||
@SerializedName("replies_policy")
|
@SerializedName("replies_policy")
|
||||||
public String replies_policy;
|
public String replies_policy;
|
||||||
|
@SerializedName("position")
|
||||||
|
public int position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,11 @@ public class PinnedTimelineHelper {
|
||||||
Collections.sort(pinnedTimelineList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));
|
Collections.sort(pinnedTimelineList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sortListPositionAsc(List<MastodonList> mastodonLists) {
|
||||||
|
//noinspection ComparatorCombinators
|
||||||
|
Collections.sort(mastodonLists, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));
|
||||||
|
}
|
||||||
|
|
||||||
public static void sortMenuItem(List<BottomMenu.MenuItem> menuItemList) {
|
public static void sortMenuItem(List<BottomMenu.MenuItem> menuItemList) {
|
||||||
//noinspection ComparatorCombinators
|
//noinspection ComparatorCombinators
|
||||||
Collections.sort(menuItemList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));
|
Collections.sort(menuItemList, (obj1, obj2) -> Integer.compare(obj1.position, obj2.position));
|
||||||
|
|
Loading…
Reference in New Issue