More suggested changes
app/src/main/java/eu/lepiller/nani/AboutActivity.java
4 | 4 | import android.net.Uri; | |
5 | 5 | import androidx.appcompat.app.AppCompatActivity; | |
6 | 6 | import android.os.Bundle; | |
7 | - | import android.view.View; | |
8 | 7 | import android.widget.Button; | |
9 | 8 | ||
10 | 9 | public class AboutActivity extends AppCompatActivity { |
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
2 | 2 | ||
3 | 3 | import android.content.Intent; | |
4 | 4 | import android.graphics.drawable.Drawable; | |
5 | - | import android.os.Build; | |
6 | 5 | ||
7 | 6 | import androidx.appcompat.app.AppCompatActivity; | |
8 | 7 | import androidx.core.content.res.ResourcesCompat; |
app/src/main/java/eu/lepiller/nani/HelpPitchActivity.java
5 | 5 | import android.content.Intent; | |
6 | 6 | import android.net.Uri; | |
7 | 7 | import android.os.Bundle; | |
8 | - | import android.view.View; | |
9 | 8 | import android.widget.Button; | |
10 | 9 | ||
11 | 10 | public class HelpPitchActivity extends AppCompatActivity { |
app/src/main/java/eu/lepiller/nani/ResultPagerAdapter.java
1 | 1 | package eu.lepiller.nani; | |
2 | 2 | ||
3 | 3 | import android.annotation.SuppressLint; | |
4 | - | import android.app.NotificationManager; | |
5 | 4 | import android.content.Context; | |
6 | 5 | import android.content.Intent; | |
7 | 6 | import android.text.Html; |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
25 | 25 | import eu.lepiller.nani.result.Result; | |
26 | 26 | ||
27 | 27 | public class DictionaryFactory { | |
28 | - | private static DictionaryFactory instance; | |
28 | + | private static boolean initialized = false; | |
29 | + | ||
29 | 30 | private static ArrayList<Dictionary> dictionaries; | |
30 | 31 | private static File cacheDir; | |
31 | 32 | private static File listFile; | |
… | |||
36 | 37 | private static final int LIST_PARSER_DESCRIPTION = 2; | |
37 | 38 | private static final String TAG = "FACTORY"; | |
38 | 39 | ||
39 | - | private DictionaryFactory(Context context) { | |
40 | + | private DictionaryFactory() {} | |
41 | + | ||
42 | + | private static void initialize(Context context) { | |
40 | 43 | cacheDir = context.getCacheDir(); | |
41 | 44 | listFile = new File(cacheDir + "/list"); | |
42 | 45 | languages = new ArrayList<>(); | |
… | |||
57 | 60 | languages.add("en"); | |
58 | 61 | Log.d(TAG, languages.toString()); | |
59 | 62 | updatePackageList(); | |
63 | + | ||
64 | + | initialized = true; | |
60 | 65 | } | |
61 | 66 | ||
62 | 67 | private static String chooseLanguage(Map<String, StringBuilder> data) { | |
… | |||
219 | 224 | } | |
220 | 225 | ||
221 | 226 | public static void prepare(Context context) { | |
222 | - | if(instance == null) | |
223 | - | instance = new DictionaryFactory(context); | |
227 | + | if(!initialized) | |
228 | + | initialize(context); | |
224 | 229 | } | |
225 | 230 | ||
226 | 231 | public static Dictionary getByName(Context context, String name) { | |
… | |||
235 | 240 | } | |
236 | 241 | ||
237 | 242 | public static ArrayList<Result> search(String text) throws DictionaryException { | |
238 | - | if(instance == null) | |
243 | + | if(!initialized) | |
239 | 244 | throw new NoDictionaryException(); | |
240 | 245 | ||
241 | 246 | int available = 0; | |
… | |||
273 | 278 | } | |
274 | 279 | ||
275 | 280 | public static KanjiResult searchKanji(String kanji) throws DictionaryException { | |
276 | - | if(instance == null) | |
281 | + | if(!initialized) | |
277 | 282 | throw new NoDictionaryException(); | |
278 | 283 | ||
279 | 284 | Stack<KanjiResult> results = new Stack<>(); | |
… | |||
314 | 319 | } | |
315 | 320 | ||
316 | 321 | public static ArrayList<Dictionary> getDictionaries(Context context) { | |
317 | - | if(instance == null) | |
318 | - | instance = new DictionaryFactory(context); | |
322 | + | if(!initialized) | |
323 | + | initialize(context); | |
319 | 324 | ||
320 | 325 | return dictionaries; | |
321 | 326 | } | |
322 | 327 | ||
323 | 328 | public static ArrayList<Dictionary> getDictionaries(Context context, String langFilter) { | |
324 | - | if(instance == null) | |
325 | - | instance = new DictionaryFactory(context); | |
329 | + | if(!initialized) | |
330 | + | initialize(context); | |
326 | 331 | ||
327 | 332 | if(langFilter.compareTo("") == 0) | |
328 | 333 | return dictionaries; | |
… | |||
336 | 341 | } | |
337 | 342 | ||
338 | 343 | public static RadicalDict getRadicalDictionary(Context context) throws NoDictionaryException { | |
339 | - | if(instance == null) | |
340 | - | instance = new DictionaryFactory(context); | |
344 | + | if(!initialized) | |
345 | + | initialize(context); | |
341 | 346 | ||
342 | 347 | for(Dictionary d: dictionaries) { | |
343 | 348 | if(d.isDownloaded() && d instanceof RadicalDict) { |
app/src/main/java/eu/lepiller/nani/result/Result.java
158 | 158 | MojiConverter converter = new MojiConverter(); | |
159 | 159 | for(int i=0; i<txt.length(); i++) { | |
160 | 160 | Character.UnicodeBlock b2 = Character.UnicodeBlock.of(txt.charAt(i)); | |
161 | - | if(b == b2) { | |
162 | - | // if the headwork contains katakana, convert it to hiragana to match pronunciation | |
163 | - | // better. | |
164 | - | current.append(txt.charAt(i)); | |
165 | - | } else { | |
161 | + | if(b != b2) { | |
166 | 162 | String s = current.toString(); | |
167 | 163 | if(!s.isEmpty()) | |
168 | 164 | portions.add(s); | |
169 | 165 | current = new StringBuilder(); | |
170 | - | current.append(txt.charAt(i)); | |
171 | 166 | } | |
167 | + | current.append(txt.charAt(i)); | |
172 | 168 | ||
173 | 169 | b = b2; | |
174 | 170 | } | |
… | |||
260 | 256 | // merge senses | |
261 | 257 | senses.addAll(other.senses); | |
262 | 258 | } | |
263 | - | ||
264 | - | public void addPitch(String kanji, String pitch) { | |
265 | - | for(Reading r: readings) { | |
266 | - | if(r.kanjis == null || r.kanjis.size() == 0 || contains(r.kanjis, kanji)) { | |
267 | - | r.addPitch(pitch); | |
268 | - | } | |
269 | - | } | |
270 | - | } | |
271 | - | ||
272 | - | private boolean contains(ArrayList<String> l, String s) { | |
273 | - | for(String c: l) { | |
274 | - | if(c.compareTo(s) == 0) | |
275 | - | return true; | |
276 | - | } | |
277 | - | return false; | |
278 | - | } | |
279 | 259 | } |