Show partial download progress

Julien LepillerThu May 28 16:42:47+0200 2020

8cfdcab

Show partial download progress

CHANGELOG.md

99
* Dictionary list is now downloaded from the website, so new dictionaries will
1010
  not always require an app update.
1111
* Show a message when a file is corrupted and delete it.
12+
* Show partial download status when a file failed partway.
1213
1314
### Bug Fixes
1415

app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java

7070
        full_description_view.setText(d.getFullDescription());
7171
7272
        download_bar = findViewById(R.id.download_progress);
73-
        download_bar.setProgress(0);
73+
        if(d.isDownloaded()) {
74+
            download_bar.setProgress(100);
75+
        } else {
76+
            download_bar.setProgress(d.getSize()*100 / d.getExpectedFileSize());
77+
        }
7478
7579
        ImageView icon_view = findViewById(R.id.icon_view);
7680
        Drawable icon = d.getDrawable(getApplicationContext());

285289
            download_bar.setProgress(100);
286290
            removeProgress();
287291
            updateLayout(d);
288-
            if(!d.isDownloaded()) {
292+
            if(!d.isDownloaded() && d.getExpectedFileSize() <= d.getSize()) {
289293
                Snackbar.make(findViewById(R.id.name_view), getString(R.string.error_dico_checksum_fail),
290294
                        Snackbar.LENGTH_LONG).show();
291295
                d.remove();

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

124124
125125
126126
    public int getSize() {
127-
        if(!isDownloaded())
127+
        if(file.exists())
128+
            return (int) (getFile().length());
129+
        else
128130
            return 0;
129-
130-
        return (int)(getFile().length());
131131
    }
132132
133133
    String getString(RandomAccessFile file) throws IOException {