Improve cache
This commit is contained in:
parent
77bb2cfa01
commit
694ebc19ee
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 -------
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 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 <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="10dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1"
|
||||
android:background="?colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/file_cache"
|
||||
android:textColor="?colorAccent"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1"
|
||||
android:background="?colorAccent" />
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:id="@+id/message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1"
|
||||
android:background="?colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/database_cache"
|
||||
android:textColor="?colorAccent"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1"
|
||||
android:background="?colorAccent" />
|
||||
<CheckBox
|
||||
android:id="@+id/cache_timeline"
|
||||
android:text="@string/cache_timeline_clear"
|
||||
style="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp" />
|
||||
<CheckBox
|
||||
android:id="@+id/cache_owntoots"
|
||||
android:text="@string/cache_owntoots_clear"
|
||||
style="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp" />
|
||||
<CheckBox
|
||||
android:id="@+id/cache_bookmarks"
|
||||
style="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/cache_bookmarks_clear"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/all_accounts"/>
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/clean_all"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1178,4 +1178,10 @@
|
|||
<string name="join_instance">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
|
||||
</string>
|
||||
<string name="poll_duplicated_entry">Your poll can\'t have duplicated options!</string>
|
||||
<string name="all_accounts">For all accounts</string>
|
||||
<string name="database_cache">Database cache</string>
|
||||
<string name="cache_timeline_clear">Clear your home timeline cache</string>
|
||||
<string name="cache_owntoots_clear">Clear your cached statuses</string>
|
||||
<string name="cache_bookmarks_clear">Clear your bookmarks</string>
|
||||
<string name="file_cache">Files in cache</string>
|
||||
</resources>
|
Loading…
Reference in New Issue