Put dictionaries in app data, not cache
app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java
32 | 32 | ||
33 | 33 | private Drawable drawable, newDrawable; | |
34 | 34 | ||
35 | - | Dictionary(String name, String description, String fullDescription, File cacheDir, int fileSize, int entries, String hash, String lang) { | |
35 | + | Dictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, int fileSize, int entries, String hash, String lang) { | |
36 | 36 | this.name = name; | |
37 | 37 | this.description = description; | |
38 | 38 | this.fullDescription = fullDescription; | |
… | |||
40 | 40 | expectedFileSize = fileSize; | |
41 | 41 | sha256 = hash; | |
42 | 42 | this.lang = lang; | |
43 | - | this.file = new File(cacheDir, "/dico/" + name); | |
44 | - | this.temporaryFile = new File(cacheDir, "/tmp/" + name); | |
43 | + | this.file = new File(dataDir, "/dico/" + name); | |
44 | + | this.temporaryFile = new File(cacheDir, "/dico/" + name); | |
45 | 45 | } | |
46 | 46 | ||
47 | 47 | public String getName() { |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
31 | 31 | private static boolean initialized = false; | |
32 | 32 | ||
33 | 33 | private static ArrayList<Dictionary> dictionaries; | |
34 | - | private static File cacheDir; | |
34 | + | private static File cacheDir, dataDir; | |
35 | 35 | private static File listFile; | |
36 | 36 | private static List<String> languages; | |
37 | 37 | ||
… | |||
44 | 44 | ||
45 | 45 | private static void initialize(Context context) { | |
46 | 46 | cacheDir = context.getCacheDir(); | |
47 | - | listFile = new File(cacheDir + "/list"); | |
47 | + | dataDir = context.getFilesDir(); | |
48 | + | listFile = new File(dataDir + "/list"); | |
48 | 49 | languages = new ArrayList<>(); | |
49 | 50 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
50 | 51 | LocaleList l = context.getResources().getConfiguration().getLocales(); | |
… | |||
118 | 119 | d = new RadicalDict(name, | |
119 | 120 | chooseLanguage(synopsis), | |
120 | 121 | chooseLanguage(description), | |
121 | - | cacheDir, url, size, entries, sha256, lang); | |
122 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
122 | 123 | Log.d("FACTORY", "radk: " + (d.isDownloaded()? "downloaded": "not downloaded")); | |
123 | 124 | } else if (type.compareTo("jmdict") == 0) { | |
124 | 125 | d = new JMDict(name, | |
125 | 126 | chooseLanguage(synopsis), | |
126 | 127 | chooseLanguage(description), | |
127 | - | cacheDir, url, size, entries, sha256, lang); | |
128 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
128 | 129 | } else if (type.compareTo("wadoku") == 0) { | |
129 | 130 | d = new WadokuResultDictionary(name, | |
130 | 131 | chooseLanguage(synopsis), | |
131 | 132 | chooseLanguage(description), | |
132 | - | cacheDir, url, size, entries, sha256, lang); | |
133 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
133 | 134 | } else if (type.compareTo("jibiki") == 0) { | |
134 | 135 | d = new Jibiki(name, | |
135 | 136 | chooseLanguage(synopsis), | |
136 | 137 | chooseLanguage(description), | |
137 | - | cacheDir, url, size, entries, sha256, lang); | |
138 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
138 | 139 | } else if (type.compareTo("wadoku_pitch") == 0) { | |
139 | 140 | d = new WadokuPitchDictionary(name, | |
140 | 141 | chooseLanguage(synopsis), | |
141 | 142 | chooseLanguage(description), | |
142 | - | cacheDir, url, size, entries, sha256, lang); | |
143 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
143 | 144 | } else if (type.compareTo("kanjidic") == 0) { | |
144 | 145 | d = new KanjiDict(name, | |
145 | 146 | chooseLanguage(synopsis), | |
146 | 147 | chooseLanguage(description), | |
147 | - | cacheDir, url, size, entries, sha256, lang); | |
148 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
148 | 149 | } else if (type.compareTo("ksvg") == 0) { | |
149 | 150 | d = new KanjiVG(name, | |
150 | 151 | chooseLanguage(synopsis), | |
151 | 152 | chooseLanguage(description), | |
152 | - | cacheDir, url, size, entries, sha256, lang); | |
153 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
153 | 154 | } else if (type.compareTo("tatoeba") == 0) { | |
154 | 155 | d = new TatoebaDictionary(name, | |
155 | 156 | chooseLanguage(synopsis), | |
156 | 157 | chooseLanguage(description), | |
157 | - | cacheDir, url, size, entries, sha256, lang); | |
158 | + | cacheDir, dataDir, url, size, entries, sha256, lang); | |
158 | 159 | } | |
159 | 160 | ||
160 | 161 | if(d != null) { |
app/src/main/java/eu/lepiller/nani/dictionary/ExampleDictionary.java
7 | 7 | import eu.lepiller.nani.result.KanjiResult; | |
8 | 8 | ||
9 | 9 | public abstract class ExampleDictionary extends FileDictionary { | |
10 | - | ExampleDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
11 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
10 | + | ExampleDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
11 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
12 | 12 | } | |
13 | 13 | ||
14 | 14 | abstract List<ExampleResult> search(final String word) throws IncompatibleFormatException; |
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
73 | 73 | private final String mUrl; | |
74 | 74 | private final static String TAG = "FileDictionary"; | |
75 | 75 | ||
76 | - | FileDictionary(String name, String description, String fullDescription, File cacheDir, String url, | |
76 | + | FileDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, | |
77 | 77 | int fileSize, int entries, String hash, String lang) { | |
78 | - | super(name, description, fullDescription, cacheDir, fileSize, entries, hash, lang); | |
78 | + | super(name, description, fullDescription, cacheDir, dataDir, fileSize, entries, hash, lang); | |
79 | 79 | mUrl = url; | |
80 | 80 | } | |
81 | 81 |
app/src/main/java/eu/lepiller/nani/dictionary/JMDict.java
5 | 5 | import eu.lepiller.nani.R; | |
6 | 6 | ||
7 | 7 | public class JMDict extends ResultDictionary { | |
8 | - | JMDict(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
8 | + | JMDict(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
10 | 10 | } | |
11 | 11 | ||
12 | 12 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/Jibiki.java
5 | 5 | import eu.lepiller.nani.R; | |
6 | 6 | ||
7 | 7 | public class Jibiki extends ResultDictionary { | |
8 | - | Jibiki(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
8 | + | Jibiki(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
10 | 10 | } | |
11 | 11 | ||
12 | 12 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/KanjiDict.java
17 | 17 | final private static String TAG = "KANJIDIC"; | |
18 | 18 | private Huffman readingHuffman, meaningHuffman; | |
19 | 19 | ||
20 | - | KanjiDict(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
21 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
20 | + | KanjiDict(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
21 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
22 | 22 | } | |
23 | 23 | ||
24 | 24 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/KanjiDictionary.java
5 | 5 | import eu.lepiller.nani.result.KanjiResult; | |
6 | 6 | ||
7 | 7 | public abstract class KanjiDictionary extends FileDictionary { | |
8 | - | KanjiDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
8 | + | KanjiDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
10 | 10 | } | |
11 | 11 | ||
12 | 12 | abstract KanjiResult search(final String kanji) throws IncompatibleFormatException; |
app/src/main/java/eu/lepiller/nani/dictionary/KanjiVG.java
19 | 19 | final private static String TAG = "KANJIVG"; | |
20 | 20 | private Huffman commandHuffman; | |
21 | 21 | ||
22 | - | KanjiVG(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
23 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
22 | + | KanjiVG(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
23 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
24 | 24 | } | |
25 | 25 | ||
26 | 26 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/RadicalDict.java
95 | 95 | } | |
96 | 96 | } | |
97 | 97 | ||
98 | - | RadicalDict(String name, String description, String fullDescription, File cacheDir, String url, | |
98 | + | RadicalDict(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, | |
99 | 99 | int fileSize, int entries, String hash, String lang) { | |
100 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
100 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
101 | 101 | } | |
102 | 102 | ||
103 | 103 | private static boolean contains(List<String> lst, String s) { |
app/src/main/java/eu/lepiller/nani/dictionary/ResultAugmenterDictionary.java
5 | 5 | import eu.lepiller.nani.result.Result; | |
6 | 6 | ||
7 | 7 | public abstract class ResultAugmenterDictionary extends FileDictionary { | |
8 | - | ResultAugmenterDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
8 | + | ResultAugmenterDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
10 | 10 | } | |
11 | 11 | ||
12 | 12 | void augment(Result r) throws IncompatibleFormatException { |
app/src/main/java/eu/lepiller/nani/dictionary/ResultDictionary.java
17 | 17 | final private static String TAG = "JMDICT"; | |
18 | 18 | private Huffman kanjiHuffman, readingHuffman, meaningHuffman; | |
19 | 19 | ||
20 | - | ResultDictionary(String name, String description, String fullDescription, File cacheDir, String url, | |
20 | + | ResultDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, | |
21 | 21 | int fileSize, int entries, String hash, String lang) { | |
22 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
22 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/TatoebaDictionary.java
18 | 18 | final private static String TAG = "TATOEBA"; | |
19 | 19 | private Huffman japaneseHuffman, translationHuffman; | |
20 | 20 | ||
21 | - | TatoebaDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
22 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
21 | + | TatoebaDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
22 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/WadokuPitchDictionary.java
18 | 18 | private Huffman huffman = null; | |
19 | 19 | private long triePos; | |
20 | 20 | ||
21 | - | WadokuPitchDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
22 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
21 | + | WadokuPitchDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
22 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | @Override |
app/src/main/java/eu/lepiller/nani/dictionary/WadokuResultDictionary.java
5 | 5 | import eu.lepiller.nani.R; | |
6 | 6 | ||
7 | 7 | public class WadokuResultDictionary extends ResultDictionary { | |
8 | - | WadokuResultDictionary(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | - | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash, lang); | |
8 | + | WadokuResultDictionary(String name, String description, String fullDescription, File cacheDir, File dataDir, String url, int fileSize, int entries, String hash, String lang) { | |
9 | + | super(name, description, fullDescription, cacheDir, dataDir, url, fileSize, entries, hash, lang); | |
10 | 10 | } | |
11 | 11 | ||
12 | 12 | @Override |