Properly notify changes to dictionary list
app/src/main/java/eu/lepiller/nani/DictionaryActivity.java
| 29 | 29 | public class DictionaryActivity extends AppCompatActivity { | |
| 30 | 30 | static final int DICO_REQUEST = 1; | |
| 31 | 31 | DictionariesAdapter adapter; | |
| 32 | + | ArrayList<Dictionary> dictionaries; | |
| 32 | 33 | ||
| 33 | 34 | @Override | |
| 34 | 35 | protected void onCreate(Bundle savedInstanceState) { | |
… | |||
| 41 | 42 | final ListView list_view = findViewById(R.id.dictionary_view); | |
| 42 | 43 | final SwipeRefreshLayout refresher = findViewById(R.id.dictionary_refresh_layout); | |
| 43 | 44 | ||
| 44 | - | final ArrayList<Dictionary> dictionaries = DictionaryFactory.getDictionnaries(getApplicationContext()); | |
| 45 | + | dictionaries = DictionaryFactory.getDictionnaries(getApplicationContext()); | |
| 45 | 46 | adapter = new DictionariesAdapter(getApplicationContext(), dictionaries); | |
| 46 | 47 | list_view.setAdapter(adapter); | |
| 47 | 48 | ||
… | |||
| 113 | 114 | super.onPostExecute(i); | |
| 114 | 115 | refresher.setRefreshing(false); | |
| 115 | 116 | DictionaryFactory.updatePackageList(); | |
| 117 | + | dictionaries.clear(); | |
| 118 | + | dictionaries.addAll(DictionaryFactory.getDictionnaries(getApplicationContext())); | |
| 116 | 119 | adapter.notifyDataSetChanged(); | |
| 117 | 120 | if(i == null) | |
| 118 | 121 | return; | |
app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java
| 54 | 54 | description_view.setText(dictionary.getDescription()); | |
| 55 | 55 | if(!dictionary.isUpToDate()) | |
| 56 | 56 | convertView.setBackgroundColor(context.getResources().getColor(R.color.colorUpdate)); | |
| 57 | + | else | |
| 58 | + | convertView.setBackgroundColor(0); | |
| 57 | 59 | ||
| 58 | 60 | // Return the completed view to render on screen | |
| 59 | 61 | return convertView; |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
| 84 | 84 | int current = LIST_PARSER_NONE; | |
| 85 | 85 | String currentLanguage = ""; | |
| 86 | 86 | ||
| 87 | + | Dictionary d; | |
| 87 | 88 | while((line = br.readLine()) != null) { | |
| 88 | 89 | if(line.isEmpty()) { | |
| 89 | 90 | // create dictionary | |
| 90 | 91 | if(type.compareTo("radk") == 0) { | |
| 91 | - | dictionaries.add(new RadicalDict(name, | |
| 92 | + | d = new RadicalDict(name, | |
| 92 | 93 | chooseLanguage(synopsis), | |
| 93 | 94 | chooseLanguage(description), | |
| 94 | 95 | cacheDir, | |
| 95 | 96 | url, | |
| 96 | 97 | size, | |
| 97 | 98 | entries, | |
| 98 | - | sha256)); | |
| 99 | + | sha256); | |
| 99 | 100 | } else if (type.compareTo("jmdict") == 0) { | |
| 100 | - | dictionaries.add(new JMDict(name, | |
| 101 | + | d = new JMDict(name, | |
| 101 | 102 | chooseLanguage(synopsis), | |
| 102 | 103 | chooseLanguage(description), | |
| 103 | 104 | cacheDir, | |
| 104 | 105 | url, | |
| 105 | 106 | size, | |
| 106 | 107 | entries, | |
| 107 | - | sha256)); | |
| 108 | + | sha256); | |
| 109 | + | } else { | |
| 110 | + | continue; | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | if(d.isDownloaded()) { | |
| 114 | + | dictionaries.add(0, d); | |
| 115 | + | } else { | |
| 116 | + | dictionaries.add(d); | |
| 108 | 117 | } | |
| 109 | 118 | } | |
| 110 | 119 |