Browse Source

add refresh indicators

connman
Aditya Kulkarni 5 years ago
parent
commit
fdc8a2bcb5
  1. 13
      app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt
  2. 4
      app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt

13
app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt

@ -48,6 +48,7 @@ object ConnectionManager {
} }
println("Attempting new connection ${DataModel.connStatus}") println("Attempting new connection ${DataModel.connStatus}")
sendRefreshSignal(false)
// If direct connection, then connect to the URL in connection string // If direct connection, then connect to the URL in connection string
if (directConn) { 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) { fun sendUpdateDataSignal(updateTxns: Boolean = false) {
val i = Intent(DATA_SIGNAL) val i = Intent(DATA_SIGNAL)
i.putExtra("action", "newdata") i.putExtra("action", "newdata")
@ -126,6 +134,7 @@ object ConnectionManager {
} else { } else {
sendUpdateDataSignal(r.updateTxns) sendUpdateDataSignal(r.updateTxns)
sendRefreshSignal(r.updateTxns)
} }
} }
@ -141,6 +150,7 @@ object ConnectionManager {
if (code == 1001) { if (code == 1001) {
sendErrorSignal(reason, true) sendErrorSignal(reason, true)
} }
sendRefreshSignal(true)
} }
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
@ -151,12 +161,15 @@ object ConnectionManager {
val allowInternetConnect = true val allowInternetConnect = true
if (t is ConnectException && (m_directConn && !allowInternetConnect)) { if (t is ConnectException && (m_directConn && !allowInternetConnect)) {
sendErrorSignal(t.localizedMessage, true) sendErrorSignal(t.localizedMessage, true)
sendRefreshSignal(false)
} }
// If this was a direct connection and there was a failure to connect, retry connecting // If this was a direct connection and there was a failure to connect, retry connecting
// without the direct connection (i.e., through wormhole) // without the direct connection (i.e., through wormhole)
if (m_directConn && allowInternetConnect) { if (m_directConn && allowInternetConnect) {
makeConnection(false) makeConnection(false)
} else {
sendRefreshSignal(false)
} }
} }
} }

4
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) { override fun onReceive(context: Context, intent: Intent) {
// We've received a signal // We've received a signal
when(intent.getStringExtra("action")) { when(intent.getStringExtra("action")) {
"refresh" -> {
swiperefresh.isRefreshing = !intent.getBooleanExtra("finished", true)
}
"newdata" -> { "newdata" -> {
val updateTxns = intent.getBooleanExtra("updateTxns", false) val updateTxns = intent.getBooleanExtra("updateTxns", false)
updateUI(updateTxns) updateUI(updateTxns)
@ -320,6 +323,7 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte
println("Connstatus = Disconnected") println("Connstatus = Disconnected")
DataModel.clear() DataModel.clear()
swiperefresh.isRefreshing = false
updateUI(true) updateUI(true)
} }

Loading…
Cancel
Save