Get feedback on request
This commit is contained in:
parent
dacf7fbc18
commit
13ae15491f
@ -40,6 +40,8 @@ class CertsManager : BaseActivity() {
|
||||
|
||||
private val TAG = CertsManager::class.java.canonicalName
|
||||
|
||||
private var loadingDialog: AlertDialog? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@ -61,6 +63,17 @@ class CertsManager : BaseActivity() {
|
||||
processGivenCertificate(this)
|
||||
}
|
||||
|
||||
// Follow request progress
|
||||
viewModel.reqStatus.observe(this) {
|
||||
if (it == "") return@observe
|
||||
|
||||
loadingDialog?.cancel()
|
||||
if (it != null)
|
||||
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
|
||||
else
|
||||
finish()
|
||||
}
|
||||
|
||||
refreshList()
|
||||
}
|
||||
|
||||
@ -160,18 +173,14 @@ class CertsManager : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun generateNewCertificate() {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
loadingDialog = AlertDialog.Builder(this)
|
||||
.setView(R.layout.generating_dialog)
|
||||
.show().apply {
|
||||
setCancelable(false)
|
||||
setCanceledOnTouchOutside(false)
|
||||
}
|
||||
|
||||
// TODO: hum hum
|
||||
viewModel.requestCertificate()
|
||||
|
||||
// Close dialog
|
||||
dialog.cancel()
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package org.communiquons.dccaggregator.viewmodel
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -9,26 +11,35 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.communiquons.dccaggregator.apis.TousAntiCovidAPIClient
|
||||
import org.communiquons.dccaggregator.helper.CertificatesList
|
||||
import java.lang.Exception
|
||||
|
||||
class CertsManagerViewModel() : ViewModel() {
|
||||
|
||||
lateinit var certsManager: CertificatesList
|
||||
|
||||
private val _reqStatus = MutableLiveData<String?>("")
|
||||
val reqStatus: LiveData<String?> = _reqStatus
|
||||
|
||||
fun requestCertificate(): Job {
|
||||
return viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
return@launch withContext(Dispatchers.IO) {
|
||||
withContext(Dispatchers.IO) {
|
||||
// First, fetch current signing key
|
||||
val config = TousAntiCovidAPIClient().getConfig()
|
||||
Log.d("testpk", config.activityPassGenerationServerPublicKey)
|
||||
Log.d("Server Primary Key", config.activityPassGenerationServerPublicKey)
|
||||
|
||||
throw java.lang.Exception("TODO: send request")
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
_reqStatus.value = null
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// return false
|
||||
}
|
||||
|
||||
// return true
|
||||
withContext(Dispatchers.Main) {
|
||||
_reqStatus.value = e.message ?: "Request failed!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user