Detect dictionary updates and display them

Julien LepillerSun May 31 17:28:21+0200 2020

832322c

Detect dictionary updates and display them

CHANGELOG.md

1111
* Show a message when a file is corrupted and delete it.
1212
* Show partial download status when a file failed partway.
1313
* 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.
1416
1517
### Bug Fixes
1618

app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java

5252
5353
        name_view.setText(dictionary.getName());
5454
        description_view.setText(dictionary.getDescription());
55+
        if(!dictionary.isUpToDate())
56+
            convertView.setBackgroundColor(context.getResources().getColor(R.color.colorUpdate));
5557
5658
        // Return the completed view to render on screen
5759
        return convertView;

app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java

5050
    public String getSha256() {
5151
        return sha256;
5252
    }
53+
    abstract public boolean isUpToDate();
5354
5455
    protected File getFile() {
5556
        return file;

app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java

9393
        return false;
9494
    }
9595
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+
96109
    @Override
97110
    public int size() {
98111
        return 1;

app/src/main/res/values/colors.xml

44
    <color name="colorPrimaryDark">#00574B</color>
55
    <color name="colorAccent">#D81B60</color>
66
    <color name="colorGrey">#EEF2EE</color>
7+
    <color name="colorUpdate">#F4DE96</color>
78
</resources>