Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switched to SingleLiveEvent observation for navigation between EnterArticles and AddressConfirmation (Seeker > Create) #133

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import app.nexd.android.api.model.CreateHelpRequestArticleDto
import app.nexd.android.api.model.HelpRequestCreateDto
import app.nexd.android.api.model.User
import app.nexd.android.ui.common.HelpRequestCreateArticleBinder
import app.nexd.android.ui.utils.SingleLiveEvent
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import io.reactivex.disposables.CompositeDisposable

class SeekerCreateRequestViewModel(private val api: Api) : ViewModel() {

sealed class Progress {
object Idle : Progress()
object Loading : Progress()
class Error(@StringRes val message: Int? = null) : Progress()
object Finished : Progress()
}

val navigateToConfirmAddress = SingleLiveEvent<Any>()

val progress = MutableLiveData<Progress>(Progress.Idle)

val firstName = MutableLiveData<String?>()
Expand Down Expand Up @@ -90,7 +92,7 @@ class SeekerCreateRequestViewModel(private val api: Api) : ViewModel() {
selectedArticles.clear()
setSelectedArticles()
if (selectedArticles.isNotEmpty()) {
progress.value = Progress.Loading
navigateToConfirmAddress.call()
} else {
progress.value = Progress.Error(R.string.seeker_request_create_no_articles)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class SeekerCreateRequestConfirmAddressFragment : Fragment() {
is Idle -> {
// nothing to do
}
is Loading -> {
//
}
is Error -> {
it.message?.let { errorMessageId ->
DefaultSnackbar(binding.root, errorMessageId, Snackbar.LENGTH_SHORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ class SeekerCreateRequestEnterArticlesFragment : Fragment() {
}
})

vm.navigateToConfirmAddress.observe(viewLifecycleOwner, Observer {
findNavController().navigate(SeekerCreateRequestEnterArticlesFragmentDirections.toSeekerCreateRequestConfirmAddressFragment())
})

vm.progress.observe(viewLifecycleOwner, Observer {
when (it) {
is Idle -> {
//nothing to do
}
is Loading -> {
findNavController().navigate(SeekerCreateRequestEnterArticlesFragmentDirections.toSeekerCreateRequestConfirmAddressFragment())
// nothing to do
}
is Finished -> {
// state not reachable
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_transcript_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
android:autofillHints="postal-code"
android:background="@drawable/rounded_white"
android:error="@{viewModel.zipCodeError}"
android:inputType="number"
android:inputType="textPostalAddress"
android:nextFocusDown="@id/editText_city_value"
android:padding="10dp"
android:text="@={viewModel.zipCode}"
Expand Down