summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2022-10-04 11:19:01 +0200
committerThomas <tschneider.ac@gmail.com>2022-10-04 11:19:01 +0200
commitfd9d9ba2e06b33c91ea5c7bc00688c6a25b7a45c (patch)
treeaa2f98dc52341ea79348a2de52270d8184fd7570
parenta93bfd6389fc2a2a970ab680f3ace650c08014aa (diff)
cache count
-rw-r--r--app/src/main/java/app/fedilab/android/activities/CacheActivity.java18
-rw-r--r--app/src/main/java/app/fedilab/android/client/entities/app/CacheAccount.java6
-rw-r--r--app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java43
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java4
-rw-r--r--app/src/main/res/layout/drawer_cache.xml1
5 files changed, 72 insertions, 0 deletions
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 7a8dce5b3..b2bc8c7ad 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 7f27aea50..b537d2d18 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 3204d1c44..0ffd7ad93 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 f914d301c..102492cba 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<RecyclerView.ViewHolder>
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 608eb7e79..5b8ecb283 100644
--- a/app/src/main/res/layout/drawer_cache.xml
+++ b/app/src/main/res/layout/drawer_cache.xml
@@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
+ android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">