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 e72a3c5c0..53f57823d 100644
--- a/app/src/main/java/app/fedilab/android/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/android/helper/Helper.java
@@ -59,6 +59,7 @@ import android.provider.MediaStore;
import android.provider.OpenableColumns;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.widget.SwitchCompat;
import androidx.browser.customtabs.CustomTabsIntent;
import com.google.android.material.navigation.NavigationView;
@@ -102,6 +103,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
+import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -3959,10 +3961,18 @@ public class Helper {
style = R.style.Dialog;
}
AlertDialog.Builder builder = new AlertDialog.Builder(contextReference.get(), style);
+ LayoutInflater inflater = ((MainActivity)contextReference.get()).getLayoutInflater();
+ View dialogView = inflater.inflate(R.layout.popup_cache, new LinearLayout((MainActivity)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 CheckBox cache_timeline = dialogView.findViewById(R.id.cache_timeline);
+ final CheckBox cache_owntoots = dialogView.findViewById(R.id.cache_owntoots);
+ final CheckBox cache_bookmarks = dialogView.findViewById(R.id.cache_bookmarks);
+ final SwitchCompat clean_all = dialogView.findViewById(R.id.clean_all);
final float finalCacheSize = cacheSize;
- builder.setMessage(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
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
@@ -3977,10 +3987,32 @@ public class Helper {
}
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StatusCacheDAO(contextReference.get(), db).removeDuplicate();
+ if( clean_all.isChecked()){
+ if( cache_timeline.isChecked()){
+ new TimelineCacheDAO(contextReference.get(), db).removeAll();
+ }
+ if( cache_owntoots.isChecked()){
+
+ }
+ if( cache_bookmarks.isChecked()){
+
+ }
+ }else{
+ if( cache_timeline.isChecked()){
+ new TimelineCacheDAO(contextReference.get(), db).removeAllConnected();
+ }
+ if( cache_owntoots.isChecked()){
+
+ }
+ if( cache_bookmarks.isChecked()){
+
+ }
+ }
+
/* Date date = new Date( System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
String dateString = Helper.dateToString(date);
new TimelineCacheDAO(contextReference.get(), db).removeAfterDate(dateString);*/
- new TimelineCacheDAO(contextReference.get(), db).removeAll();
+
} catch (Exception ignored) {
}
}
diff --git a/app/src/main/java/app/fedilab/android/sqlite/TimelineCacheDAO.java b/app/src/main/java/app/fedilab/android/sqlite/TimelineCacheDAO.java
index 1eb082a46..5beee6a39 100644
--- a/app/src/main/java/app/fedilab/android/sqlite/TimelineCacheDAO.java
+++ b/app/src/main/java/app/fedilab/android/sqlite/TimelineCacheDAO.java
@@ -113,11 +113,21 @@ public class TimelineCacheDAO {
* Remove stored status
* @return int
*/
- public int removeAll(){
- return db.delete(Sqlite.TABLE_TIMELINE_CACHE, null, null);
+ public int removeAllConnected(){
+ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
+ String instance = Helper.getLiveInstance(context);
+ return db.delete(Sqlite.TABLE_TIMELINE_CACHE, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null);
}
+ /***
+ * Remove stored status
+ * @return int
+ */
+ public int removeAll(){
+ return db.delete(Sqlite.TABLE_TIMELINE_CACHE, null, null);
+ }
//------- GETTERS -------
diff --git a/app/src/main/res/layout/popup_cache.xml b/app/src/main/res/layout/popup_cache.xml
new file mode 100644
index 000000000..eb98a6d81
--- /dev/null
+++ b/app/src/main/res/layout/popup_cache.xml
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 531a92134..3d25c7fb7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1178,4 +1178,10 @@
For joining my instance \"%1$s\", you can download Fedilab:\n\nF-Droid: %2$s\nGoogle: %3$s\n\nThen open the link below with Fedilab and create your account :)\n\n%4$s
Your poll can\'t have duplicated options!
+ For all accounts
+ Database cache
+ Clear your home timeline cache
+ Clear your cached statuses
+ Clear your bookmarks
+ Files in cache
\ No newline at end of file