diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f907ab4b..b79bd1f0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -184,6 +184,11 @@
android:theme="@style/AppThemeBarDark"
android:windowSoftInputMode="stateVisible" />
+
+
{
- BaseMainActivity.this.recreate();
- recreate();
- dialog.dismiss();
- })
- .setIcon(android.R.drawable.ic_dialog_alert)
- .show();
- return true;
}
return true;
});
diff --git a/app/src/main/java/app/fedilab/android/activities/CacheActivity.java b/app/src/main/java/app/fedilab/android/activities/CacheActivity.java
new file mode 100644
index 00000000..58566b8c
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/activities/CacheActivity.java
@@ -0,0 +1,85 @@
+package app.fedilab.android.activities;
+/* Copyright 2022 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see . */
+
+
+import android.graphics.drawable.ColorDrawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.MenuItem;
+
+import androidx.annotation.Nullable;
+import androidx.core.content.ContextCompat;
+import androidx.recyclerview.widget.LinearLayoutManager;
+
+import java.util.List;
+import java.util.Locale;
+
+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.databinding.ActivityCacheBinding;
+import app.fedilab.android.helper.CacheHelper;
+import app.fedilab.android.helper.ThemeHelper;
+import app.fedilab.android.ui.drawer.CacheAdapter;
+
+public class CacheActivity extends BaseActivity {
+
+ private ActivityCacheBinding binding;
+
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ThemeHelper.applyThemeBar(this);
+ binding = ActivityCacheBinding.inflate(getLayoutInflater());
+ setContentView(binding.getRoot());
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
+ }
+ CacheHelper.getCacheValues(CacheActivity.this, size -> {
+ if (size > 0) {
+ size = size / 1000000.0f;
+ }
+ binding.fileCacheSize.setText(String.format("%s %s", String.format(Locale.getDefault(), "%.2f", size), getString(R.string.cache_units)));
+ });
+
+
+ new Thread(() -> {
+ List accounts = new Account(CacheActivity.this).getPushNotificationAccounts();
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ Runnable myRunnable = () -> {
+ CacheAdapter cacheAdapter = new CacheAdapter(accounts);
+ LinearLayoutManager mLayoutManager = new LinearLayoutManager(CacheActivity.this);
+ binding.cacheRecyclerview.setLayoutManager(mLayoutManager);
+ binding.cacheRecyclerview.setAdapter(cacheAdapter);
+ };
+ mainHandler.post(myRunnable);
+ }).start();
+
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/QuickLoad.java b/app/src/main/java/app/fedilab/android/client/entities/app/QuickLoad.java
index a40c385e..9bc3ce6b 100644
--- a/app/src/main/java/app/fedilab/android/client/entities/app/QuickLoad.java
+++ b/app/src/main/java/app/fedilab/android/client/entities/app/QuickLoad.java
@@ -22,6 +22,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.google.gson.annotations.SerializedName;
+import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.client.entities.api.Notification;
@@ -147,6 +148,30 @@ public class QuickLoad {
return (count > 0);
}
+
+ /**
+ * Count statuses in cache for an account
+ *
+ * @param account Account {@link Account}
+ * @return int - Number of statuses
+ * @throws DBException Exception
+ */
+ public int count(BaseAccount account) throws DBException {
+ if (db == null) {
+ throw new DBException("db is null. Wrong initialization.");
+ }
+ int count = 0;
+ Cursor c = db.query(Sqlite.TABLE_QUICK_LOAD, null, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
+ new String[]{account.user_id, account.instance}, null, null, null, null);
+ List quickLoadList = cursorToQuickLoadList(c);
+ if (quickLoadList != null) {
+ for (QuickLoad quickLoad : quickLoadList) {
+ count += quickLoad.statuses.size();
+ }
+ }
+ return count;
+ }
+
/**
* @param position - current position in timeline
* @param timeLineType - Timeline.TimeLineEnum
@@ -510,6 +535,52 @@ public class QuickLoad {
quickLoad.statuses = statuses.subList(startAt, endAt);
}
+
+ /**
+ * Restore statusDraft list from db
+ *
+ * @param c Cursor
+ * @return List
+ */
+ private List cursorToQuickLoadList(Cursor c) {
+ //No element found
+ if (c.getCount() == 0) {
+ c.close();
+ return null;
+ }
+ List quickLoads = new ArrayList<>();
+ while (c.moveToNext()) {
+ QuickLoad quickLoad = convertCursorToQuickLoad(c);
+ quickLoads.add(quickLoad);
+ }
+ //Close the cursor
+ c.close();
+ return quickLoads;
+ }
+
+ /**
+ * Convert a cursor to QuickLoad
+ *
+ * @param c Cursor
+ * @return QuickLoad
+ */
+ private QuickLoad convertCursorToQuickLoad(Cursor c) {
+ QuickLoad quickLoad = new QuickLoad();
+ quickLoad.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID));
+ quickLoad.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE));
+ quickLoad.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID));
+ quickLoad.slug = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_SLUG));
+ if (typeOfFetch == type.STATUSES) {
+ quickLoad.statuses = StatusDraft.restoreStatusListFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
+ } else if (typeOfFetch == type.NOTIFICATIONS) {
+ quickLoad.notifications = Notification.restoreNotificationsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
+ }
+ quickLoad.position = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_POSITION));
+ //TimelineHelper.filterStatus(_mContext, quickLoad.statuses, TimelineHelper.FilterTimeLineType.PUBLIC);
+ quickLoad.statuses = SpannableHelper.convertStatus(_mContext, quickLoad.statuses);
+ return quickLoad;
+ }
+
/**
* Convert a cursor to QuickLoad
*
@@ -524,20 +595,7 @@ public class QuickLoad {
}
//Take the first element
c.moveToFirst();
- QuickLoad quickLoad = new QuickLoad();
- quickLoad.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID));
- quickLoad.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE));
- quickLoad.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID));
- quickLoad.slug = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_SLUG));
- if (typeOfFetch == type.STATUSES) {
- quickLoad.statuses = StatusDraft.restoreStatusListFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
- } else if (typeOfFetch == type.NOTIFICATIONS) {
- quickLoad.notifications = Notification.restoreNotificationsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_STATUSES)));
- }
- quickLoad.position = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_POSITION));
-
- //TimelineHelper.filterStatus(_mContext, quickLoad.statuses, TimelineHelper.FilterTimeLineType.PUBLIC);
- quickLoad.statuses = SpannableHelper.convertStatus(_mContext, quickLoad.statuses);
+ QuickLoad quickLoad = convertCursorToQuickLoad(c);
//Close the cursor
c.close();
return quickLoad;
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 342a2fef..63f21547 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
@@ -343,6 +343,19 @@ public class StatusCache {
return reply;
}
+
+ public int count(BaseAccount account) 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_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null);
+ mCount.moveToFirst();
+ int count = mCount.getInt(0);
+ mCount.close();
+ return count;
+ }
+
/**
* Convert a cursor to list of statuses
*
diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/StatusDraft.java b/app/src/main/java/app/fedilab/android/client/entities/app/StatusDraft.java
index 95e02e50..711d9c8f 100644
--- a/app/src/main/java/app/fedilab/android/client/entities/app/StatusDraft.java
+++ b/app/src/main/java/app/fedilab/android/client/entities/app/StatusDraft.java
@@ -73,6 +73,7 @@ public class StatusDraft implements Serializable {
this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
}
+
/**
* Serialized a list of Status class
*
@@ -190,6 +191,19 @@ public class StatusDraft implements Serializable {
return db.delete(Sqlite.TABLE_STATUS_DRAFT, Sqlite.COL_USER_ID + " = '" + BaseMainActivity.currentUserID + "' AND " + Sqlite.COL_INSTANCE + " = '" + BaseMainActivity.currentInstance + "'", null);
}
+
+ public int count(BaseAccount account) throws DBException {
+ if (db == null) {
+ throw new DBException("db is null. Wrong initialization.");
+ }
+ Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_DRAFT
+ + " where " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null);
+ mCount.moveToFirst();
+ int count = mCount.getInt(0);
+ mCount.close();
+ return count;
+ }
+
/**
* update statusDraft in db
*
diff --git a/app/src/main/java/app/fedilab/android/helper/CacheHelper.java b/app/src/main/java/app/fedilab/android/helper/CacheHelper.java
new file mode 100644
index 00000000..4a87274b
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/helper/CacheHelper.java
@@ -0,0 +1,197 @@
+package app.fedilab.android.helper;
+/* Copyright 2022 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see . */
+
+import static app.fedilab.android.helper.Helper.getCurrentAccount;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.widget.SwitchCompat;
+
+import java.io.File;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+
+import app.fedilab.android.BaseMainActivity;
+import app.fedilab.android.R;
+import app.fedilab.android.client.entities.app.BaseAccount;
+import app.fedilab.android.client.entities.app.QuickLoad;
+import app.fedilab.android.client.entities.app.StatusCache;
+import app.fedilab.android.client.entities.app.StatusDraft;
+import app.fedilab.android.exception.DBException;
+import es.dmoral.toasty.Toasty;
+
+public class CacheHelper {
+
+ public static void getCacheValues(Context context, Callback callback) {
+ new Thread(() -> {
+ long sizeCache = cacheSize(context.getCacheDir().getParentFile());
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ Runnable myRunnable = () -> callback.getCacheSize(sizeCache);
+ mainHandler.post(myRunnable);
+ }).start();
+ }
+
+ public static void getTimelineValues(Context context, BaseAccount account, CallbackAccount callbackAccount) {
+ new Thread(() -> {
+ List count = new ArrayList<>();
+ try {
+ count.add(new StatusCache(context).count(account));
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
+ try {
+ count.add(new QuickLoad(context).count(account));
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
+ try {
+ count.add(new StatusDraft(context).count(account));
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ Runnable myRunnable = () -> callbackAccount.getcount(count);
+ mainHandler.post(myRunnable);
+ }).start();
+ }
+
+ /**
+ * Retrieves the cache size
+ *
+ * @param directory File
+ * @return long value in Mo
+ */
+ public static long cacheSize(File directory) {
+ long length = 0;
+ if (directory == null || directory.length() == 0)
+ return -1;
+ for (File file : Objects.requireNonNull(directory.listFiles())) {
+ if (file.isFile()) {
+ try {
+ length += file.length();
+ } catch (NullPointerException e) {
+ return -1;
+ }
+ } else {
+ if (!file.getName().equals("databases") && !file.getName().equals("shared_prefs")) {
+ length += cacheSize(file);
+ }
+ }
+ }
+ return length;
+ }
+
+ public static boolean deleteDir(File dir) {
+ if (dir != null && dir.isDirectory()) {
+ String[] children = dir.list();
+ assert children != null;
+ for (String aChildren : children) {
+ if (!aChildren.equals("databases") && !aChildren.equals("shared_prefs")) {
+ boolean success = deleteDir(new File(dir, aChildren));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ } else {
+ return dir != null && dir.isFile() && dir.delete();
+ }
+ }
+
+
+ public interface Callback {
+ void getCacheSize(float size);
+ }
+
+
+ public interface CallbackAccount {
+ void getcount(List countStatuses);
+ }
+
+ public static class CacheTask {
+ private final WeakReference contextReference;
+ private float cacheSize;
+
+ public CacheTask(Context context) {
+ contextReference = new WeakReference<>(context);
+ doInBackground();
+ }
+
+ protected void doInBackground() {
+ new Thread(() -> {
+ long sizeCache = cacheSize(contextReference.get().getCacheDir().getParentFile());
+ cacheSize = 0;
+ if (sizeCache > 0) {
+ cacheSize = (float) sizeCache / 1000000.0f;
+ }
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ Runnable myRunnable = () -> {
+ AlertDialog.Builder builder = new AlertDialog.Builder(contextReference.get(), Helper.dialogStyle());
+ LayoutInflater inflater = ((BaseMainActivity) contextReference.get()).getLayoutInflater();
+ View dialogView = inflater.inflate(R.layout.popup_cache, new LinearLayout(contextReference.get()), false);
+ TextView message = dialogView.findViewById(R.id.message);
+ message.setText(contextReference.get().getString(R.string.cache_message, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", cacheSize), contextReference.get().getString(R.string.cache_units))));
+ builder.setView(dialogView);
+ builder.setTitle(R.string.cache_title);
+
+ final SwitchCompat clean_all = dialogView.findViewById(R.id.clean_all);
+ final float finalCacheSize = cacheSize;
+ builder
+ .setPositiveButton(R.string.clear, (dialog, which) -> new Thread(() -> {
+ try {
+ String path = Objects.requireNonNull(contextReference.get().getCacheDir().getParentFile()).getPath();
+ File dir = new File(path);
+ if (dir.isDirectory()) {
+ deleteDir(dir);
+ }
+ if (clean_all.isChecked()) {
+ new QuickLoad(contextReference.get()).deleteForAllAccount();
+ new StatusCache(contextReference.get()).deleteForAllAccount();
+ } else {
+ new QuickLoad(contextReference.get()).deleteForAccount(getCurrentAccount(contextReference.get()));
+ new StatusCache(contextReference.get()).deleteForAccount(getCurrentAccount(contextReference.get()));
+ }
+ Handler mainHandler2 = new Handler(Looper.getMainLooper());
+ Runnable myRunnable2 = () -> {
+ Toasty.success(contextReference.get(), contextReference.get().getString(R.string.toast_cache_clear, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", finalCacheSize), contextReference.get().getString(R.string.cache_units))), Toast.LENGTH_LONG).show();
+ dialog.dismiss();
+ };
+ mainHandler2.post(myRunnable2);
+ } catch (Exception ignored) {
+ }
+ }).start())
+ .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+ };
+ mainHandler.post(myRunnable);
+ }).start();
+ }
+ }
+
+}
diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java
index c15e12c2..1fd9af9b 100644
--- a/app/src/main/java/app/fedilab/android/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/android/helper/Helper.java
@@ -55,7 +55,6 @@ import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.TypedValue;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -67,7 +66,6 @@ import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -75,7 +73,6 @@ import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.widget.SwitchCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
@@ -102,7 +99,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.ref.WeakReference;
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -133,8 +129,6 @@ import app.fedilab.android.broadcastreceiver.ToastMessage;
import app.fedilab.android.client.entities.api.Attachment;
import app.fedilab.android.client.entities.app.Account;
import app.fedilab.android.client.entities.app.BaseAccount;
-import app.fedilab.android.client.entities.app.QuickLoad;
-import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.viewmodel.mastodon.OauthVM;
@@ -1047,49 +1041,6 @@ public class Helper {
}
}
- /**
- * Retrieves the cache size
- *
- * @param directory File
- * @return long value in Mo
- */
- public static long cacheSize(File directory) {
- long length = 0;
- if (directory == null || directory.length() == 0)
- return -1;
- for (File file : Objects.requireNonNull(directory.listFiles())) {
- if (file.isFile()) {
- try {
- length += file.length();
- } catch (NullPointerException e) {
- return -1;
- }
- } else {
- if (!file.getName().equals("databases") && !file.getName().equals("shared_prefs")) {
- length += cacheSize(file);
- }
- }
- }
- return length;
- }
-
- public static boolean deleteDir(File dir) {
- if (dir != null && dir.isDirectory()) {
- String[] children = dir.list();
- assert children != null;
- for (String aChildren : children) {
- if (!aChildren.equals("databases") && !aChildren.equals("shared_prefs")) {
- boolean success = deleteDir(new File(dir, aChildren));
- if (!success) {
- return false;
- }
- }
- }
- return dir.delete();
- } else {
- return dir != null && dir.isFile() && dir.delete();
- }
- }
public static Proxy getProxy(Context context) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@@ -1626,64 +1577,5 @@ public class Helper {
return currentAccount;
}
- public static class CacheTask {
- private final WeakReference contextReference;
- private float cacheSize;
- public CacheTask(Context context) {
- contextReference = new WeakReference<>(context);
- doInBackground();
- }
-
- protected void doInBackground() {
- new Thread(() -> {
- long sizeCache = cacheSize(contextReference.get().getCacheDir().getParentFile());
- cacheSize = 0;
- if (sizeCache > 0) {
- cacheSize = (float) sizeCache / 1000000.0f;
- }
- Handler mainHandler = new Handler(Looper.getMainLooper());
- Runnable myRunnable = () -> {
- AlertDialog.Builder builder = new AlertDialog.Builder(contextReference.get(), Helper.dialogStyle());
- LayoutInflater inflater = ((BaseMainActivity) contextReference.get()).getLayoutInflater();
- View dialogView = inflater.inflate(R.layout.popup_cache, new LinearLayout(contextReference.get()), false);
- TextView message = dialogView.findViewById(R.id.message);
- message.setText(contextReference.get().getString(R.string.cache_message, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", cacheSize), contextReference.get().getString(R.string.cache_units))));
- builder.setView(dialogView);
- builder.setTitle(R.string.cache_title);
-
- final SwitchCompat clean_all = dialogView.findViewById(R.id.clean_all);
- final float finalCacheSize = cacheSize;
- builder
- .setPositiveButton(R.string.clear, (dialog, which) -> new Thread(() -> {
- try {
- String path = Objects.requireNonNull(contextReference.get().getCacheDir().getParentFile()).getPath();
- File dir = new File(path);
- if (dir.isDirectory()) {
- deleteDir(dir);
- }
- if (clean_all.isChecked()) {
- new QuickLoad(contextReference.get()).deleteForAllAccount();
- new StatusCache(contextReference.get()).deleteForAllAccount();
- } else {
- new QuickLoad(contextReference.get()).deleteForAccount(getCurrentAccount(contextReference.get()));
- new StatusCache(contextReference.get()).deleteForAccount(getCurrentAccount(contextReference.get()));
- }
- Handler mainHandler2 = new Handler(Looper.getMainLooper());
- Runnable myRunnable2 = () -> {
- Toasty.success(contextReference.get(), contextReference.get().getString(R.string.toast_cache_clear, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", finalCacheSize), contextReference.get().getString(R.string.cache_units))), Toast.LENGTH_LONG).show();
- dialog.dismiss();
- };
- mainHandler2.post(myRunnable2);
- } catch (Exception ignored) {
- }
- }).start())
- .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
- .setIcon(android.R.drawable.ic_dialog_alert)
- .show();
- };
- mainHandler.post(myRunnable);
- }).start();
- }
- }
}
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
new file mode 100644
index 00000000..953e058c
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/CacheAdapter.java
@@ -0,0 +1,96 @@
+package app.fedilab.android.ui.drawer;
+/* Copyright 2022 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see . */
+
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.util.List;
+
+import app.fedilab.android.activities.ProfileActivity;
+import app.fedilab.android.client.entities.app.BaseAccount;
+import app.fedilab.android.databinding.DrawerCacheBinding;
+import app.fedilab.android.helper.CacheHelper;
+import app.fedilab.android.helper.MastodonHelper;
+
+
+public class CacheAdapter extends RecyclerView.Adapter {
+
+ private static ProfileActivity.action doAction;
+ private final List accountList;
+ private Context context;
+
+ public CacheAdapter(List accountList) {
+ this.accountList = accountList;
+ }
+
+
+ public int getCount() {
+ return accountList.size();
+ }
+
+ public BaseAccount getItem(int position) {
+ return accountList.get(position);
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ this.context = parent.getContext();
+ DrawerCacheBinding itemBinding = DrawerCacheBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
+ return new AccountCacheViewHolder(itemBinding);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
+ BaseAccount account = accountList.get(position);
+ AccountCacheViewHolder holder = (AccountCacheViewHolder) viewHolder;
+ MastodonHelper.loadPPMastodon(holder.binding.pp, account.mastodon_account);
+ holder.binding.acct.setText(String.format("@%s@%s", account.mastodon_account.username, account.instance));
+ holder.binding.displayName.setText(account.mastodon_account.display_name);
+ CacheHelper.getTimelineValues(context, account, countStatuses -> {
+ if (countStatuses != null && countStatuses.size() == 3) {
+ holder.binding.homeCount.setText(String.valueOf(countStatuses.get(0)));
+ holder.binding.otherCount.setText(String.valueOf(countStatuses.get(1)));
+ holder.binding.draftCount.setText(String.valueOf(countStatuses.get(2)));
+ }
+ });
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public int getItemCount() {
+ return accountList.size();
+ }
+
+
+ public static class AccountCacheViewHolder extends RecyclerView.ViewHolder {
+ DrawerCacheBinding binding;
+
+ AccountCacheViewHolder(DrawerCacheBinding itemView) {
+ super(itemView.getRoot());
+ binding = itemView;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java
index 4fe8e831..d1da7a79 100644
--- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java
+++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java
@@ -19,8 +19,12 @@ import android.os.Bundle;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SeekBarPreference;
import app.fedilab.android.R;
+import app.fedilab.android.helper.Helper;
+import es.dmoral.toasty.Toasty;
public class FragmentInterfaceSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -30,8 +34,21 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen
createPref();
}
+ boolean recreate;
private void createPref() {
-
+ getPreferenceScreen().removeAll();
+ addPreferencesFromResource(R.xml.pref_interface);
+ PreferenceScreen preferenceScreen = getPreferenceScreen();
+ if (preferenceScreen == null) {
+ Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
+ return;
+ }
+ SeekBarPreference SET_FONT_SCALE = findPreference(getString(R.string.SET_FONT_SCALE_INT));
+ if (SET_FONT_SCALE != null) {
+ SET_FONT_SCALE.setMax(180);
+ SET_FONT_SCALE.setMin(80);
+ }
+ recreate = false;
}
@Override
@@ -39,7 +56,12 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen
if (getActivity() != null) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
SharedPreferences.Editor editor = sharedpreferences.edit();
-
+ if (key.compareToIgnoreCase(getString(R.string.SET_FONT_SCALE_INT)) == 0) {
+ int progress = sharedPreferences.getInt(getString(R.string.SET_FONT_SCALE_INT), 110);
+ float scale = (float) (progress) / 100.0f;
+ editor.putFloat(getString(R.string.SET_FONT_SCALE), scale);
+ recreate = true;
+ }
editor.apply();
}
}
@@ -57,6 +79,11 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
+ if (recreate) {
+ recreate = false;
+ requireActivity().recreate();
+ Helper.recreateMainActivity(requireActivity());
+ }
}
diff --git a/app/src/main/res/layout/activity_cache.xml b/app/src/main/res/layout/activity_cache.xml
new file mode 100644
index 00000000..075c1d3c
--- /dev/null
+++ b/app/src/main/res/layout/activity_cache.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/drawer_cache.xml b/app/src/main/res/layout/drawer_cache.xml
new file mode 100644
index 00000000..608eb7e7
--- /dev/null
+++ b/app/src/main/res/layout/drawer_cache.xml
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 9efab0d9..0642c09c 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -13,10 +13,6 @@
android:id="@+id/action_proxy"
android:title="@string/proxy_set"
app:showAsAction="never" />
-
- SET_NOTIF_MEDIA
SET_NOTIF_STATUS
SET_FONT_SCALE
+ SET_FONT_SCALE_INT
SET_NOTIF_FOLLOW_FILTER
SET_NOTIF_ADD_FILTER
SET_NOTIF_MENTION_FILTER
@@ -1627,6 +1628,13 @@
Share Image
Tap here to refresh poll
Announcement ยท %1$s - %2$s
+ Delete cache
+ Messages in cache for Home
+ Messages in cache for other timelines
+ Messages stored in drafts
+ Built-in browser cache
+ Fiiles cache
+ File cache size
diff --git a/app/src/main/res/xml/pref_interface.xml b/app/src/main/res/xml/pref_interface.xml
index b1a0b8ae..9b78b0bb 100644
--- a/app/src/main/res/xml/pref_interface.xml
+++ b/app/src/main/res/xml/pref_interface.xml
@@ -34,6 +34,14 @@
app:summary="@string/set_enable_crash_report_indication"
app:title="@string/set_enable_crash_report" />
+
+