diff --git a/app/src/main/java/app/fedilab/android/activities/CacheActivity.java b/app/src/main/java/app/fedilab/android/activities/CacheActivity.java index 7a8dce5b..b2bc8c7a 100644 --- a/app/src/main/java/app/fedilab/android/activities/CacheActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/CacheActivity.java @@ -36,7 +36,10 @@ import app.fedilab.android.R; import app.fedilab.android.client.entities.app.Account; import app.fedilab.android.client.entities.app.BaseAccount; import app.fedilab.android.client.entities.app.CacheAccount; +import app.fedilab.android.client.entities.app.StatusCache; +import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.databinding.ActivityCacheBinding; +import app.fedilab.android.exception.DBException; import app.fedilab.android.helper.CacheHelper; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.ThemeHelper; @@ -72,6 +75,21 @@ public class CacheActivity extends BaseActivity { for (BaseAccount baseAccount : accounts) { CacheAccount cacheAccount = new CacheAccount(); cacheAccount.account = baseAccount; + try { + cacheAccount.home_cache_count = new StatusCache(CacheActivity.this).countHome(baseAccount); + } catch (DBException e) { + e.printStackTrace(); + } + try { + cacheAccount.other_cache_count = new StatusCache(CacheActivity.this).countOther(baseAccount); + } catch (DBException e) { + e.printStackTrace(); + } + try { + cacheAccount.draft_count = new StatusDraft(CacheActivity.this).count(baseAccount); + } catch (DBException e) { + e.printStackTrace(); + } cacheAccounts.add(cacheAccount); } Handler mainHandler = new Handler(Looper.getMainLooper()); diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/CacheAccount.java b/app/src/main/java/app/fedilab/android/client/entities/app/CacheAccount.java index 7f27aea5..b537d2d1 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/CacheAccount.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/CacheAccount.java @@ -28,4 +28,10 @@ public class CacheAccount implements Serializable { public boolean clear_drafts = false; @SerializedName("account") public BaseAccount account; + @SerializedName("home_cache_count") + public int home_cache_count; + @SerializedName("other_cache_count") + public int other_cache_count; + @SerializedName("draft_count") + public int draft_count; } 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 3204d1c4..0ffd7ad9 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 @@ -210,6 +210,49 @@ public class StatusCache { } } + + /** + * count messages for home + * + * @param baseAccount Status {@link BaseAccount} + * @return int - number of occurrences + * @throws DBException Exception + */ + public int countHome(BaseAccount baseAccount) throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_CACHE + + " where " + Sqlite.COL_TYPE + " = '" + Timeline.TimeLineEnum.HOME.getValue() + "'" + + " AND " + Sqlite.COL_INSTANCE + " = '" + baseAccount.instance + "'" + + " AND " + Sqlite.COL_USER_ID + "= '" + baseAccount.user_id + "'", null); + mCount.moveToFirst(); + int count = mCount.getInt(0); + mCount.close(); + return count; + } + + /** + * count messages for other timelines + * + * @param baseAccount Status {@link BaseAccount} + * @return int - number of occurrences + * @throws DBException Exception + */ + public int countOther(BaseAccount baseAccount) throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_CACHE + + " where " + Sqlite.COL_TYPE + " != '" + Timeline.TimeLineEnum.HOME.getValue() + "'" + + " AND " + Sqlite.COL_INSTANCE + " = '" + baseAccount.instance + "'" + + " AND " + Sqlite.COL_USER_ID + "= '" + baseAccount.user_id + "'", null); + mCount.moveToFirst(); + int count = mCount.getInt(0); + mCount.close(); + return count; + } + /** * Check if a status exists in db * diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java index f914d301..102492cb 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java @@ -71,6 +71,10 @@ public class CacheAdapter extends RecyclerView.Adapter holder.binding.draftCount.setText(String.valueOf(countStatuses.get(2))); } }); + holder.binding.homeCount.setText(String.valueOf(cacheAccount.home_cache_count)); + holder.binding.otherCount.setText(String.valueOf(cacheAccount.other_cache_count)); + holder.binding.draftCount.setText(String.valueOf(cacheAccount.draft_count)); + holder.binding.labelHomeTimelineCacheCount.setChecked(cacheAccount.clear_home); holder.binding.labelTimelinesCacheCount.setChecked(cacheAccount.clear_other); holder.binding.labelDraftsCount.setChecked(cacheAccount.clear_drafts); diff --git a/app/src/main/res/layout/drawer_cache.xml b/app/src/main/res/layout/drawer_cache.xml index 608eb7e7..5b8ecb28 100644 --- a/app/src/main/res/layout/drawer_cache.xml +++ b/app/src/main/res/layout/drawer_cache.xml @@ -2,6 +2,7 @@