Skip to content

Commit

Permalink
:bugs: Change coroutin to execute after response
Browse files Browse the repository at this point in the history
  • Loading branch information
paul2126 committed Nov 26, 2023
1 parent 9b0213d commit d2264e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class SettingsBackupDto(
@Json(name = "display_mode") val displayMode: Int? = null,
@Json(name = "default_menu") val defaultMenu: Int? = null
@Json(name = "default_menu") val defaultMenu: Int? = null,
@Json(name = "updated_at") val updatedAt: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,19 @@ class SettingsRepository @Inject constructor(
response.body()?.let { settingsDto ->
val displayMode = settingsDto.displayMode
val defaultMenu = settingsDto.defaultMenu
val updatedAt = settingsDto.updatedAt!!
setLastBackupDate(updatedAt)
if (displayMode == 0) {
setDarkMode(false)
settingsPrefManager.saveDarkMode(false)
} else {
setDarkMode(true)
settingsPrefManager.saveDarkMode(true)
}
if (defaultMenu == 0) {
setInitialPage(InitialPage.SYMBOL_SELECTION)
} else {
setInitialPage(InitialPage.TEXT_TO_SPEECH)
}

Resource.success(null)
} ?: returnUnknownError()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.example.speechbuddy.utils.Status
import com.example.speechbuddy.utils.isValidEmail
import com.example.speechbuddy.utils.isValidPassword
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
Expand Down Expand Up @@ -128,11 +130,14 @@ class LoginViewModel @Inject internal constructor(
// AccessToken is already saved in AuthTokenPrefsManager by the authRepository
sessionManager.setAuthToken(resource.data!!)
runBlocking {
getMyInfoFromRemote(resource.data.accessToken)
getMyDisplaySettingsFromRemote(resource.data.accessToken)
getSymbolListFromRemote(resource.data.accessToken)
getFavoritesListFromRemote(resource.data.accessToken)
getWeightTableFromRemote(resource.data.accessToken)
val jobs = mutableListOf<Job>()
jobs.add(viewModelScope.launch { getMyInfoFromRemote(resource.data.accessToken) })
jobs.add(viewModelScope.launch { getMyDisplaySettingsFromRemote(resource.data.accessToken) })
jobs.add(viewModelScope.launch { getSymbolListFromRemote(resource.data.accessToken) })
jobs.add(viewModelScope.launch { getFavoritesListFromRemote(resource.data.accessToken) })
jobs.add(viewModelScope.launch { getWeightTableFromRemote(resource.data.accessToken) })

jobs.joinAll()
}

} else if (resource.message?.contains("email", ignoreCase = true) == true) {
Expand Down

0 comments on commit d2264e0

Please sign in to comment.