Detect dictionary updates and display them
CHANGELOG.md
11 | 11 | * Show a message when a file is corrupted and delete it. | |
12 | 12 | * Show partial download status when a file failed partway. | |
13 | 13 | * New pause button to stop downloads partway and retry later. | |
14 | + | * Detect dictionary updates, display them with a yellow background in the list | |
15 | + | of dictionaries. | |
14 | 16 | ||
15 | 17 | ### Bug Fixes | |
16 | 18 |
app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java
52 | 52 | ||
53 | 53 | name_view.setText(dictionary.getName()); | |
54 | 54 | description_view.setText(dictionary.getDescription()); | |
55 | + | if(!dictionary.isUpToDate()) | |
56 | + | convertView.setBackgroundColor(context.getResources().getColor(R.color.colorUpdate)); | |
55 | 57 | ||
56 | 58 | // Return the completed view to render on screen | |
57 | 59 | return convertView; |
app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java
50 | 50 | public String getSha256() { | |
51 | 51 | return sha256; | |
52 | 52 | } | |
53 | + | abstract public boolean isUpToDate(); | |
53 | 54 | ||
54 | 55 | protected File getFile() { | |
55 | 56 | return file; |
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
93 | 93 | return false; | |
94 | 94 | } | |
95 | 95 | ||
96 | + | public boolean isUpToDate() { | |
97 | + | File sha256 = new File(getFile() + ".sha256"); | |
98 | + | try { | |
99 | + | String current = readSha256FromFile(sha256); | |
100 | + | String latest = getSha256(); | |
101 | + | ||
102 | + | return latest.compareTo(current) == 0; | |
103 | + | } catch (IOException e) { | |
104 | + | e.printStackTrace(); | |
105 | + | return true; | |
106 | + | } | |
107 | + | } | |
108 | + | ||
96 | 109 | @Override | |
97 | 110 | public int size() { | |
98 | 111 | return 1; |
app/src/main/res/values/colors.xml
4 | 4 | <color name="colorPrimaryDark">#00574B</color> | |
5 | 5 | <color name="colorAccent">#D81B60</color> | |
6 | 6 | <color name="colorGrey">#EEF2EE</color> | |
7 | + | <color name="colorUpdate">#F4DE96</color> | |
7 | 8 | </resources> |