mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-04 11:54:10 +01:00
Added setting to delete old attachments
This commit is contained in:
@@ -97,6 +97,17 @@ public interface DaoAttachment {
|
||||
" WHERE id = :id")
|
||||
void setCid(long id, String cid);
|
||||
|
||||
@Query("UPDATE attachment" +
|
||||
" SET available = 0" +
|
||||
" WHERE EXISTS" +
|
||||
" (SELECT * FROM attachment a" +
|
||||
" JOIN message ON message.id = a.message" +
|
||||
" JOIN folder ON folder.id = message.folder" +
|
||||
" WHERE a.id = attachment.id" +
|
||||
" AND a.available" +
|
||||
" AND message.stored < :now - folder.sync_days * 24 * 3600 * 1000)")
|
||||
int purge(long now);
|
||||
|
||||
@Insert
|
||||
long insertAttachment(EntityAttachment attachment);
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private TextView tvUuid;
|
||||
private SwitchCompat swDebug;
|
||||
private Button btnReset;
|
||||
private SwitchCompat swCleanupAttachments;
|
||||
private Button btnCleanup;
|
||||
private TextView tvLastCleanup;
|
||||
private Button btnMore;
|
||||
@@ -84,7 +85,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private Group grpDebug;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"shortcuts", "fts", "english", "watchdog", "auto_optimize", "updates", "experiments", "crash_reports", "debug"
|
||||
"shortcuts", "fts", "english", "watchdog", "auto_optimize", "updates",
|
||||
"experiments", "crash_reports", "debug", "cleanup_attachments"
|
||||
};
|
||||
|
||||
private final static String[] RESET_QUESTIONS = new String[]{
|
||||
@@ -122,6 +124,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
tvUuid = view.findViewById(R.id.tvUuid);
|
||||
swDebug = view.findViewById(R.id.swDebug);
|
||||
btnReset = view.findViewById(R.id.btnReset);
|
||||
swCleanupAttachments = view.findViewById(R.id.swCleanupAttachments);
|
||||
btnCleanup = view.findViewById(R.id.btnCleanup);
|
||||
tvLastCleanup = view.findViewById(R.id.tvLastCleanup);
|
||||
btnMore = view.findViewById(R.id.btnMore);
|
||||
@@ -272,6 +275,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
}
|
||||
});
|
||||
|
||||
swCleanupAttachments.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("cleanup_attachments", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
btnCleanup.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -447,6 +457,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
|
||||
tvUuid.setText(prefs.getString("uuid", null));
|
||||
swDebug.setChecked(prefs.getBoolean("debug", false));
|
||||
swCleanupAttachments.setChecked(prefs.getBoolean("cleanup_attachments", false));
|
||||
|
||||
tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));
|
||||
|
||||
|
||||
@@ -68,8 +68,11 @@ public class WorkerCleanup extends Worker {
|
||||
}
|
||||
|
||||
static void cleanup(Context context, boolean manual) {
|
||||
DB db = DB.getInstance(context);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean fts = prefs.getBoolean("fts", true);
|
||||
boolean cleanup_attachments = prefs.getBoolean("cleanup_attachments", false);
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
Log.i("Start cleanup manual=" + manual);
|
||||
|
||||
@@ -88,6 +91,11 @@ public class WorkerCleanup extends Worker {
|
||||
}
|
||||
}
|
||||
|
||||
if (cleanup_attachments) {
|
||||
int purged = db.attachment().purge(new Date().getTime());
|
||||
Log.i("Attachments purged=" + purged);
|
||||
}
|
||||
|
||||
// Check attachments files
|
||||
Log.i("Checking attachments files");
|
||||
List<Long> aids = db.attachment().getAttachmentAvailable();
|
||||
@@ -195,7 +203,6 @@ public class WorkerCleanup extends Worker {
|
||||
}
|
||||
}
|
||||
|
||||
boolean fts = prefs.getBoolean("fts", true);
|
||||
Log.i("Cleanup FTS=" + fts);
|
||||
if (fts) {
|
||||
int deleted = 0;
|
||||
|
||||
@@ -267,6 +267,29 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDebugHint" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swCleanupAttachments"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_cleanup_attachments"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnReset"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvCleanupAttachmentsHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:text="@string/title_advanced_cleanup_attachments_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swCleanupAttachments" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCleanup"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
@@ -275,7 +298,7 @@
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_cleanup"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnReset" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCleanupAttachmentsHint" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvCleanupHint"
|
||||
|
||||
@@ -445,6 +445,7 @@
|
||||
<string name="title_advanced_experiments">Try experimental features</string>
|
||||
<string name="title_advanced_crash_reports">Send error reports</string>
|
||||
<string name="title_advanced_debug">Debug mode</string>
|
||||
<string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string>
|
||||
<string name="title_advanced_cleanup">Cleanup</string>
|
||||
<string name="title_advanced_last_cleanup">Last cleanup: %1$s</string>
|
||||
<string name="title_advanced_more">More options</string>
|
||||
@@ -521,6 +522,7 @@
|
||||
<string name="title_advanced_optimize_hint">Enabling this can automatically change the receive settings to reduce battery usage</string>
|
||||
<string name="title_advanced_experiments_hint">List of current experimental features</string>
|
||||
<string name="title_advanced_debug_hint">Enable extra logging and show debug information at various places</string>
|
||||
<string name="title_advanced_cleanup_attachments_hint">This will remove attachments from messages that are no longer synchronized</string>
|
||||
<string name="title_advanced_cleanup_hint">This will delete all temporary files</string>
|
||||
|
||||
<string name="title_advanced_never_favorite">Never favorite</string>
|
||||
|
||||
Reference in New Issue
Block a user