mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 15:46:34 +02:00
Added experimental external files support
This commit is contained in:
@@ -39,7 +39,6 @@ import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.TypefaceSpan;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -134,6 +133,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
private Button btnRepair;
|
||||
private SwitchCompat swAutostart;
|
||||
private SwitchCompat swExternalStorage;
|
||||
private TextView tvRoomQueryThreads;
|
||||
private SeekBar sbRoomQueryThreads;
|
||||
private ImageButton ibRoom;
|
||||
@@ -190,6 +190,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
"updates", "weekly", "show_changelog",
|
||||
"experiments", "crash_reports", "cleanup_attachments",
|
||||
"protocol", "debug", "log_level", "test1", "test2", "test3", "test4", "test5",
|
||||
// "external_storage",
|
||||
"query_threads", "wal", "checkpoints", "sqlite_cache",
|
||||
"chunk_size", "undo_manager", "webview_legacy",
|
||||
"use_modseq", "uid_command", "perform_expunge", "uid_expunge",
|
||||
@@ -280,6 +281,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
btnRepair = view.findViewById(R.id.btnRepair);
|
||||
swAutostart = view.findViewById(R.id.swAutostart);
|
||||
swExternalStorage = view.findViewById(R.id.swExternalStorage);
|
||||
tvRoomQueryThreads = view.findViewById(R.id.tvRoomQueryThreads);
|
||||
sbRoomQueryThreads = view.findViewById(R.id.sbRoomQueryThreads);
|
||||
ibRoom = view.findViewById(R.id.ibRoom);
|
||||
@@ -776,6 +778,50 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
}
|
||||
});
|
||||
|
||||
swExternalStorage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
prefs.edit().putBoolean("external_storage", isChecked).apply();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean("external_storage", isChecked);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) throws IOException {
|
||||
boolean external_storage = args.getBoolean("external_storage");
|
||||
|
||||
File source = (!external_storage
|
||||
? context.getExternalFilesDir(null)
|
||||
: context.getFilesDir());
|
||||
|
||||
File target = (external_storage
|
||||
? context.getExternalFilesDir(null)
|
||||
: context.getFilesDir());
|
||||
|
||||
source = new File(source, "attachments");
|
||||
target = new File(target, "attachments");
|
||||
|
||||
File[] attachments = source.listFiles();
|
||||
if (attachments != null)
|
||||
for (File attachment : attachments) {
|
||||
File dest = new File(target, attachment.getName());
|
||||
Log.i("Move " + attachment + " to " + dest);
|
||||
Helper.copy(attachment, dest);
|
||||
attachment.delete();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, args, "external");
|
||||
}
|
||||
});
|
||||
|
||||
sbRoomQueryThreads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
@@ -1125,6 +1171,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
files.addAll(getFiles(context.getCacheDir(), MIN_FILE_SIZE));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
files.addAll(getFiles(context.getDataDir(), MIN_FILE_SIZE));
|
||||
files.addAll(getFiles(context.getExternalFilesDir(null), MIN_FILE_SIZE));
|
||||
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
@Override
|
||||
@@ -1158,6 +1205,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
? null : context.getDataDir());
|
||||
File filesDir = context.getFilesDir();
|
||||
File cacheDir = context.getCacheDir();
|
||||
File externalDir = context.getExternalFilesDir(null);
|
||||
|
||||
if (dataDir != null)
|
||||
ssb.append("Data: ").append(dataDir.getAbsolutePath()).append("\r\n");
|
||||
@@ -1165,6 +1213,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
ssb.append("Files: ").append(filesDir.getAbsolutePath()).append("\r\n");
|
||||
if (cacheDir != null)
|
||||
ssb.append("Cache: ").append(cacheDir.getAbsolutePath()).append("\r\n");
|
||||
if (externalDir != null)
|
||||
ssb.append("External: ").append(externalDir.getAbsolutePath()).append("\r\n");
|
||||
ssb.append("\r\n");
|
||||
|
||||
for (File file : files) {
|
||||
@@ -1432,6 +1482,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
swTest5.setChecked(prefs.getBoolean("test5", false));
|
||||
|
||||
swAutostart.setChecked(Helper.isComponentEnabled(getContext(), ReceiverAutoStart.class));
|
||||
swExternalStorage.setChecked(prefs.getBoolean("external_storage", false));
|
||||
|
||||
int query_threads = prefs.getInt("query_threads", DB.DEFAULT_QUERY_THREADS);
|
||||
tvRoomQueryThreads.setText(getString(R.string.title_advanced_room_query_threads, NF.format(query_threads)));
|
||||
|
||||
Reference in New Issue
Block a user