mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 14:41:08 +00:00
Added experimental external files support
This commit is contained in:
parent
6ad4276ea1
commit
826c67700e
5 changed files with 78 additions and 3 deletions
|
@ -22,9 +22,11 @@ package eu.faircode.email;
|
|||
import static androidx.room.ForeignKey.CASCADE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
import androidx.room.Index;
|
||||
|
@ -112,7 +114,14 @@ public class EntityAttachment {
|
|||
}
|
||||
|
||||
static File getFile(Context context, long id, String name) {
|
||||
File dir = new File(context.getFilesDir(), "attachments");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean external_storage = prefs.getBoolean("external_storage", false);
|
||||
|
||||
File root = (external_storage
|
||||
? context.getExternalFilesDir(null)
|
||||
: context.getFilesDir());
|
||||
|
||||
File dir = new File(root, "attachments");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
String filename = Long.toString(id);
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -702,6 +702,17 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/btnRepair"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swExternalStorage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_external_storage"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swAutostart"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvRoomQueryThreads"
|
||||
android:layout_width="0dp"
|
||||
|
@ -712,7 +723,7 @@
|
|||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swAutostart" />
|
||||
app:layout_constraintTop_toBottomOf="@id/swExternalStorage" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/sbRoomQueryThreads"
|
||||
|
|
|
@ -686,6 +686,7 @@
|
|||
<string name="title_advanced_test5" translatable="false">Test #5</string>
|
||||
<string name="title_advanced_repair" translatable="false">Repair</string>
|
||||
<string name="title_advanced_autostart" translatable="false">Autostart</string>
|
||||
<string name="title_advanced_external_storage" translatable="false">External storage</string>
|
||||
<string name="title_advanced_room_query_threads" translatable="false">ROOM query threads: %1$s</string>
|
||||
<string name="title_advanced_wal" translatable="false">WAL</string>
|
||||
<string name="title_advanced_checkpoints" translatable="false">Checkpoints</string>
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<files-path
|
||||
name="attachments"
|
||||
path="attachments" />
|
||||
<external-files-path
|
||||
name="external"
|
||||
path="attachments" />
|
||||
<files-path
|
||||
name="raw"
|
||||
path="raw" />
|
||||
|
|
Loading…
Reference in a new issue