diff options
Diffstat (limited to 'app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java')
-rw-r--r-- | app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java | 26 |
1 files changed, 25 insertions, 1 deletions
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 7c718b2ad..7e438623b 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); @@ -255,6 +258,27 @@ public class CachedBundle { /** * 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 */ private void removeIntent(BaseAccount account, String target_id) throws DBException { if (db == null) { |