Skip to content

Commit

Permalink
Merge pull request #12 from AliElDerawi/code_improvments
Browse files Browse the repository at this point in the history
feat: Apply code improvements for Instructions classes
  • Loading branch information
AliElDerawi authored Jan 6, 2025
2 parents ed8bcfa + fb00365 commit eb9c604
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ class InstructionsFragment : BaseFragment() {

private fun initViewPager() {

with(mBinding) {
boardingViewPager.adapter = OnBoardingAdapter(InstructionModel.getInstructionCallBack())
mViewModel.setLastPage(mViewModel.instructionListStateFlow.value.size - 1)
}

mBinding.boardingViewPager.adapter =
OnBoardingAdapter(InstructionModel.getInstructionCallBack())
initBoardingViewPagerListener()

}


Expand All @@ -78,7 +76,7 @@ class InstructionsFragment : BaseFragment() {
}
}

goNextScreenLiveData.observe(mLifecycleOwner) {
goNextScreenSingleLiveData.observe(mLifecycleOwner) {
if (it) {
mSharedViewModel.apply {
updateNewUserValidation(false)
Expand All @@ -97,7 +95,7 @@ class InstructionsFragment : BaseFragment() {
ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
mViewModel.onPageChange(position)
mViewModel.onPageChange(position)
}
})
}
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 goNextScreenLiveData: LiveData<Boolean>
val goNextScreenSingleLiveData: LiveData<Boolean>
get() = _goNextScreenSingleLiveEvent

private var _instructionListStateFlow = MutableStateFlow<MutableList<InstructionModel>>(mutableListOf())
Expand All @@ -31,6 +31,7 @@ class InstructionsViewModel(val app: Application) : BaseViewModel(app) {

init {
_instructionListStateFlow.value.addAll(app.getInstruction())
setLastPage(instructionListStateFlow.value.size - 1)
}

private fun incrementPage() {
Expand All @@ -42,9 +43,6 @@ class InstructionsViewModel(val app: Application) : BaseViewModel(app) {
}

fun onPageChange(position: Int) {
if (position == 0 && currentPageLiveData.value != -1) {
return
}
Timber.d("onPageChange: $position")
_currentPageLiveData.value = position
}
Expand Down

0 comments on commit eb9c604

Please sign in to comment.