Store timelines in db for faster start / switch between them.

This commit is contained in:
Thomas 2022-05-07 13:55:15 +02:00
parent e4375381e9
commit 2ad650ba2f
2 changed files with 18 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import java.util.List;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.client.mastodon.entities.Status;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.SpannableHelper; import app.fedilab.android.helper.SpannableHelper;
import app.fedilab.android.sqlite.Sqlite; import app.fedilab.android.sqlite.Sqlite;
@ -126,6 +127,7 @@ public class QuickLoad {
quickLoad.slug = key; quickLoad.slug = key;
quickLoad.instance = MainActivity.currentInstance; quickLoad.instance = MainActivity.currentInstance;
quickLoad.user_id = MainActivity.currentUserID; quickLoad.user_id = MainActivity.currentUserID;
purge(quickLoad);
try { try {
insertOrUpdate(quickLoad); insertOrUpdate(quickLoad);
} catch (DBException e) { } catch (DBException e) {
@ -180,6 +182,21 @@ public class QuickLoad {
return null; 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);
}
/** /**
* Update a QuickLoad in db * Update a QuickLoad in db
* *

View File

@ -408,7 +408,7 @@ public class FragmentMastodonTimeline extends Fragment {
new Thread(() -> { new Thread(() -> {
QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(timelineType, ident); QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(timelineType, ident);
if (quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { if (direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) {
Statuses statuses = new Statuses(); Statuses statuses = new Statuses();
statuses.statuses = quickLoad.statuses; statuses.statuses = quickLoad.statuses;
statuses.pagination = new Pagination(); statuses.pagination = new Pagination();