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,16 +95,33 @@ 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 -> {
|
||||||
if (mastodonLists != null && mastodonLists.size() > 0) {
|
ReorderVM reorderVM = new ViewModelProvider(MastodonListActivity.this).get(ReorderVM.class);
|
||||||
mastodonListList = new ArrayList<>(mastodonLists);
|
reorderVM.getPinned().observe(MastodonListActivity.this, pinned -> {
|
||||||
mastodonListAdapter = new MastodonListAdapter(mastodonListList);
|
if (mastodonLists != null && mastodonLists.size() > 0) {
|
||||||
mastodonListAdapter.actionOnList = this;
|
mastodonListList = new ArrayList<>(mastodonLists);
|
||||||
binding.notContent.setVisibility(View.GONE);
|
if (pinned != null) {
|
||||||
binding.recyclerView.setAdapter(mastodonListAdapter);
|
if (pinned.pinnedTimelines != null && pinned.pinnedTimelines.size() > 0) {
|
||||||
binding.recyclerView.setLayoutManager(new LinearLayoutManager(MastodonListActivity.this));
|
for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
|
||||||
} else {
|
if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) {
|
||||||
binding.notContent.setVisibility(View.VISIBLE);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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