Fix laggyness when downloading dictionaries. Fixes #13.
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
| 177 | 177 | ||
| 178 | 178 | private class DownloadTask extends AsyncTask<Dictionary, Integer, String> { | |
| 179 | 179 | private Dictionary d; | |
| 180 | + | private int lastNotifiedProgress = -1; | |
| 180 | 181 | ||
| 181 | 182 | @Override | |
| 182 | 183 | protected String doInBackground(Dictionary... sDicos) { | |
… | |||
| 305 | 306 | return null; | |
| 306 | 307 | } | |
| 307 | 308 | total += count; | |
| 308 | - | // publishing the progress.... | |
| 309 | - | if (fileLength > 0) // only if total length is known | |
| 310 | - | publishProgress((int) (total * 100 / fileLength)); | |
| 311 | 309 | output.write(data, 0, count); | |
| 310 | + | // publishing the progress.... | |
| 311 | + | if (fileLength > 0) {// only if total length is known | |
| 312 | + | float progress = (int) (total * 100 / fileLength); | |
| 313 | + | if(lastNotifiedProgress < progress - 2) { | |
| 314 | + | lastNotifiedProgress = (int)progress; | |
| 315 | + | publishProgress((int) progress); | |
| 316 | + | output.flush(); | |
| 317 | + | } | |
| 318 | + | } | |
| 312 | 319 | } | |
| 313 | 320 | } catch (Exception ex) { | |
| 314 | 321 | Log.e(TAG, ex.toString()); | |