mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Restore elements between tabs
This commit is contained in:
parent
5472764a9f
commit
ac918aaa20
3 changed files with 241 additions and 121 deletions
|
@ -122,6 +122,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
private ActivityMainBinding binding;
|
private ActivityMainBinding binding;
|
||||||
private Pinned pinned;
|
private Pinned pinned;
|
||||||
|
|
||||||
|
|
||||||
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
|
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package app.fedilab.android.client.entities.app;
|
||||||
|
/* Copyright 2022 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.entities.Timeline;
|
||||||
|
import app.fedilab.android.client.mastodon.entities.Status;
|
||||||
|
|
||||||
|
public class SavedValues {
|
||||||
|
|
||||||
|
public static HashMap<String, SavedValues> storedStates = new HashMap<>();
|
||||||
|
public int position;
|
||||||
|
public List<Status> statusList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves saved values
|
||||||
|
*
|
||||||
|
* @param timeLineType - Timeline.TimeLineEnum
|
||||||
|
* @param ident - the name for pinned timeline
|
||||||
|
* @return SavedValues
|
||||||
|
*/
|
||||||
|
public static SavedValues getSavedValue(Timeline.TimeLineEnum timeLineType, String ident) {
|
||||||
|
if (!canBestored(timeLineType)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String key = timeLineType.getValue();
|
||||||
|
if (ident != null) {
|
||||||
|
key += "|" + ident;
|
||||||
|
}
|
||||||
|
return storedStates.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current timeline can be stored
|
||||||
|
*
|
||||||
|
* @param timeLineType - Timeline.TimeLineEnum
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private static boolean canBestored(Timeline.TimeLineEnum timeLineType) {
|
||||||
|
return timeLineType == Timeline.TimeLineEnum.HOME || timeLineType == Timeline.TimeLineEnum.LOCAL || timeLineType == Timeline.TimeLineEnum.PUBLIC || timeLineType == Timeline.TimeLineEnum.REMOTE || timeLineType == Timeline.TimeLineEnum.LIST || timeLineType == Timeline.TimeLineEnum.TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position - current position in timeline
|
||||||
|
* @param timeLineType - Timeline.TimeLineEnum
|
||||||
|
* @param statusList - List<Status> to save
|
||||||
|
* @param ident - the name for pinned timeline
|
||||||
|
*/
|
||||||
|
public static void storeTimeline(int position, Timeline.TimeLineEnum timeLineType, List<Status> statusList, String ident) {
|
||||||
|
if (!canBestored(timeLineType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String key = timeLineType.getValue();
|
||||||
|
if (ident != null) {
|
||||||
|
key += "|" + ident;
|
||||||
|
}
|
||||||
|
SavedValues savedValues = new SavedValues();
|
||||||
|
savedValues.position = position;
|
||||||
|
savedValues.statusList = statusList;
|
||||||
|
storedStates.put(key, savedValues);
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ import java.util.List;
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.client.entities.Timeline;
|
import app.fedilab.android.client.entities.Timeline;
|
||||||
|
import app.fedilab.android.client.entities.app.SavedValues;
|
||||||
import app.fedilab.android.client.entities.app.TagTimeline;
|
import app.fedilab.android.client.entities.app.TagTimeline;
|
||||||
import app.fedilab.android.client.mastodon.entities.Account;
|
import app.fedilab.android.client.mastodon.entities.Account;
|
||||||
import app.fedilab.android.client.mastodon.entities.Marker;
|
import app.fedilab.android.client.mastodon.entities.Marker;
|
||||||
|
@ -78,6 +79,8 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
private Account accountTimeline;
|
private Account accountTimeline;
|
||||||
private boolean exclude_replies, exclude_reblogs, show_pinned, media_only, minified;
|
private boolean exclude_replies, exclude_reblogs, show_pinned, media_only, minified;
|
||||||
private String viewModelKey, remoteInstance;
|
private String viewModelKey, remoteInstance;
|
||||||
|
private String ident;
|
||||||
|
|
||||||
|
|
||||||
//Handle actions that can be done in other fragments
|
//Handle actions that can be done in other fragments
|
||||||
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
||||||
|
@ -161,6 +164,15 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
minified = getArguments().getBoolean(Helper.ARG_MINIFIED, false);
|
minified = getArguments().getBoolean(Helper.ARG_MINIFIED, false);
|
||||||
statusReport = (Status) getArguments().getSerializable(Helper.ARG_STATUS_REPORT);
|
statusReport = (Status) getArguments().getSerializable(Helper.ARG_STATUS_REPORT);
|
||||||
}
|
}
|
||||||
|
if (tagTimeline != null) {
|
||||||
|
ident = tagTimeline.name;
|
||||||
|
} else if (list_id != null) {
|
||||||
|
ident = list_id;
|
||||||
|
} else if (remoteInstance != null) {
|
||||||
|
ident = remoteInstance;
|
||||||
|
} else {
|
||||||
|
ident = null;
|
||||||
|
}
|
||||||
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
|
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
|
||||||
binding = FragmentPaginationBinding.inflate(inflater, container, false);
|
binding = FragmentPaginationBinding.inflate(inflater, container, false);
|
||||||
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
|
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
|
||||||
|
@ -340,6 +352,11 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|
||||||
|
if (mLayoutManager != null) {
|
||||||
|
int position = mLayoutManager.findFirstVisibleItemPosition();
|
||||||
|
new Thread(() -> SavedValues.storeTimeline(position, timelineType, statuses, ident)).start();
|
||||||
|
}
|
||||||
//Update last read id for home timeline
|
//Update last read id for home timeline
|
||||||
storeMarker();
|
storeMarker();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
|
@ -384,130 +401,156 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
|
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
|
||||||
*/
|
*/
|
||||||
private void route(DIRECTION direction) {
|
private void route(DIRECTION direction) {
|
||||||
// --- HOME TIMELINE ---
|
|
||||||
if (timelineType == Timeline.TimeLineEnum.HOME) {
|
new Thread(() -> {
|
||||||
//for more visibility it's done through loadHomeStrategy method
|
SavedValues savedValues = SavedValues.getSavedValue(timelineType, ident);
|
||||||
loadHomeStrategy(direction);
|
if (savedValues != null && savedValues.statusList != null && savedValues.statusList.size() > 0) {
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
|
Statuses statuses = new Statuses();
|
||||||
if (direction == null) {
|
statuses.statuses = savedValues.statusList;
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
statuses.pagination = new Pagination();
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
statuses.pagination.max_id = savedValues.statusList.get(savedValues.statusList.size() - 1).id;
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
statuses.pagination.min_id = savedValues.statusList.get(0).id;
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
try {
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
Thread.sleep(200);
|
||||||
} else if (direction == DIRECTION.TOP) {
|
} catch (InterruptedException e) {
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
e.printStackTrace();
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
|
|
||||||
if (direction == null) {
|
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else if (direction == DIRECTION.TOP) {
|
|
||||||
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
|
|
||||||
if (direction == null) {
|
|
||||||
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
timelinesVM.getPublic(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else if (direction == DIRECTION.TOP) {
|
|
||||||
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
|
|
||||||
if (direction == null) {
|
|
||||||
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else if (direction == DIRECTION.TOP) {
|
|
||||||
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.TAG) { //TAG TIMELINE
|
|
||||||
if (tagTimeline == null) {
|
|
||||||
tagTimeline = new TagTimeline();
|
|
||||||
tagTimeline.name = search;
|
|
||||||
}
|
|
||||||
if (direction == null) {
|
|
||||||
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else if (direction == DIRECTION.TOP) {
|
|
||||||
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
|
|
||||||
if (direction == null) {
|
|
||||||
if (show_pinned) {
|
|
||||||
//Fetch pinned statuses to display them at the top
|
|
||||||
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), otherStatuses -> {
|
|
||||||
if (otherStatuses != null && otherStatuses.statuses != null) {
|
|
||||||
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses);
|
|
||||||
initializeStatusesCommonView(otherStatuses);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
}
|
}
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
Runnable myRunnable = () -> initializeStatusesCommonView(statuses);
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
mainHandler.post(myRunnable);
|
||||||
} else {
|
} else {
|
||||||
flagLoading = false;
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> {
|
||||||
|
// --- HOME TIMELINE ---
|
||||||
|
if (timelineType == Timeline.TimeLineEnum.HOME) {
|
||||||
|
//for more visibility it's done through loadHomeStrategy method
|
||||||
|
loadHomeStrategy(direction);
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
|
||||||
|
if (direction == null) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else if (direction == DIRECTION.TOP) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
|
||||||
|
if (direction == null) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else if (direction == DIRECTION.TOP) {
|
||||||
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
|
||||||
|
if (direction == null) {
|
||||||
|
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
timelinesVM.getPublic(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else if (direction == DIRECTION.TOP) {
|
||||||
|
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
|
||||||
|
if (direction == null) {
|
||||||
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else if (direction == DIRECTION.TOP) {
|
||||||
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.TAG) { //TAG TIMELINE
|
||||||
|
if (tagTimeline == null) {
|
||||||
|
tagTimeline = new TagTimeline();
|
||||||
|
tagTimeline.name = search;
|
||||||
|
}
|
||||||
|
if (direction == null) {
|
||||||
|
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else if (direction == DIRECTION.TOP) {
|
||||||
|
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
|
||||||
|
if (direction == null) {
|
||||||
|
if (show_pinned) {
|
||||||
|
//Fetch pinned statuses to display them at the top
|
||||||
|
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), otherStatuses -> {
|
||||||
|
if (otherStatuses != null && otherStatuses.statuses != null) {
|
||||||
|
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses);
|
||||||
|
initializeStatusesCommonView(otherStatuses);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
}
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else {
|
||||||
|
flagLoading = false;
|
||||||
|
}
|
||||||
|
} else if (search != null) {
|
||||||
|
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
||||||
|
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.STATUSES_PER_CALL)
|
||||||
|
.observe(getViewLifecycleOwner(), results -> {
|
||||||
|
Statuses statuses = new Statuses();
|
||||||
|
statuses.statuses = results.statuses;
|
||||||
|
statuses.pagination = new Pagination();
|
||||||
|
initializeStatusesCommonView(statuses);
|
||||||
|
});
|
||||||
|
} else if (searchCache != null) {
|
||||||
|
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
||||||
|
searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim())
|
||||||
|
.observe(getViewLifecycleOwner(), results -> {
|
||||||
|
Statuses statuses = new Statuses();
|
||||||
|
statuses.statuses = results.statuses;
|
||||||
|
statuses.pagination = new Pagination();
|
||||||
|
initializeStatusesCommonView(statuses);
|
||||||
|
});
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) {
|
||||||
|
if (direction == null) {
|
||||||
|
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null)
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id)
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else {
|
||||||
|
flagLoading = false;
|
||||||
|
}
|
||||||
|
} else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) {
|
||||||
|
if (direction == null) {
|
||||||
|
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null, null)
|
||||||
|
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||||
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
|
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), max_id, null, null)
|
||||||
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
||||||
|
} else {
|
||||||
|
flagLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
}
|
}
|
||||||
} else if (search != null) {
|
|
||||||
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
}).start();
|
||||||
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.STATUSES_PER_CALL)
|
|
||||||
.observe(getViewLifecycleOwner(), results -> {
|
|
||||||
Statuses statuses = new Statuses();
|
|
||||||
statuses.statuses = results.statuses;
|
|
||||||
statuses.pagination = new Pagination();
|
|
||||||
initializeStatusesCommonView(statuses);
|
|
||||||
});
|
|
||||||
} else if (searchCache != null) {
|
|
||||||
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
|
||||||
searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim())
|
|
||||||
.observe(getViewLifecycleOwner(), results -> {
|
|
||||||
Statuses statuses = new Statuses();
|
|
||||||
statuses.statuses = results.statuses;
|
|
||||||
statuses.pagination = new Pagination();
|
|
||||||
initializeStatusesCommonView(statuses);
|
|
||||||
});
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) {
|
|
||||||
if (direction == null) {
|
|
||||||
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null)
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id)
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else {
|
|
||||||
flagLoading = false;
|
|
||||||
}
|
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) {
|
|
||||||
if (direction == null) {
|
|
||||||
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null, null)
|
|
||||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
|
||||||
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), max_id, null, null)
|
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
|
|
||||||
} else {
|
|
||||||
flagLoading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue