remove quickload

pull/434/head
Thomas 2 years ago
parent 3587408123
commit 29b3107889

@ -37,7 +37,6 @@ import androidx.preference.PreferenceManager;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.QuickLoad;
import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.databinding.ActivityConversationBinding;
import app.fedilab.android.exception.DBException;
@ -99,7 +98,6 @@ public class ContextActivity extends BaseActivity {
new Thread(() -> {
try {
new StatusCache(getApplication()).updateIfExists(statusCache);
new QuickLoad(getApplication().getApplicationContext()).updateStatus(currentAccount, status);
Handler mainHandler = new Handler(Looper.getMainLooper());
//Update UI
Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null);

@ -1,647 +0,0 @@
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 android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.client.entities.api.Notification;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
public class QuickLoad {
private final SQLiteDatabase db;
@SerializedName("id")
public long id;
@SerializedName("user_id")
public String user_id;
@SerializedName("instance")
public String instance;
@SerializedName("slug")
public String slug;
@SerializedName("position")
public int position;
@SerializedName("statuses")
public List<Status> statuses;
@SerializedName("notifications")
public List<Notification> notifications;
private Context _mContext;
private type typeOfFetch;
public QuickLoad() {
db = null;
}
public QuickLoad(Context context) {
//Creation of the DB with tables
this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
_mContext = context;
this.typeOfFetch = type.STATUSES;
}
public QuickLoad(Context context, type type) {
//Creation of the DB with tables
this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
_mContext = context;
this.typeOfFetch = type;
}
/**
* Check if the current timeline can be stored
*
* @param timeLineType - Timeline.TimeLineEnum
* @return boolean
*/
public static boolean cannotBeStored(Timeline.TimeLineEnum timeLineType) {
return timeLineType != Timeline.TimeLineEnum.LOCAL && timeLineType != Timeline.TimeLineEnum.PUBLIC && timeLineType != Timeline.TimeLineEnum.REMOTE && timeLineType != Timeline.TimeLineEnum.LIST && timeLineType != Timeline.TimeLineEnum.TAG;
}
/**
* Update a QuickLoad in db
*
* @param quickLoad {@link QuickLoad}
* @throws DBException exception with database
*/
private void updateStatus(QuickLoad quickLoad) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
ContentValues values = new ContentValues();
values.put(Sqlite.COL_POSITION, quickLoad.position);
if (quickLoad.statuses != null) {
values.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(quickLoad.statuses));
} else if (quickLoad.notifications != null) {
values.put(Sqlite.COL_STATUSES, Notification.notificationsToStringStorage(quickLoad.notifications));
}
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{quickLoad.user_id, quickLoad.instance, quickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Insert or update a QuickLoad
*
* @param quickLoad {@link QuickLoad}
* @throws DBException exception with database
*/
private void insertOrUpdate(QuickLoad quickLoad) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
boolean exists = quickLoadExist(quickLoad);
if (exists) {
updateStatus(quickLoad);
} else {
insertQuickLoad(quickLoad);
}
}
/**
* Check if a QuickLoad exists in db
*
* @param quickLoad QuickLoad {@link QuickLoad}
* @return boolean - QuickLoad exists
* @throws DBException Exception
*/
public boolean quickLoadExist(QuickLoad quickLoad) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_QUICK_LOAD
+ " where " + Sqlite.COL_SLUG + " = '" + quickLoad.slug + "'"
+ " AND " + Sqlite.COL_INSTANCE + " = '" + quickLoad.instance + "'"
+ " AND " + Sqlite.COL_USER_ID + "= '" + quickLoad.user_id + "'", null);
mCount.moveToFirst();
int count = mCount.getInt(0);
mCount.close();
return (count > 0);
}
/**
* Count statuses in cache for an account
*
* @param account Account {@link Account}
* @return int - Number of statuses
* @throws DBException Exception
*/
public int count(BaseAccount account) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
int count = 0;
Cursor c = db.query(Sqlite.TABLE_QUICK_LOAD, null, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{account.user_id, account.instance}, null, null, null, null);
List<QuickLoad> quickLoadList = cursorToQuickLoadList(c);
if (quickLoadList != null) {
for (QuickLoad quickLoad : quickLoadList) {
count += quickLoad.statuses.size();
}
}
return count;
}
/**
* @param position - current position in timeline
* @param timeLineType - Timeline.TimeLineEnum
* @param statusList - List<Status> to save
* @param ident - the name for pinned timeline
*/
public void storeTimeline(int position, String user_id, String instance, Timeline.TimeLineEnum timeLineType, List<Status> statusList, String ident) {
if (cannotBeStored(timeLineType)) {
return;
}
String key = timeLineType.getValue();
if (ident != null) {
key += "|" + ident;
}
QuickLoad quickLoad = new QuickLoad();
quickLoad.position = position;
quickLoad.statuses = statusList;
quickLoad.slug = key;
quickLoad.instance = instance;
quickLoad.user_id = user_id;
purge(quickLoad);
try {
insertOrUpdate(quickLoad);
} catch (DBException e) {
e.printStackTrace();
}
}
/**
* @param position - current position in timeline
* @param notificationTypeEnum - Timeline.NotificationTypeEnum
* @param notificationList - List<Notification> to save
*/
public void storeNotifications(int position, String user_id, String instance, FragmentMastodonNotification.NotificationTypeEnum notificationTypeEnum, List<Notification> notificationList) {
String key = notificationTypeEnum.getValue();
QuickLoad quickLoad = new QuickLoad();
quickLoad.position = position;
quickLoad.notifications = notificationList;
quickLoad.slug = key;
quickLoad.instance = instance;
quickLoad.user_id = user_id;
purge(quickLoad);
try {
insertOrUpdate(quickLoad);
} catch (DBException e) {
e.printStackTrace();
}
}
/**
* Insert a QuickLoad in db
*
* @param quickLoad {@link QuickLoad}
* @throws DBException exception with database
*/
private void insertQuickLoad(QuickLoad quickLoad) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
ContentValues values = new ContentValues();
values.put(Sqlite.COL_USER_ID, quickLoad.user_id);
values.put(Sqlite.COL_INSTANCE, quickLoad.instance);
values.put(Sqlite.COL_SLUG, quickLoad.slug);
values.put(Sqlite.COL_POSITION, quickLoad.position);
if (quickLoad.statuses != null) {
values.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(quickLoad.statuses));
} else if (quickLoad.notifications != null) {
values.put(Sqlite.COL_STATUSES, Notification.notificationsToStringStorage(quickLoad.notifications));
}
//Inserts token
try {
db.insertOrThrow(Sqlite.TABLE_QUICK_LOAD, null, values);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* delete all cache for all accounts
*
* @return long - db id
* @throws DBException exception with database
*/
@SuppressWarnings("UnusedReturnValue")
public long deleteForAllAccount() throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_QUICK_LOAD, null, null);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* delete all cache for an account
*
* @param account - Account
* @return long - db id
* @throws DBException exception with database
*/
@SuppressWarnings("UnusedReturnValue")
public long deleteForAccount(BaseAccount account) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_QUICK_LOAD,
Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{account.user_id, account.instance});
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* Update a status in quickload
*
* @param account {@link BaseAccount}
* @param newStatus - Status
* @throws DBException exception with database
*/
public void updateStatus(BaseAccount account, Status newStatus) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
QuickLoad homeQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.HOME, null);
QuickLoad localQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.LOCAL, null);
QuickLoad publicQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.PUBLIC, null);
if (homeQuickLoad != null && homeQuickLoad.statuses != null && newStatus != null) {
for (int i = 0; i < homeQuickLoad.statuses.size(); i++) {
if (homeQuickLoad.statuses.get(i).id.equals(newStatus.id)) {
homeQuickLoad.statuses.set(i, newStatus);
break;
}
}
ContentValues valuesHome = new ContentValues();
valuesHome.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesHome, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
if (localQuickLoad != null && localQuickLoad.statuses != null && newStatus != null) {
for (int i = 0; i < localQuickLoad.statuses.size(); i++) {
if (localQuickLoad.statuses.get(i).id.equals(newStatus.id)) {
localQuickLoad.statuses.set(i, newStatus);
break;
}
}
ContentValues valuesLocal = new ContentValues();
valuesLocal.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(localQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesLocal, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{localQuickLoad.user_id, localQuickLoad.instance, localQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
if (publicQuickLoad != null && publicQuickLoad.statuses != null && newStatus != null) {
for (int i = 0; i < publicQuickLoad.statuses.size(); i++) {
if (publicQuickLoad.statuses.get(i).id.equals(newStatus.id)) {
publicQuickLoad.statuses.set(i, newStatus);
break;
}
}
ContentValues valuesPublic = new ContentValues();
valuesPublic.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(publicQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesPublic, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{publicQuickLoad.user_id, publicQuickLoad.instance, publicQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Delete a status in quickload
*
* @param account {@link Account}
* @param id - String id of the status
* @throws DBException exception with database
*/
public void deleteStatus(BaseAccount account, String id) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
QuickLoad homeQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.HOME, null);
QuickLoad localQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.LOCAL, null);
QuickLoad publicQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.PUBLIC, null);
if (homeQuickLoad != null && homeQuickLoad.statuses != null) {
for (Status status : homeQuickLoad.statuses) {
if (status.id.equals(id)) {
homeQuickLoad.statuses.remove(status);
break;
}
}
ContentValues valuesHome = new ContentValues();
valuesHome.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesHome, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
if (localQuickLoad != null && localQuickLoad.statuses != null) {
for (Status status : localQuickLoad.statuses) {
if (status.id.equals(id)) {
localQuickLoad.statuses.remove(status);
break;
}
}
ContentValues valuesLocal = new ContentValues();
valuesLocal.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(localQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesLocal, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{localQuickLoad.user_id, localQuickLoad.instance, localQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
if (publicQuickLoad != null && publicQuickLoad.statuses != null) {
for (Status status : publicQuickLoad.statuses) {
if (status.id.equals(id)) {
publicQuickLoad.statuses.remove(status);
break;
}
}
ContentValues valuesPublic = new ContentValues();
valuesPublic.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(publicQuickLoad.statuses));
//Inserts token
try {
db.update(Sqlite.TABLE_QUICK_LOAD,
valuesPublic, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{publicQuickLoad.user_id, publicQuickLoad.instance, publicQuickLoad.slug});
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Retrieves saved values
*
* @param timeLineType - Timeline.TimeLineEnum
* @param ident - the name for pinned timeline
* @return SavedValues
*/
public QuickLoad getSavedValue(String user_id, String instance, Timeline.TimeLineEnum timeLineType, String ident) {
if (cannotBeStored(timeLineType)) {
return null;
}
String key = timeLineType.getValue();
if (ident != null) {
key += "|" + ident;
}
try {
return get(user_id, instance, key);
} catch (DBException e) {
e.printStackTrace();
}
return null;
}
/**
* Retrieves saved values
*
* @param notificationTypeEnum - FragmentMastodonNotification.NotificationTypeEnum
* @return SavedValues
*/
public QuickLoad getSavedValue(String user_id, String instance, FragmentMastodonNotification.NotificationTypeEnum notificationTypeEnum) {
String key = notificationTypeEnum.getValue();
try {
return get(user_id, instance, key);
} catch (DBException e) {
e.printStackTrace();
}
return null;
}
/**
* Retrieves saved values
*
* @param notificationTypeEnum - FragmentMastodonNotification.NotificationTypeEnum
* @return SavedValues
*/
public QuickLoad getSavedValue(BaseAccount account, FragmentMastodonNotification.NotificationTypeEnum notificationTypeEnum) {
String key = notificationTypeEnum.getValue();
try {
return get(key, account);
} catch (DBException e) {
e.printStackTrace();
}
return null;
}
/**
* Retrieves saved values
*
* @param timeLineType - Timeline.TimeLineEnum
* @param ident - the name for pinned timeline
* @return SavedValues
*/
public QuickLoad getSavedValue(BaseAccount account, Timeline.TimeLineEnum timeLineType, String ident) {
if (cannotBeStored(timeLineType)) {
return null;
}
String key = timeLineType.getValue();
if (ident != null) {
key += "|" + ident;
}
try {
return get(key, account);
} catch (DBException e) {
e.printStackTrace();
}
return null;
}
/**
* Purge the list to avoid long list of Statuses in db
*
* @param quickLoad - QuickLoad to purge
*/
private void purge(QuickLoad quickLoad) {
List<Status> statuses = quickLoad.statuses;
int position = quickLoad.position;
int limit = MastodonHelper.statusesPerCall(_mContext) + 10;
int startAt = Math.max(position - limit, 0);
int endAt = Math.min(position + limit, statuses.size());
quickLoad.position = position - startAt;
quickLoad.statuses = statuses.subList(startAt, endAt);
}
/**
* Restore statusDraft list from db
*
* @param c Cursor
* @return List<Emoji>
*/
private List<QuickLoad> cursorToQuickLoadList(Cursor c) {
//No element found
if (c.getCount() == 0) {
c.close();
return null;
}
List<QuickLoad> quickLoads = new ArrayList<>();
while (c.moveToNext()) {
QuickLoad quickLoad = convertCursorToQuickLoad(c);
quickLoads.add(quickLoad);
}
//Close the cursor
c.close();
return quickLoads;
}
/**
* Convert a cursor to QuickLoad
*
* @param c Cursor
* @return QuickLoad
*/
private QuickLoad convertCursorToQuickLoad(Cursor c) {
QuickLoad quickLoad = new QuickLoad();
quickLoad.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID));
quickLoad.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE));
quickLoad.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID));
quickLoad.slug = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_SLUG));
if (typeOfFetch == type.STATUSES) {
quickLoad.statuses = StatusDraft.restoreStatusListFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
} else if (typeOfFetch == type.NOTIFICATIONS) {
quickLoad.notifications = Notification.restoreNotificationsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
}
quickLoad.position = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_POSITION));
//TimelineHelper.filterStatus(_mContext, quickLoad.statuses, TimelineHelper.FilterTimeLineType.PUBLIC);
return quickLoad;
}
/**
* Convert a cursor to QuickLoad
*
* @param c Cursor
* @return QuickLoad
*/
private QuickLoad cursorToQuickLoad(Cursor c) {
//No element found
if (c.getCount() == 0) {
c.close();
return null;
}
//Take the first element
c.moveToFirst();
QuickLoad quickLoad = convertCursorToQuickLoad(c);
//Close the cursor
c.close();
return quickLoad;
}
/**
* Get paginated statuses from db
*
* @return Statuses
* @throws DBException - throws a db exception
*/
private QuickLoad get(String user_id, String instance, String slug) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
Cursor c = db.query(Sqlite.TABLE_QUICK_LOAD, null, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{user_id, instance, slug}, null, null, null, "1");
return cursorToQuickLoad(c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Get paginated statuses from db
*
* @return Statuses
* @throws DBException - throws a db exception
*/
private QuickLoad get(String slug, BaseAccount account) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
Cursor c = db.query(Sqlite.TABLE_QUICK_LOAD, null, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
new String[]{account.user_id, account.instance, slug}, null, null, null, "1");
return cursorToQuickLoad(c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
enum type {
STATUSES,
NOTIFICATIONS
}
}

@ -25,7 +25,6 @@ import java.util.Objects;
import app.fedilab.android.client.entities.app.BaseAccount;
import app.fedilab.android.client.entities.app.CacheAccount;
import app.fedilab.android.client.entities.app.QuickLoad;
import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.client.entities.app.StatusDraft;
import app.fedilab.android.exception.DBException;
@ -49,11 +48,6 @@ public class CacheHelper {
} catch (DBException e) {
e.printStackTrace();
}
try {
count.add(new QuickLoad(context).count(account));
} catch (DBException e) {
e.printStackTrace();
}
try {
count.add(new StatusDraft(context).count(account));
} catch (DBException e) {
@ -126,13 +120,6 @@ public class CacheHelper {
e.printStackTrace();
}
}
if (cacheAccount.clear_other) {
try {
new QuickLoad(context).deleteForAccount(cacheAccount.account);
} catch (DBException e) {
e.printStackTrace();
}
}
if (cacheAccount.clear_drafts) {
try {
new StatusDraft(context).removeAllDraftFor(cacheAccount.account);

@ -20,8 +20,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -44,9 +42,7 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Notification;
import app.fedilab.android.client.entities.api.Notifications;
import app.fedilab.android.client.entities.api.Pagination;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.QuickLoad;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
@ -279,46 +275,28 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
if (binding == null || !isAdded() || getActivity() == null) {
return;
}
new Thread(() -> {
QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(BaseMainActivity.currentUserID, BaseMainActivity.currentInstance, notificationType);
if (direction != FragmentMastodonTimeline.DIRECTION.REFRESH && !fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.notifications != null && quickLoad.notifications.size() > 0) {
Notifications notifications = new Notifications();
notifications.notifications = quickLoad.notifications;
notifications.pagination = new Pagination();
notifications.pagination.max_id = quickLoad.notifications.get(quickLoad.statuses.size() - 1).id;
notifications.pagination.min_id = quickLoad.notifications.get(0).id;
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> initializeNotificationView(notifications);
mainHandler.post(myRunnable);
} else {
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (!isAdded()) {
return;
}
if (direction == null) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), this::initializeNotificationView);
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsBottom -> dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == FragmentMastodonTimeline.DIRECTION.TOP) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsTop -> dealWithPagination(notificationsTop, FragmentMastodonTimeline.DIRECTION.TOP, fetchingMissing));
} else if (direction == FragmentMastodonTimeline.DIRECTION.REFRESH) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsRefresh -> {
if (notificationAdapter != null) {
dealWithPagination(notificationsRefresh, FragmentMastodonTimeline.DIRECTION.REFRESH, true);
} else {
initializeNotificationView(notificationsRefresh);
}
});
}
};
mainHandler.post(myRunnable);
}
}).start();
if (!isAdded()) {
return;
}
if (direction == null) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), this::initializeNotificationView);
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsBottom -> dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == FragmentMastodonTimeline.DIRECTION.TOP) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsTop -> dealWithPagination(notificationsTop, FragmentMastodonTimeline.DIRECTION.TOP, fetchingMissing));
} else if (direction == FragmentMastodonTimeline.DIRECTION.REFRESH) {
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(getViewLifecycleOwner(), notificationsRefresh -> {
if (notificationAdapter != null) {
dealWithPagination(notificationsRefresh, FragmentMastodonTimeline.DIRECTION.REFRESH, true);
} else {
initializeNotificationView(notificationsRefresh);
}
});
}
}
private List<Notification> aggregateNotifications(List<Notification> notifications) {
@ -469,30 +447,12 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
@Override
public void onDestroyView() {
if (mLayoutManager != null) {
int position = mLayoutManager.findFirstVisibleItemPosition();
new Thread(() -> {
try {
new QuickLoad(requireActivity()).storeNotifications(position, user_id, instance, notificationType, notificationList);
} catch (Exception ignored) {
}
}).start();
}
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action);
super.onDestroyView();
}
@Override
public void onPause() {
if (mLayoutManager != null) {
int position = mLayoutManager.findFirstVisibleItemPosition();
new Thread(() -> {
try {
new QuickLoad(requireActivity()).storeNotifications(position, user_id, instance, notificationType, notificationList);
} catch (Exception ignored) {
}
}).start();
}
super.onPause();
}

@ -48,7 +48,6 @@ import app.fedilab.android.client.entities.api.Pagination;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.api.Statuses;
import app.fedilab.android.client.entities.app.PinnedTimeline;
import app.fedilab.android.client.entities.app.QuickLoad;
import app.fedilab.android.client.entities.app.RemoteInstance;
import app.fedilab.android.client.entities.app.TagTimeline;
import app.fedilab.android.client.entities.app.Timeline;
@ -514,15 +513,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override
public void onPause() {
if (mLayoutManager != null) {
int position = mLayoutManager.findFirstVisibleItemPosition();
new Thread(() -> {
try {
new QuickLoad(requireActivity()).storeTimeline(position, user_id, instance, timelineType, statuses, ident);
} catch (Exception ignored) {
}
}).start();
}
storeMarker();
super.onPause();
}
@ -531,15 +521,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
public void onDestroyView() {
//Update last read id for home timeline
if (isAdded()) {
if (mLayoutManager != null) {
int position = mLayoutManager.findFirstVisibleItemPosition();
new Thread(() -> {
try {
new QuickLoad(requireActivity()).storeTimeline(position, user_id, instance, timelineType, statuses, ident);
} catch (Exception ignored) {
}
}).start();
}
storeMarker();
}
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action);
@ -699,207 +680,175 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
*/
private void route(DIRECTION direction, boolean fetchingMissing) {
new Thread(() -> {
if (binding == null || getActivity() == null || !isAdded()) {
return;
}
boolean nitterInstance = false;
//For remote instance, we check if it's a Nitter timeline
if (timelineType == Timeline.TimeLineEnum.REMOTE) {
nitterInstance = pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER;
}
QuickLoad quickLoad = null;
//For timelines that can be stored we check if there is a stored TL in db
//HOME TL, is excluded and should use its own cache
if (!QuickLoad.cannotBeStored(timelineType)) {
quickLoad = new QuickLoad(requireActivity()).getSavedValue(BaseMainActivity.currentUserID, BaseMainActivity.currentInstance, timelineType, ident);
if (binding == null || getActivity() == null || !isAdded()) {
return;
}
// --- HOME TIMELINE ---
if (timelineType == Timeline.TimeLineEnum.HOME) {
//for more visibility it's done through loadHomeStrategy method
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
//NITTER TIMELINES
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
if (direction == null) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
} //GNU TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.GNU) {
}//MISSKEY TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.MISSKEY) {
if (direction == null) {
timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getMisskey(remoteInstance, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
} //PEERTUBE TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PEERTUBE) {
if (direction == null) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPeertube(remoteInstance, String.valueOf(statuses.size()), MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
} else { //Other remote timelines
routeCommon(direction, fetchingMissing);
}
if (!nitterInstance && !fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) {
Statuses statuses = new Statuses();
statuses.statuses = quickLoad.statuses;
statuses.pagination = new Pagination();
statuses.pagination.max_id = quickLoad.statuses.get(quickLoad.statuses.size() - 1).id;
statuses.pagination.min_id = quickLoad.statuses.get(0).id;
Handler mainHandler = new Handler(Looper.getMainLooper());
QuickLoad finalQuickLoad = quickLoad;
Runnable myRunnable = () -> initializeStatusesCommonView(statuses, finalQuickLoad.position);
mainHandler.post(myRunnable);
} else {
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (!isAdded()) {
return;
}
// --- HOME TIMELINE ---
if (timelineType == Timeline.TimeLineEnum.HOME) {
//for more visibility it's done through loadHomeStrategy method
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
//NITTER TIMELINES
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
if (direction == null) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
} //GNU TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.GNU) {
}//MISSKEY TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.MISSKEY) {
if (direction == null) {
timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getMisskey(remoteInstance, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
} //PEERTUBE TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PEERTUBE) {
if (direction == null) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPeertube(remoteInstance, String.valueOf(statuses.size()), MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true);
} else {
initializeStatusesCommonView(statusesRefresh);
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
routeCommon(direction, fetchingMissing);
} 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 && pinnedStatuses != null && pinnedStatuses.statuses != null) {
for (Status status : pinnedStatuses.statuses) {
status.pinned = true;
}
});
}
} else { //Other remote timelines
routeCommon(direction, fetchingMissing);
}
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
routeCommon(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
routeCommon(direction, fetchingMissing);
} 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 && pinnedStatuses != null && pinnedStatuses.statuses != null) {
for (Status status : pinnedStatuses.statuses) {
status.pinned = true;
}
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, false));
} 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 -> {
if (results != null) {
Statuses statuses = new Statuses();
statuses.statuses = results.statuses;
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
});
} 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 -> {
if (results != null) {
Statuses statuses = new Statuses();
statuses.statuses = results.statuses;
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
});
} 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, false));
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, false));
} 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 -> {
if (results != null) {
Statuses statuses = new Statuses();
statuses.statuses = results.statuses;
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
flagLoading = false;
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
} 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, false));
});
} 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 -> {
if (results != null) {
Statuses statuses = new Statuses();
statuses.statuses = results.statuses;
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
flagLoading = false;
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
} else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE) {
if (direction == null) {
timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance)
.observe(getViewLifecycleOwner(), statusesTrends -> {
Statuses statuses = new Statuses();
statuses.statuses = new ArrayList<>();
if (statusesTrends != null) {
statuses.statuses.addAll(statusesTrends);
}
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
});
}
}
};
mainHandler.post(myRunnable);
});
} 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, false));
} 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, false));
} else {
flagLoading = false;
}
} else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE) {
if (direction == null) {
timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance)
.observe(getViewLifecycleOwner(), statusesTrends -> {
Statuses statuses = new Statuses();
statuses.statuses = new ArrayList<>();
if (statusesTrends != null) {
statuses.statuses.addAll(statusesTrends);
}
statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
});
}
}
}).start();
}

@ -42,7 +42,6 @@ import app.fedilab.android.client.entities.api.ScheduledStatus;
import app.fedilab.android.client.entities.api.ScheduledStatuses;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.BaseAccount;
import app.fedilab.android.client.entities.app.QuickLoad;
import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
@ -320,7 +319,6 @@ public class StatusesVM extends AndroidViewModel {
try {
BaseAccount account = new app.fedilab.android.client.entities.app.Account(getApplication().getApplicationContext()).getAccountByToken(token);
new StatusCache(getApplication().getApplicationContext()).deleteStatus(id, account.instance);
new QuickLoad(getApplication().getApplicationContext()).deleteStatus(account, id);
} catch (DBException e) {
e.printStackTrace();
}

Loading…
Cancel
Save