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}")
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)
}
}
}

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) {
// 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)
}

Loading…
Cancel
Save