Refactoring

pull/214/head
M66B 1 year ago
parent 9f1bab8e19
commit 9569b0e28e

@ -566,7 +566,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
if (TextUtils.isEmpty(fname))
return uri;
File dir = Helper.ensureExists(getFilesDir(), "shared");
File dir = Helper.ensureExists(this, "shared");
File file = new File(dir, fname);
Log.i("Copying shared file to " + file);

@ -183,7 +183,7 @@ public class ActivityEML extends ActivityBase {
if (uri == null)
throw new FileNotFoundException();
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
File dir = Helper.ensureExists(context, "shared");
File file = new File(dir, "email.eml");
Helper.copy(context, uri, file);

@ -132,7 +132,7 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
if (certificate == null)
return null;
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
File dir = Helper.ensureExists(context, "shared");
String name = Helper.sanitizeFilename(certificate.email);
File file = new File(dir, name + ".pem");
Helper.writeText(file, certificate.getPem());

@ -4105,7 +4105,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
response.setMethod(Method.REPLY);
response.addEvent(ev);
File dir = Helper.ensureExists(context.getFilesDir(), "calendar");
File dir = Helper.ensureExists(context, "calendar");
File ics = new File(dir, message.id + ".ics");
response.write(ics);
@ -6389,7 +6389,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
File source = EntityMessage.getFile(context, id);
File dir = Helper.ensureExists(context.getFilesDir(), "shared");
File dir = Helper.ensureExists(context, "shared");
File target = new File(dir, id + ".html");
Helper.copy(source, target);

@ -186,7 +186,7 @@ public class CloudSync {
private static Long updateSyncdata(Context context) throws IOException, JSONException {
DB db = DB.getInstance(context);
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
File dir = Helper.ensureExists(context, "syncdata");
Long last = null;
@ -352,7 +352,7 @@ public class CloudSync {
private static void receiveRemoteData(Context context, String user, String password, long lrevision, long rrevision, JSONObject jstatus)
throws JSONException, GeneralSecurityException, IOException, InvalidCipherTextException {
DB db = DB.getInstance(context);
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
File dir = Helper.ensureExists(context, "syncdata");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cloud_receive = prefs.getBoolean("cloud_receive", false);

@ -357,7 +357,7 @@ public class ContactInfo {
final String domain = d.toLowerCase(Locale.ROOT);
File dir = Helper.ensureExists(context.getFilesDir(), "favicons");
File dir = Helper.ensureExists(context, "favicons");
try {
// check cache
@ -548,7 +548,7 @@ public class ContactInfo {
String tag = (TextUtils.isEmpty(info.email) ? name : info.email);
String etag = (TextUtils.isEmpty(info.email) ? Helper.sanitizeFilename(name + "@name") : ekey);
if (info.bitmap == null && generated && !TextUtils.isEmpty(tag)) {
File dir = Helper.ensureExists(context.getFilesDir(), "generated");
File dir = Helper.ensureExists(context, "generated");
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {

@ -172,7 +172,7 @@ public class EntityAttachment {
}
static File getFile(Context context, long id, String name) {
File dir = Helper.ensureExists(context.getFilesDir(), "attachments");
File dir = Helper.ensureExists(context, "attachments");
String filename = Long.toString(id);
if (!TextUtils.isEmpty(name))
filename += "." + Helper.sanitizeFilename(name);

@ -619,8 +619,9 @@ public class EntityMessage implements Serializable {
}
static File getFile(Context context, Long id) {
File root = Helper.ensureExists(context.getFilesDir(), "messages");
File dir = Helper.ensureExists(root, "D" + (id / 1000));
File root = Helper.ensureExists(context, "messages");
File dir = new File(root, "D" + (id / 1000));
dir.mkdir();
return new File(dir, id.toString());
}
@ -644,12 +645,12 @@ public class EntityMessage implements Serializable {
}
File getFile(Context context, int revision) {
File dir = Helper.ensureExists(context.getFilesDir(), "revision");
File dir = Helper.ensureExists(context, "revision");
return new File(dir, id + "." + revision);
}
File getRefFile(Context context) {
File dir = Helper.ensureExists(context.getFilesDir(), "references");
File dir = Helper.ensureExists(context, "references");
return new File(dir, id.toString());
}
@ -658,7 +659,7 @@ public class EntityMessage implements Serializable {
}
static File getRawFile(Context context, Long id) {
File dir = Helper.ensureExists(context.getFilesDir(), "raw");
File dir = Helper.ensureExists(context, "raw");
return new File(dir, id + ".eml");
}

@ -3562,7 +3562,7 @@ public class FragmentCompose extends FragmentBase {
});
snackbar.show();
} else {
File dir = Helper.ensureExists(context.getFilesDir(), "photo");
File dir = Helper.ensureExists(context, "photo");
File file = new File(dir, working + "_" + new Date().getTime() + ".jpg");
try {
photoURI = FileProviderEx.getUri(context, BuildConfig.APPLICATION_ID, file);
@ -3874,7 +3874,7 @@ public class FragmentCompose extends FragmentBase {
throw new IllegalArgumentException(context.getString(R.string.title_from_missing));
// Create files
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
File tmp = Helper.ensureExists(context, "encryption");
File input = new File(tmp, draft.id + "_" + session + ".pgp_input");
File output = new File(tmp, draft.id + "_" + session + ".pgp_output");
@ -4242,7 +4242,7 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean check_certificate = prefs.getBoolean("check_certificate", true);
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
File tmp = Helper.ensureExists(context, "encryption");
DB db = DB.getInstance(context);

@ -8828,7 +8828,7 @@ public class FragmentMessages extends FragmentBase
OutputStream out = null;
boolean inline = false;
File tmp = Helper.ensureExists(context.getFilesDir(), "encryption");
File tmp = Helper.ensureExists(context, "encryption");
File plain = new File(tmp, message.id + ".pgp_out");
// Find encrypted data

@ -1839,7 +1839,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
.remove("cloud_last_sync")
.apply();
File dir = Helper.ensureExists(context.getFilesDir(), "syncdata");
File dir = Helper.ensureExists(context, "syncdata");
File[] files = dir.listFiles();
if (files != null)
for (File file : files) {

@ -2641,11 +2641,9 @@ public class Helper {
private static final Map<File, Boolean> exists = new HashMap<>();
static File ensureExists(File parent, String subdir) {
parent.mkdir();
File dir = new File(parent, subdir);
Log.jni_safe_mkdirs(dir);
static File ensureExists(Context context, String subdir) {
File dir = new File(context.getFilesDir(), subdir);
dir.mkdirs();
synchronized (exists) {
if (exists.containsKey(dir))

@ -791,7 +791,7 @@ class ImageHelper {
@NonNull
static File getCacheFile(Context context, long id, String source, String extension) {
File dir = Helper.ensureExists(context.getFilesDir(), "images");
File dir = Helper.ensureExists(context, "images");
return new File(dir, id + "_" + Math.abs(source.hashCode()) + extension);
}

@ -1933,8 +1933,6 @@ public class Log {
db.endTransaction();
}
Log.jni_safe_mkdirs(new File(context.getFilesDir(), "testing"));
ServiceSynchronize.eval(context, "debuginfo");
return draft;

Loading…
Cancel
Save