Skip to content

Commit

Permalink
Merge pull request #45 from atick-faisal/feature/debuggable-app
Browse files Browse the repository at this point in the history
Feature/debuggable app
  • Loading branch information
atick-faisal authored Dec 29, 2022
2 parents b8fa726 + 4088c13 commit 8a1559b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dev.atick.core.utils.extensions.showAlertDialog
import dev.atick.core.utils.extensions.showToast
import dev.atick.movesense.Movesense
import dev.atick.movesense.data.ConnectionState
import dev.atick.network.repository.CardiacZoneRepository
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -24,6 +25,9 @@ class DashboardFragment : BaseComposeFragment() {
@Inject
lateinit var movesense: Movesense

@Inject
lateinit var cardiacZoneRepository: CardiacZoneRepository

private val viewModel: DashboardViewModel by viewModels()

@Composable
Expand All @@ -48,6 +52,12 @@ class DashboardFragment : BaseComposeFragment() {
observeEvent(viewModel.connectDoctorStatus) {
requireContext().showToast(it)
}

collectWithLifecycle(cardiacZoneRepository.error) { error ->
error?.message?.let {
requireContext().showToast(it)
}
}
}

private fun showExitDialog() {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/kotlin/dev/atick/compose/ui/login/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import dev.atick.compose.ui.theme.ComposeTheme
import dev.atick.core.ui.BaseComposeFragment
import dev.atick.core.utils.extensions.collectWithLifecycle
import dev.atick.core.utils.extensions.observeEvent
import dev.atick.core.utils.extensions.showToast
import dev.atick.network.repository.CardiacZoneRepository
import javax.inject.Inject

@AndroidEntryPoint
class LoginFragment : BaseComposeFragment() {

private val viewModel: LoginViewModel by viewModels()

@Inject
lateinit var cardiacZoneRepository: CardiacZoneRepository

@Composable
override fun ComposeUi() {
ComposeTheme {
Expand All @@ -25,6 +32,12 @@ class LoginFragment : BaseComposeFragment() {
observeEvent(viewModel.userId) { id ->
if (id.length > 8) navigateToConnectionFragment()
}

collectWithLifecycle(cardiacZoneRepository.error) { error ->
error?.message?.let {
requireContext().showToast(it)
}
}
}

private fun navigateToConnectionFragment() {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ buildscript {
compile_sdk_version = 33
min_sdk_version = 26
target_sdk_version = 33
version_code = 27
version_name = "3.0.1"
version_code = 29
version_name = "3.1.3"

agp_version = "7.3.1"
kotlin_version = "1.7.20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.atick.network.data.*
import kotlinx.coroutines.flow.StateFlow

interface CardiacZoneRepository {
val error: StateFlow<Exception?>
val abnormalEcg: StateFlow<List<Ecg>>
suspend fun login(request: LoginRequest): LoginResponse?
suspend fun pushEcg(request: EcgRequest): PushEcgResponse?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ class CardiacZoneRepositoryImpl @Inject constructor(
override val abnormalEcg: StateFlow<List<Ecg>>
get() = _abnormalEcg.asStateFlow()

private val _error = MutableStateFlow<Exception?>(null)
override val error: StateFlow<Exception?>
get() = _error.asStateFlow()

override suspend fun login(request: LoginRequest): LoginResponse? {
return try {
cardiacZoneAPi.login(request)
} catch (e: Exception) {
Logger.e("LOGIN ATTEMPT UNSUCCESSFUL! ${e.message}")
_error.value = e
null
}
}
Expand All @@ -38,6 +43,7 @@ class CardiacZoneRepositoryImpl @Inject constructor(
response
} catch (e: Exception) {
Logger.e("ECG DATA NOT SENT! ${e.message}")
_error.value = e
null
}
}
Expand All @@ -48,6 +54,7 @@ class CardiacZoneRepositoryImpl @Inject constructor(
return response?.success ?: false
} catch (e: Exception) {
Logger.e("ERROR ADDING DOCTOR! ${e.message}")
_error.value = e
false
}
}
Expand Down

0 comments on commit 8a1559b

Please sign in to comment.