From e589e2549d949b7b3b0cdb594ceeb2adf5c5eca2 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 12 Jan 2024 11:05:42 +0100 Subject: [PATCH] Keep intent longer --- .../app/fedilab/android/BaseMainActivity.java | 4 +-- .../client/entities/app/CachedBundle.java | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 6531aa63..7dfb38fb 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -321,7 +321,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt args2.putSerializable(Helper.ARG_STATUS, statusSent); new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> { Bundle bundle2 = new Bundle(); - bundle.putLong(Helper.ARG_INTENT_ID, bundleId2); + bundle2.putLong(Helper.ARG_INTENT_ID, bundleId2); intentContext.putExtras(bundle2); intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intentContext); @@ -348,7 +348,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } } }); - } } }; @@ -378,6 +377,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt //Delete cache older than 7 days new StatusCache(activity).deleteForAllAccountAfter7Days(); new TimelineCacheLogs(activity).deleteForAllAccountAfter7Days(); + new CachedBundle(activity).deleteOldIntent(); } catch (DBException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java index 7c718b2a..7e438623 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java @@ -30,6 +30,7 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Calendar; import java.util.Date; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -142,9 +143,11 @@ public class CachedBundle { } } } - removeIntent(String.valueOf(id)); } catch (DBException ignored) { } + if( bundle == null) { + bundle = new Bundle(); + } Handler mainHandler = new Handler(Looper.getMainLooper()); Bundle finalBundle = bundle; Runnable myRunnable = () -> callback.get(finalBundle); @@ -253,6 +256,27 @@ public class CachedBundle { db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_ID + " = '" + id + "'", null); } + /** + * Remove a bundle from db + * + */ + public long deleteOldIntent() throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + cal.add(Calendar.DATE, -1); + Date date = cal.getTime(); + String dateStr = Helper.dateToString(date); + try { + return db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_CREATED_AT + " < ?", new String[]{dateStr}); + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + /** * Remove a bundle from db */