Skip to content

Commit

Permalink
Merge pull request #13 from AliElDerawi/code_improvements
Browse files Browse the repository at this point in the history
refactor: Ensure type reflection for all ShoeDetailViewModel observab…
  • Loading branch information
AliElDerawi authored Jan 6, 2025
2 parents eb9c604 + 8b2a49d commit 10a7377
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class InstructionsFragment : BaseFragment() {
}
}

goNextScreenSingleLiveData.observe(mLifecycleOwner) {
goNextScreenSingleLiveEvent.observe(mLifecycleOwner) {
if (it) {
mSharedViewModel.apply {
updateNewUserValidation(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class InstructionsViewModel(val app: Application) : BaseViewModel(app) {
get() = _lastPageStateFlow

private var _goNextScreenSingleLiveEvent = SingleLiveEvent<Boolean>()
val goNextScreenSingleLiveData: LiveData<Boolean>
val goNextScreenSingleLiveEvent: LiveData<Boolean>
get() = _goNextScreenSingleLiveEvent

private var _instructionListStateFlow = MutableStateFlow<MutableList<InstructionModel>>(mutableListOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.udacity.shoestore.R
import com.udacity.shoestore.data.BaseFragment
import com.udacity.shoestore.data.NavigationCommand
import com.udacity.shoestore.databinding.FragmentShoeDetailBinding
import com.udacity.shoestore.features.main.viewModel.MainViewModel
import com.udacity.shoestore.features.shoeDetail.viewModel.ShoeDetailViewModel
import com.udacity.shoestore.utils.AppSharedMethods.getCompatColor
import com.udacity.shoestore.utils.AppSharedMethods.getCompatColorStateList
import com.udacity.shoestore.utils.AppSharedMethods.setButtonStyle
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
Expand Down Expand Up @@ -62,14 +59,14 @@ class ShoeDetailFragment : BaseFragment() {

private fun initViewModelObserver() {
with(mViewModel) {
onProcessSaveShoeLiveData.observe(mLifecycleOwner) {
onProcessSaveShoeSingleLiveEvent.observe(mLifecycleOwner) {
it?.let {
mSharedViewModel.addShoe(it)
mSharedViewModel.navigationCommand.value = NavigationCommand.Back
}
}

onCancelClickMutableLiveData.observe(mLifecycleOwner) {
onCancelClickSingleLiveEvent.observe(mLifecycleOwner) {
if (it) {
mSharedViewModel.navigationCommand.value = NavigationCommand.Back
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class ShoeDetailViewModel(val app: Application) : BaseViewModel(app) {
get() = _shoeDescriptionStateFlow

private var _onProcessSaveShoeSingleLiveEvent = SingleLiveEvent<ShoeModel>()
val onProcessSaveShoeLiveData: LiveData<ShoeModel>
val onProcessSaveShoeSingleLiveEvent: LiveData<ShoeModel>
get() = _onProcessSaveShoeSingleLiveEvent

private var _onCancelClickSingleLiveEvent = SingleLiveEvent<Boolean>()
val onCancelClickMutableLiveData: LiveData<Boolean>
val onCancelClickSingleLiveEvent: LiveData<Boolean>
get() = _onCancelClickSingleLiveEvent

private var _instructionMessageLiveData = MutableLiveData<String>(app.getString(R.string.text_add_shoe_message))
val instructionMessage: LiveData<String>
val instructionMessageLiveData: LiveData<String>
get() = _instructionMessageLiveData

init {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_shoe_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:lineSpacingMultiplier="0.7"
android:paddingStart="@dimen/margin_btnView"
android:paddingEnd="@dimen/margin_btnView"
android:text="@{shoeDetailViewModel.instructionMessage}"
android:text="@{shoeDetailViewModel.instructionMessageLiveData}"
android:textColor="@color/colorDark31"
android:theme="@style/BodyStyle"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 10a7377

Please sign in to comment.