From c2d3ae8e40e565af810f68f163b3aaf012368042 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 21 May 2022 15:31:34 +0200 Subject: [PATCH] Fix issue #70 - Timeline can be mixed due to cache --- .../android/client/entities/QuickLoad.java | 15 +++++++-------- .../timeline/FragmentMastodonTimeline.java | 10 ++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java index 64389e91..d33b68a0 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java +++ b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java @@ -24,7 +24,6 @@ import com.google.gson.annotations.SerializedName; 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; @@ -113,7 +112,7 @@ public class QuickLoad { * @param statusList - List to save * @param ident - the name for pinned timeline */ - public void storeTimeline(int position, Timeline.TimeLineEnum timeLineType, List statusList, String ident) { + public void storeTimeline(int position, String user_id, String instance, Timeline.TimeLineEnum timeLineType, List statusList, String ident) { if (cannotBeStored(timeLineType)) { return; } @@ -125,8 +124,8 @@ public class QuickLoad { quickLoad.position = position; quickLoad.statuses = statusList; quickLoad.slug = key; - quickLoad.instance = MainActivity.currentInstance; - quickLoad.user_id = MainActivity.currentUserID; + quickLoad.instance = user_id; + quickLoad.user_id = instance; purge(quickLoad); try { insertOrUpdate(quickLoad); @@ -233,7 +232,7 @@ public class QuickLoad { * @param ident - the name for pinned timeline * @return SavedValues */ - public QuickLoad getSavedValue(Timeline.TimeLineEnum timeLineType, String ident) { + public QuickLoad getSavedValue(String user_id, String instance, Timeline.TimeLineEnum timeLineType, String ident) { if (cannotBeStored(timeLineType)) { return null; } @@ -242,7 +241,7 @@ public class QuickLoad { key += "|" + ident; } try { - return get(key); + return get(user_id, instance, key); } catch (DBException e) { e.printStackTrace(); } @@ -316,13 +315,13 @@ public class QuickLoad { * @return Statuses * @throws DBException - throws a db exception */ - private QuickLoad get(String slug) throws DBException { + 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[]{MainActivity.currentUserID, MainActivity.currentInstance, slug}, null, null, null, "1"); + new String[]{user_id, instance, slug}, null, null, null, "1"); return cursorToQuickLoad(c); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 095b1e0c..8b96b1dc 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -41,6 +41,7 @@ import java.util.List; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.client.entities.QuickLoad; import app.fedilab.android.client.entities.Timeline; import app.fedilab.android.client.entities.app.TagTimeline; @@ -82,7 +83,7 @@ public class FragmentMastodonTimeline extends Fragment { private boolean exclude_replies, exclude_reblogs, show_pinned, media_only, minified; private String viewModelKey, remoteInstance; private String ident; - + private String instance, user_id; //Handle actions that can be done in other fragments private final BroadcastReceiver receive_action = new BroadcastReceiver() { @@ -160,7 +161,8 @@ public class FragmentMastodonTimeline extends Fragment { ViewGroup container, Bundle savedInstanceState) { timelineType = Timeline.TimeLineEnum.HOME; - + instance = MainActivity.currentInstance; + user_id = MainActivity.currentUserID; if (getArguments() != null) { timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE); list_id = getArguments().getString(Helper.ARG_LIST_ID, null); @@ -425,7 +427,7 @@ public class FragmentMastodonTimeline extends Fragment { int position = mLayoutManager.findFirstVisibleItemPosition(); new Thread(() -> { try { - new QuickLoad(requireActivity()).storeTimeline(position, timelineType, statuses, ident); + new QuickLoad(requireActivity()).storeTimeline(position, user_id, instance, timelineType, statuses, ident); } catch (Exception ignored) { } }).start(); @@ -476,7 +478,7 @@ public class FragmentMastodonTimeline extends Fragment { private void route(DIRECTION direction) { new Thread(() -> { - QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(timelineType, ident); + QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident); if (binding == null) { return; }