mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 06:38:29 +02:00
Bring back external attachment storage
This commit is contained in:
@@ -22,10 +22,12 @@ package eu.faircode.email;
|
||||
import static androidx.room.ForeignKey.CASCADE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
import androidx.room.Ignore;
|
||||
@@ -170,7 +172,7 @@ public class EntityAttachment {
|
||||
}
|
||||
|
||||
static File getFile(Context context, long id, String name) {
|
||||
File dir = Helper.ensureExists(context, "attachments");
|
||||
File dir = getRoot(context);
|
||||
String filename = Long.toString(id);
|
||||
if (!TextUtils.isEmpty(name))
|
||||
filename += "." + Helper.sanitizeFilename(name);
|
||||
@@ -179,6 +181,19 @@ public class EntityAttachment {
|
||||
return new File(dir, filename);
|
||||
}
|
||||
|
||||
static File getRoot(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean external_storage = prefs.getBoolean("external_storage", false);
|
||||
|
||||
if (external_storage) {
|
||||
File dir = Helper.getExternalFilesDir(context);
|
||||
dir.mkdirs();
|
||||
return dir;
|
||||
}
|
||||
|
||||
return Helper.ensureExists(context, "attachments");
|
||||
}
|
||||
|
||||
static void copy(Context context, long oldid, long newid) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user