Fix issue #82 - Wrong position when storing in cache

pull/95/head
Thomas 3 years ago
parent b809dfecfd
commit 9cc5170a70

@ -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
*

@ -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
*

@ -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 = () -> {

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

Loading…
Cancel
Save