Observe auth statuses as LiveData, not Flow
This commit is contained in:
@@ -12,7 +12,6 @@ import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import gq.kirmanak.mealient.databinding.FragmentAuthenticationBinding
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import timber.log.Timber
|
||||
|
||||
@AndroidEntryPoint
|
||||
@@ -30,11 +29,9 @@ class AuthenticationFragment : Fragment() {
|
||||
|
||||
private fun listenToAuthenticationStatuses() {
|
||||
Timber.d("listenToAuthenticationStatuses() called")
|
||||
lifecycleScope.launchWhenCreated {
|
||||
viewModel.authenticationStatuses().collectLatest {
|
||||
Timber.d("listenToAuthenticationStatuses: new status = $it")
|
||||
if (it) navigateToRecipes()
|
||||
}
|
||||
viewModel.authenticationStatuses().observe(this) {
|
||||
Timber.d("listenToAuthenticationStatuses: new status = $it")
|
||||
if (it) navigateToRecipes()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package gq.kirmanak.mealient.ui.auth
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import gq.kirmanak.mealient.data.auth.AuthRepo
|
||||
import gq.kirmanak.mealient.data.recipes.RecipeRepo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -24,9 +25,9 @@ class AuthenticationViewModel @Inject constructor(
|
||||
authRepo.authenticate(username, password, baseUrl)
|
||||
}
|
||||
|
||||
fun authenticationStatuses(): Flow<Boolean> {
|
||||
fun authenticationStatuses(): LiveData<Boolean> {
|
||||
Timber.v("authenticationStatuses() called")
|
||||
return authRepo.authenticationStatuses()
|
||||
return authRepo.authenticationStatuses().asLiveData()
|
||||
}
|
||||
|
||||
fun logout() {
|
||||
|
||||
Reference in New Issue
Block a user