From d2f9c13f2ea0bb4d79ae95a7315e802968efaaed Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 4 Oct 2022 15:13:22 +0200 Subject: [PATCH] Delete cache for all timelines after 7 days --- .../app/fedilab/android/BaseMainActivity.java | 3 +++ .../client/entities/app/StatusCache.java | 24 +++++++++++++++++++ .../android/helper/PinnedTimelineHelper.java | 18 ++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 245ebc3c..f0ff5669 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -124,6 +124,7 @@ import app.fedilab.android.client.entities.app.BottomMenu; import app.fedilab.android.client.entities.app.DomainsBlock; import app.fedilab.android.client.entities.app.Pinned; import app.fedilab.android.client.entities.app.PinnedTimeline; +import app.fedilab.android.client.entities.app.StatusCache; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.client.entities.app.Timeline; import app.fedilab.android.databinding.ActivityMainBinding; @@ -760,6 +761,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt new Thread(() -> { try { currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); + //Delete cache older than 7 days + new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days(); } catch (DBException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java index 0ffd7ad9..821b8459 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java @@ -23,6 +23,7 @@ import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; @@ -385,6 +386,29 @@ public class StatusCache { } } + /** + * delete all cache for all account after 7 days + * + * @return long - db id + * @throws DBException exception with database + */ + public long deleteForAllAccountAfter7Days() 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, -7); + Date date = cal.getTime(); + String dateStr = Helper.dateToString(date); + try { + return db.delete(Sqlite.TABLE_STATUS_CACHE, Sqlite.COL_CREATED_AT + " < ?", new String[]{dateStr}); + } catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + /** * delete all cache for an account * diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 8bae379f..3293a9c2 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -123,10 +123,6 @@ public class PinnedTimelineHelper { params.setMargins(0, 0, 0, actionBarHeight); } } - //Remove badge when reselecting - activityMainBinding.bottomNavView.setOnItemReselectedListener(item -> { - activityMainBinding.bottomNavView.removeBadge(item.getItemId()); - }); activityMainBinding.viewPager.setLayoutParams(params); List pinnedTimelines = pinned.pinnedTimelines; @@ -501,6 +497,20 @@ public class PinnedTimelineHelper { @Override public void onTabReselected(TabLayout.Tab tab) { + if (!singleBar && tab.getTag() != null) { + if (tab.getTag().equals(Timeline.TimeLineEnum.HOME.getValue())) { + activityMainBinding.bottomNavView.removeBadge(R.id.nav_home); + } else if (tab.getTag().equals(Timeline.TimeLineEnum.LOCAL.getValue())) { + activityMainBinding.bottomNavView.removeBadge(R.id.nav_local); + } else if (tab.getTag().equals(Timeline.TimeLineEnum.PUBLIC.getValue())) { + activityMainBinding.bottomNavView.removeBadge(R.id.nav_public); + } else if (tab.getTag().equals(Timeline.TimeLineEnum.NOTIFICATION.getValue())) { + activityMainBinding.bottomNavView.removeBadge(R.id.nav_notifications); + } else if (tab.getTag().equals(Timeline.TimeLineEnum.CONVERSATION.getValue())) { + activityMainBinding.bottomNavView.removeBadge(R.id.nav_privates); + } + + } Fragment fragment = fedilabPageAdapter.getCurrentFragment(); View view = tab.getCustomView(); if (view != null) {