mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix issue #70 - Timeline can be mixed due to cache
This commit is contained in:
parent
cba32bd12b
commit
c2d3ae8e40
2 changed files with 13 additions and 12 deletions
|
@ -24,7 +24,6 @@ import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.MastodonHelper;
|
||||||
|
@ -113,7 +112,7 @@ public class QuickLoad {
|
||||||
* @param statusList - List<Status> to save
|
* @param statusList - List<Status> to save
|
||||||
* @param ident - the name for pinned timeline
|
* @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)) {
|
if (cannotBeStored(timeLineType)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -125,8 +124,8 @@ public class QuickLoad {
|
||||||
quickLoad.position = position;
|
quickLoad.position = position;
|
||||||
quickLoad.statuses = statusList;
|
quickLoad.statuses = statusList;
|
||||||
quickLoad.slug = key;
|
quickLoad.slug = key;
|
||||||
quickLoad.instance = MainActivity.currentInstance;
|
quickLoad.instance = user_id;
|
||||||
quickLoad.user_id = MainActivity.currentUserID;
|
quickLoad.user_id = instance;
|
||||||
purge(quickLoad);
|
purge(quickLoad);
|
||||||
try {
|
try {
|
||||||
insertOrUpdate(quickLoad);
|
insertOrUpdate(quickLoad);
|
||||||
|
@ -233,7 +232,7 @@ public class QuickLoad {
|
||||||
* @param ident - the name for pinned timeline
|
* @param ident - the name for pinned timeline
|
||||||
* @return SavedValues
|
* @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)) {
|
if (cannotBeStored(timeLineType)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +241,7 @@ public class QuickLoad {
|
||||||
key += "|" + ident;
|
key += "|" + ident;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return get(key);
|
return get(user_id, instance, key);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -316,13 +315,13 @@ public class QuickLoad {
|
||||||
* @return Statuses
|
* @return Statuses
|
||||||
* @throws DBException - throws a db exception
|
* @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) {
|
if (db == null) {
|
||||||
throw new DBException("db is null. Wrong initialization.");
|
throw new DBException("db is null. Wrong initialization.");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Cursor c = db.query(Sqlite.TABLE_QUICK_LOAD, null, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?",
|
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);
|
return cursorToQuickLoad(c);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.client.entities.QuickLoad;
|
import app.fedilab.android.client.entities.QuickLoad;
|
||||||
import app.fedilab.android.client.entities.Timeline;
|
import app.fedilab.android.client.entities.Timeline;
|
||||||
import app.fedilab.android.client.entities.app.TagTimeline;
|
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 boolean exclude_replies, exclude_reblogs, show_pinned, media_only, minified;
|
||||||
private String viewModelKey, remoteInstance;
|
private String viewModelKey, remoteInstance;
|
||||||
private String ident;
|
private String ident;
|
||||||
|
private String instance, user_id;
|
||||||
|
|
||||||
//Handle actions that can be done in other fragments
|
//Handle actions that can be done in other fragments
|
||||||
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
||||||
|
@ -160,7 +161,8 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
timelineType = Timeline.TimeLineEnum.HOME;
|
timelineType = Timeline.TimeLineEnum.HOME;
|
||||||
|
instance = MainActivity.currentInstance;
|
||||||
|
user_id = MainActivity.currentUserID;
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE);
|
timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE);
|
||||||
list_id = getArguments().getString(Helper.ARG_LIST_ID, null);
|
list_id = getArguments().getString(Helper.ARG_LIST_ID, null);
|
||||||
|
@ -425,7 +427,7 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
int position = mLayoutManager.findFirstVisibleItemPosition();
|
int position = mLayoutManager.findFirstVisibleItemPosition();
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
new QuickLoad(requireActivity()).storeTimeline(position, timelineType, statuses, ident);
|
new QuickLoad(requireActivity()).storeTimeline(position, user_id, instance, timelineType, statuses, ident);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -476,7 +478,7 @@ public class FragmentMastodonTimeline extends Fragment {
|
||||||
private void route(DIRECTION direction) {
|
private void route(DIRECTION direction) {
|
||||||
|
|
||||||
new Thread(() -> {
|
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) {
|
if (binding == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue