Fix laggyness when downloading dictionaries.

Julien LepillerTue Jun 09 14:21:35+0200 2020

2477d89

Fix laggyness when downloading dictionaries. Fixes #13.

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

177177
178178
    private class DownloadTask extends AsyncTask<Dictionary, Integer, String> {
179179
        private Dictionary d;
180+
        private int lastNotifiedProgress = -1;
180181
181182
        @Override
182183
        protected String doInBackground(Dictionary... sDicos) {

305306
                            return null;
306307
                        }
307308
                        total += count;
308-
                        // publishing the progress....
309-
                        if (fileLength > 0) // only if total length is known
310-
                            publishProgress((int) (total * 100 / fileLength));
311309
                        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+
                        }
312319
                    }
313320
                } catch (Exception ex) {
314321
                    Log.e(TAG, ex.toString());