Show partial download progress
CHANGELOG.md
| 9 | 9 | * Dictionary list is now downloaded from the website, so new dictionaries will | |
| 10 | 10 | not always require an app update. | |
| 11 | 11 | * Show a message when a file is corrupted and delete it. | |
| 12 | + | * Show partial download status when a file failed partway. | |
| 12 | 13 | ||
| 13 | 14 | ### Bug Fixes | |
| 14 | 15 |
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
| 70 | 70 | full_description_view.setText(d.getFullDescription()); | |
| 71 | 71 | ||
| 72 | 72 | 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 | + | } | |
| 74 | 78 | ||
| 75 | 79 | ImageView icon_view = findViewById(R.id.icon_view); | |
| 76 | 80 | Drawable icon = d.getDrawable(getApplicationContext()); | |
… | |||
| 285 | 289 | download_bar.setProgress(100); | |
| 286 | 290 | removeProgress(); | |
| 287 | 291 | updateLayout(d); | |
| 288 | - | if(!d.isDownloaded()) { | |
| 292 | + | if(!d.isDownloaded() && d.getExpectedFileSize() <= d.getSize()) { | |
| 289 | 293 | Snackbar.make(findViewById(R.id.name_view), getString(R.string.error_dico_checksum_fail), | |
| 290 | 294 | Snackbar.LENGTH_LONG).show(); | |
| 291 | 295 | d.remove(); | |
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | 126 | public int getSize() { | |
| 127 | - | if(!isDownloaded()) | |
| 127 | + | if(file.exists()) | |
| 128 | + | return (int) (getFile().length()); | |
| 129 | + | else | |
| 128 | 130 | return 0; | |
| 129 | - | ||
| 130 | - | return (int)(getFile().length()); | |
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | 133 | String getString(RandomAccessFile file) throws IOException { |