mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-23 09:10:04 +02:00
cache count
This commit is contained in:
parent
a93bfd6389
commit
fd9d9ba2e0
5 changed files with 72 additions and 0 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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">
|
||||
|
||||
|
|
Loading…
Reference in a new issue