]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Select app-specific storage by default.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 14 Feb 2016 16:09:49 +0000 (17:09 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 14 Feb 2016 16:09:49 +0000 (17:09 +0100)
Should avoid issues with "cleanup" apps deleting
the dictionaries.
Use the old default if there are issues with that
though, or if there are still dictionaries around.

src/com/hughes/android/dictionary/DictionaryApplication.java

index 61fd524ef6ada1c729a087779a4911545f571406..3c351d9da35eb12fa31a999cca6d78aec931a6f8 100644 (file)
@@ -402,14 +402,33 @@ public class DictionaryApplication extends Application {
         });
     }
 
+    private String selectDefaultDir() {
+        final File defaultDictDir = new File(Environment.getExternalStorageDirectory(), "quickDic");
+        String dir = defaultDictDir.getAbsolutePath();
+        File dictDir = new File(dir);
+        if (dictDir.isDirectory() && dictDir.list().length > 0) {
+            return dir;
+        }
+        File efd = getApplicationContext().getExternalFilesDir(null);
+        if (efd != null) {
+            efd.mkdirs();
+            if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                getApplicationContext().getExternalFilesDirs(null);
+            }
+            if (efd.isDirectory() && efd.canWrite() && checkFileCreate(efd)) {
+                return efd.getAbsolutePath();
+            }
+        }
+        return dir;
+    }
+
     public synchronized File getDictDir() {
         // This metaphor doesn't work, because we've already reset
         // prefsMightHaveChanged.
         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
         String dir = prefs.getString(getString(R.string.quickdicDirectoryKey), "");
         if (dir.isEmpty()) {
-            final File defaultDictDir = new File(Environment.getExternalStorageDirectory(), "quickDic");
-            dir = defaultDictDir.getAbsolutePath();
+            dir = selectDefaultDir();
         }
         dictDir = new File(dir);
         dictDir.mkdirs();