Device provision show toast is device already registered

This commit is contained in:
chandrashekhar reddy
2024-04-02 16:10:17 +05:30
parent c91082ee6d
commit f258cc3440
4 changed files with 13 additions and 4 deletions

View File

@@ -45,6 +45,7 @@ import com.google.firebase.storage.ktx.storage
import kotlinx.coroutines.tasks.await
import okhttp3.MultipartBody
import okhttp3.ResponseBody
import retrofit2.HttpException
import java.io.File
import java.net.ConnectException
import java.net.SocketTimeoutException
@@ -52,6 +53,7 @@ import javax.inject.Inject
import javax.inject.Named
class NetworkException(message: String, cause: Throwable) : Exception(message, cause)
class ValidationException(message: String) : Exception(message)
class DatabaseRepository @Inject constructor(
@Named("Auth") private val molbioAuthApi: MolbioAuthApi,
private val molbioResultApi: MolbioResultApi,
@@ -64,6 +66,8 @@ class DatabaseRepository @Inject constructor(
return try {
val response = apiCall.invoke()
Result.Success(response)
}catch (e: HttpException) {
Result.Error(ValidationException("Device Already Registered /"+e.message))
} catch (e: SocketTimeoutException) {
Result.Error(NetworkException("Network timeout", e))
} catch (e: ConnectException) {

View File

@@ -125,7 +125,7 @@ class HomeFragment : Fragment() {
getDeviceId()
checkUnprocessedCSVData()
checkForUpdate()
// checkForUpdate()
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
deleteIncompleteRegistrations(userData)
}

View File

@@ -161,10 +161,11 @@ class DeviceProvisionFragment : Fragment() {
}
is Result.Error -> {
Log.d("deviceProvisionResponse", response.exception.toString())
response.exception.let { message ->
Toast.makeText(
activity,
"An error occurred in device provision: $message",
"An error occurred in device provision: ${message.message}",
Toast.LENGTH_LONG
).show()
}

View File

@@ -51,6 +51,7 @@ import com.example.hpostesting.data.repository.Repository
import com.example.hpostesting.domain.CheckUpdateWorker
import com.example.hpostesting.domain.LogFileManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
@@ -167,7 +168,7 @@ class HemoCubeViewModel @Inject constructor(
}
fun sendDataToMolbio() = viewModelScope.launch(Dispatchers.IO) {
fun sendDataToMolbio() = viewModelScope.launch(Dispatchers.IO + coroutineExceptionHandler) {
Log.d("molbio","getting in sendMolbio")
val resultList = MolbioV2ResultRequest(mutableListOf())
@@ -235,7 +236,7 @@ class HemoCubeViewModel @Inject constructor(
}
fun sendDataToFirebase() = viewModelScope.launch ( Dispatchers.IO ) {
fun sendDataToFirebase() = viewModelScope.launch ( Dispatchers.IO + coroutineExceptionHandler ) {
val pendingData = hemoCubeDao.getFirebasePending()
pendingData.forEach{
userData ->
@@ -680,4 +681,7 @@ class HemoCubeViewModel @Inject constructor(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
).format(Calendar.getInstance().time)
}
val coroutineExceptionHandler = CoroutineExceptionHandler{_, throwable ->
throwable.printStackTrace()
}
}