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 val TAG = CertsManager::class.java.canonicalName
|
||||||
|
|
||||||
|
private var loadingDialog: AlertDialog? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@ -61,6 +63,17 @@ class CertsManager : BaseActivity() {
|
|||||||
processGivenCertificate(this)
|
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()
|
refreshList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,18 +173,14 @@ class CertsManager : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateNewCertificate() {
|
private fun generateNewCertificate() {
|
||||||
val dialog = AlertDialog.Builder(this)
|
loadingDialog = AlertDialog.Builder(this)
|
||||||
.setView(R.layout.generating_dialog)
|
.setView(R.layout.generating_dialog)
|
||||||
.show().apply {
|
.show().apply {
|
||||||
setCancelable(false)
|
setCancelable(false)
|
||||||
setCanceledOnTouchOutside(false)
|
setCanceledOnTouchOutside(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: hum hum
|
|
||||||
viewModel.requestCertificate()
|
viewModel.requestCertificate()
|
||||||
|
|
||||||
// Close dialog
|
|
||||||
dialog.cancel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package org.communiquons.dccaggregator.viewmodel
|
package org.communiquons.dccaggregator.viewmodel
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -9,26 +11,35 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.communiquons.dccaggregator.apis.TousAntiCovidAPIClient
|
import org.communiquons.dccaggregator.apis.TousAntiCovidAPIClient
|
||||||
import org.communiquons.dccaggregator.helper.CertificatesList
|
import org.communiquons.dccaggregator.helper.CertificatesList
|
||||||
import java.lang.Exception
|
|
||||||
|
|
||||||
class CertsManagerViewModel() : ViewModel() {
|
class CertsManagerViewModel() : ViewModel() {
|
||||||
|
|
||||||
lateinit var certsManager: CertificatesList
|
lateinit var certsManager: CertificatesList
|
||||||
|
|
||||||
|
private val _reqStatus = MutableLiveData<String?>("")
|
||||||
|
val reqStatus: LiveData<String?> = _reqStatus
|
||||||
|
|
||||||
fun requestCertificate(): Job {
|
fun requestCertificate(): Job {
|
||||||
return viewModelScope.launch(Dispatchers.IO) {
|
return viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
return@launch withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
// First, fetch current signing key
|
// First, fetch current signing key
|
||||||
val config = TousAntiCovidAPIClient().getConfig()
|
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) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
// return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// return true
|
withContext(Dispatchers.Main) {
|
||||||
|
_reqStatus.value = e.message ?: "Request failed!"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user