Fix issue #70 - Timeline can be mixed due to cache

This commit is contained in:
Thomas 2022-05-21 15:31:34 +02:00
parent cba32bd12b
commit c2d3ae8e40
2 changed files with 13 additions and 12 deletions

View file

@ -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<Status> to save
* @param ident - the name for pinned timeline
*/
public void storeTimeline(int position, Timeline.TimeLineEnum timeLineType, List<Status> statusList, String ident) {
public void storeTimeline(int position, String user_id, String instance, Timeline.TimeLineEnum timeLineType, List<Status> 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();

View file

@ -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;
}