From fdc8a2bcb5a3c1efc4f5efdafd8f230e5e3e61fd Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 7 Feb 2019 16:06:51 -0800 Subject: [PATCH] add refresh indicators --- .../adityapk/zcash/zqwandroid/ConnectionManager.kt | 13 +++++++++++++ .../com/adityapk/zcash/zqwandroid/MainActivity.kt | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt b/app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt index 0f52cbd..dc2da50 100644 --- a/app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt +++ b/app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt @@ -48,6 +48,7 @@ object ConnectionManager { } println("Attempting new connection ${DataModel.connStatus}") + sendRefreshSignal(false) // If direct connection, then connect to the URL in connection string if (directConn) { @@ -78,6 +79,13 @@ object ConnectionManager { } } + fun sendRefreshSignal(finished: Boolean) { + val i = Intent(DATA_SIGNAL) + i.putExtra("action", "refresh") + i.putExtra("finished", finished) + ZQWApp.appContext?.sendBroadcast(i) + } + fun sendUpdateDataSignal(updateTxns: Boolean = false) { val i = Intent(DATA_SIGNAL) i.putExtra("action", "newdata") @@ -126,6 +134,7 @@ object ConnectionManager { } else { sendUpdateDataSignal(r.updateTxns) + sendRefreshSignal(r.updateTxns) } } @@ -141,6 +150,7 @@ object ConnectionManager { if (code == 1001) { sendErrorSignal(reason, true) } + sendRefreshSignal(true) } override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { @@ -151,12 +161,15 @@ object ConnectionManager { val allowInternetConnect = true if (t is ConnectException && (m_directConn && !allowInternetConnect)) { sendErrorSignal(t.localizedMessage, true) + sendRefreshSignal(false) } // If this was a direct connection and there was a failure to connect, retry connecting // without the direct connection (i.e., through wormhole) if (m_directConn && allowInternetConnect) { makeConnection(false) + } else { + sendRefreshSignal(false) } } } diff --git a/app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt b/app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt index 60c0c19..a6fe1f2 100644 --- a/app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt +++ b/app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt @@ -251,6 +251,9 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte override fun onReceive(context: Context, intent: Intent) { // We've received a signal when(intent.getStringExtra("action")) { + "refresh" -> { + swiperefresh.isRefreshing = !intent.getBooleanExtra("finished", true) + } "newdata" -> { val updateTxns = intent.getBooleanExtra("updateTxns", false) updateUI(updateTxns) @@ -320,6 +323,7 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte println("Connstatus = Disconnected") DataModel.clear() + swiperefresh.isRefreshing = false updateUI(true) }