Skip to content

Commit

Permalink
[refactor] #92 입력값 검사할 때도 LiveData 대신 StateFlow 사용하도록
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Aug 8, 2023
1 parent 5861401 commit 75ccd24
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.android.go.sopt.winey.presentation.main.feed.upload.amount

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import com.android.go.sopt.winey.domain.repository.AuthRepository
import com.android.go.sopt.winey.util.multipart.UriToRequestBody
import com.android.go.sopt.winey.util.view.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
Expand All @@ -26,19 +26,15 @@ import javax.inject.Inject
class AmountViewModel @Inject constructor(
private val authRepository: AuthRepository
) : ViewModel() {
val _amount = MutableLiveData<String>()
val amount: String get() = _amount.value ?: ""
val isValidAmount: LiveData<Boolean> = _amount.map { validateAmount(it) }

// val _amount = MutableStateFlow("")
// val amount: String get() = _amount.value
//
// val isValidAmount: StateFlow<Boolean> = _amount.map { validateAmount(it) }
// .stateIn(
// initialValue = false,
// scope = viewModelScope,
// started = WhileSubscribed(PRODUCE_STOP_TIMEOUT)
// )
val _amount = MutableStateFlow("")
val amount: String get() = _amount.value

val isValidAmount: StateFlow<Boolean> = _amount.map { validateAmount(it) }
.stateIn(
initialValue = false,
scope = viewModelScope,
started = WhileSubscribed(PRODUCE_STOP_TIMEOUT)
)

private var imageRequestBody: UriToRequestBody? = null

Expand Down

0 comments on commit 75ccd24

Please sign in to comment.