From 67f722dc9b6989b7574f45c1bb0903ee11326605 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 2 Dec 2018 12:21:29 +0000 Subject: [PATCH] show progress while loading accounts --- .../ktnx/mobileledger/LatestTransactions.java | 29 ++++++++++++++++++- .../mobileledger/RetrieveAccountsTask.java | 18 ++++++------ .../layout/content_latest_transactions.xml | 21 +++++++++++--- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java b/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java index 8e0269f5..b3f2c90b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java +++ b/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java @@ -1,9 +1,11 @@ package net.ktnx.mobileledger; +import android.app.Activity; import android.content.Intent; import android.content.pm.PackageInfo; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.design.widget.Snackbar; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; @@ -13,9 +15,12 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; import java.util.Date; +import static android.view.View.GONE; import static net.ktnx.mobileledger.MobileLedgerDB.db; public class LatestTransactions extends AppCompatActivity { @@ -105,7 +110,29 @@ public class LatestTransactions extends AppCompatActivity { private void update_accounts() { prepare_db(); - RetrieveAccountsTask task = new RetrieveAccountsTask(); + Activity activity = this; + + ProgressBar pb = findViewById(R.id.progressBar); + TextView pt = findViewById(R.id.textProgress); + pb.setIndeterminate(true); + + RetrieveAccountsTask task = new RetrieveAccountsTask() { + @Override + protected void onProgressUpdate(Integer... values) { + if ( values[0] == 0 ) + pt.setText(R.string.progress_connecting); + else + pt.setText(String.format(getResources().getString(R.string.progress_N_accounts_loaded), values[0])); + } + + @Override + protected void onPostExecute(Void result) { + pb.setVisibility(GONE); + pt.setVisibility(GONE); + if (this.error != 0) + Snackbar.make(drawer, activity.getResources().getString(this.error), Snackbar.LENGTH_LONG ); + } + }; task.setPref(PreferenceManager.getDefaultSharedPreferences(this)); task.execute(db); diff --git a/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java b/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java index 60e6c456..85f2306c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java @@ -17,8 +17,8 @@ import java.net.URLDecoder; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class RetrieveAccountsTask extends android.os.AsyncTask { - private int error; +abstract public class RetrieveAccountsTask extends android.os.AsyncTask { + protected int error; SharedPreferences pref; public void setPref(SharedPreferences pref) { @@ -49,8 +49,9 @@ public class RetrieveAccountsTask extends android.os.AsyncTask + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a06a809b..0bd439e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,4 +64,6 @@ Network I/O error HTTP error Network error + Connecting… + %d accounts loaded -- 2.39.5