Clear cache when leaving
This commit is contained in:
parent
95eb2b33ac
commit
3719acaa7f
|
@ -72,6 +72,8 @@ import android.widget.SeekBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -115,6 +117,7 @@ import app.fedilab.android.services.LiveNotificationService;
|
|||
import app.fedilab.android.services.StopLiveNotificationReceiver;
|
||||
import app.fedilab.android.sqlite.AccountDAO;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
import app.fedilab.android.sqlite.StatusCacheDAO;
|
||||
import app.fedilab.android.sqlite.TempMuteDAO;
|
||||
import app.fedilab.android.sqlite.TimelineCacheDAO;
|
||||
import app.fedilab.android.sqlite.TimelinesDAO;
|
||||
|
@ -140,6 +143,8 @@ import app.fedilab.android.interfaces.OnUpdateAccountInfoInterface;
|
|||
|
||||
import static app.fedilab.android.asynctasks.ManageFiltersAsyncTask.action.GET_ALL_FILTER;
|
||||
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
||||
import static app.fedilab.android.sqlite.StatusCacheDAO.ARCHIVE_CACHE;
|
||||
import static app.fedilab.android.sqlite.StatusCacheDAO.BOOKMARK_CACHE;
|
||||
|
||||
|
||||
public abstract class BaseMainActivity extends BaseActivity
|
||||
|
@ -1646,6 +1651,27 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
super.onDestroy();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
boolean backgroundProcess = sharedpreferences.getBoolean(Helper.SET_KEEP_BACKGROUND_PROCESS, true);
|
||||
boolean clearCacheExit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false);
|
||||
WeakReference<Context> contextReference = new WeakReference<>(getApplicationContext());
|
||||
if( clearCacheExit){
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String path = contextReference.get().getCacheDir().getParentFile().getPath();
|
||||
File dir = new File(path);
|
||||
if (dir.isDirectory()) {
|
||||
Helper.deleteDir(dir);
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new StatusCacheDAO(contextReference.get(), db).removeDuplicate();
|
||||
new TimelineCacheDAO(contextReference.get(), db).removeAll();
|
||||
new StatusCacheDAO(contextReference.get(), db).removeAll(ARCHIVE_CACHE);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!backgroundProcess)
|
||||
sendBroadcast(new Intent(getApplicationContext(), StopLiveNotificationReceiver.class));
|
||||
if( hidde_menu != null)
|
||||
|
|
|
@ -323,6 +323,19 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
boolean clear_cache_exit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false);
|
||||
final CheckBox set_clear_cache_exit = rootView.findViewById(R.id.set_clear_cache_exit);
|
||||
set_clear_cache_exit.setChecked(clear_cache_exit);
|
||||
set_clear_cache_exit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_CLEAR_CACHE_EXIT, set_clear_cache_exit.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
boolean auto_backup_notifications = sharedpreferences.getBoolean(Helper.SET_AUTO_BACKUP_NOTIFICATIONS+userId+instance, false);
|
||||
final CheckBox set_auto_backup_notifications = rootView.findViewById(R.id.set_auto_backup_notifications);
|
||||
set_auto_backup_notifications.setChecked(auto_backup_notifications);
|
||||
|
|
|
@ -356,6 +356,7 @@ public class Helper {
|
|||
public static final String SET_NOTIF_SOUND = "set_notif_sound";
|
||||
public static final String SET_ENABLE_TIME_SLOT = "set_enable_time_slot";
|
||||
public static final String SET_KEEP_BACKGROUND_PROCESS = "set_keep_background_process";
|
||||
public static final String SET_CLEAR_CACHE_EXIT = "set_clear_cache_exit";
|
||||
public static final String SET_DISPLAY_EMOJI = "set_display_emoji";
|
||||
public static final String SET_DISPLAY_CARD = "set_display_card";
|
||||
public static final String SET_DISPLAY_VIDEO_PREVIEWS= "set_display_video_previews";
|
||||
|
|
|
@ -1041,6 +1041,43 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:text="@string/action_cache"
|
||||
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:textSize="16sp"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||
android:layout_marginBottom="@dimen/settings_checkbox_margin"
|
||||
android:orientation="horizontal">
|
||||
<CheckBox
|
||||
android:id="@+id/set_clear_cache_exit"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:textSize="16sp"
|
||||
android:text="@string/set_clear_cache_exit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textColor="@color/mastodonC2"
|
||||
android:text="@string/set_clear_cache_exit_indication"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:text="@string/set_crash_reports"
|
||||
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||
|
|
|
@ -1202,4 +1202,6 @@
|
|||
<string name="top_notification_message">For %1$s accounts with %2$s events</string>
|
||||
<string name="set_allow_live_notifications">Live notifications for %1$s</string>
|
||||
<string name="set_allow_live_notifications_indication">Live notifications will be enabled for this account.</string>
|
||||
<string name="set_clear_cache_exit">Clear cache when leaving</string>
|
||||
<string name="set_clear_cache_exit_indication">The cache (media, cached messages, data from the built-in browser) will be automatically cleared when leaving the application.</string>
|
||||
</resources>
|
Loading…
Reference in New Issue