Fix issue #82 - Wrong position when storing in cache

This commit is contained in:
Thomas 2022-05-22 11:51:32 +02:00
parent b809dfecfd
commit 9cc5170a70
4 changed files with 89 additions and 7 deletions

View file

@ -124,8 +124,8 @@ public class QuickLoad {
quickLoad.position = position;
quickLoad.statuses = statusList;
quickLoad.slug = key;
quickLoad.instance = user_id;
quickLoad.user_id = instance;
quickLoad.instance = instance;
quickLoad.user_id = user_id;
purge(quickLoad);
try {
insertOrUpdate(quickLoad);
@ -159,6 +159,45 @@ public class QuickLoad {
}
/**
* delete all cache for all accounts
*
* @return long - db id
* @throws DBException exception with database
*/
public long deleteForAllAccount() throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_QUICK_LOAD, null, null);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* delete all cache for an account
*
* @param account - Account
* @return long - db id
* @throws DBException exception with database
*/
public long deleteForAccount(Account account) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_QUICK_LOAD,
Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{account.user_id, account.instance});
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* Delete a status in quickload
*

View file

@ -194,6 +194,45 @@ public class StatusCache {
}
/**
* delete all cache for all account
*
* @return long - db id
* @throws DBException exception with database
*/
public long deleteForAllAccount() throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_STATUS_CACHE, null, null);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* delete all cache for an account
*
* @param account - Account
* @return long - db id
* @throws DBException exception with database
*/
public long deleteForAccount(Account account) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
return db.delete(Sqlite.TABLE_STATUS_CACHE,
Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{account.user_id, account.instance});
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* delete a status in db
*

View file

@ -125,6 +125,8 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.WebviewActivity;
import app.fedilab.android.broadcastreceiver.ToastMessage;
import app.fedilab.android.client.entities.Account;
import app.fedilab.android.client.entities.QuickLoad;
import app.fedilab.android.client.entities.StatusCache;
import app.fedilab.android.client.mastodon.entities.Attachment;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.sqlite.Sqlite;
@ -1518,9 +1520,11 @@ public class Helper {
deleteDir(dir);
}
if (clean_all.isChecked()) {
new QuickLoad(contextReference.get()).deleteForAllAccount();
new StatusCache(contextReference.get()).deleteForAllAccount();
} else {
new QuickLoad(contextReference.get()).deleteForAccount(MainActivity.accountWeakReference.get());
new StatusCache(contextReference.get()).deleteForAccount(MainActivity.accountWeakReference.get());
}
Handler mainHandler2 = new Handler(Looper.getMainLooper());
Runnable myRunnable2 = () -> {

View file

@ -407,15 +407,15 @@ public class FragmentMastodonTimeline extends Fragment {
@Override
public void onPause() {
/* if (mLayoutManager != null) {
if (mLayoutManager != null) {
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();
}*/
}
storeMarker();
super.onPause();
}