Store timelines in db for faster start / switch between them.
This commit is contained in:
parent
e4375381e9
commit
2ad650ba2f
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.client.mastodon.entities.Status;
|
||||
import app.fedilab.android.exception.DBException;
|
||||
import app.fedilab.android.helper.MastodonHelper;
|
||||
import app.fedilab.android.helper.SpannableHelper;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
|
||||
|
@ -126,6 +127,7 @@ public class QuickLoad {
|
|||
quickLoad.slug = key;
|
||||
quickLoad.instance = MainActivity.currentInstance;
|
||||
quickLoad.user_id = MainActivity.currentUserID;
|
||||
purge(quickLoad);
|
||||
try {
|
||||
insertOrUpdate(quickLoad);
|
||||
} catch (DBException e) {
|
||||
|
@ -180,6 +182,21 @@ public class QuickLoad {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -408,7 +408,7 @@ public class FragmentMastodonTimeline extends Fragment {
|
|||
|
||||
new Thread(() -> {
|
||||
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 = quickLoad.statuses;
|
||||
statuses.pagination = new Pagination();
|
||||
|
|
Loading…
Reference in New Issue