-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate alert facility change sheet to use Mobius loop (#4824)
- Loading branch information
1 parent
78e8538
commit 8d8de95
Showing
16 changed files
with
452 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
sealed class AlertFacilityChangeEffect | ||
sealed interface AlertFacilityChangeEffect { | ||
data object LoadIsFacilityChangedStatus : AlertFacilityChangeEffect | ||
|
||
data object MarkFacilityChangedAsFalse : AlertFacilityChangeEffect | ||
} | ||
|
||
sealed interface AlertFacilityChangeViewEffect : AlertFacilityChangeEffect { | ||
data object CloseSheetWithContinuation : AlertFacilityChangeViewEffect | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeEffectHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
import com.f2prateek.rx.preferences2.Preference | ||
import com.spotify.mobius.functions.Consumer | ||
import com.spotify.mobius.rx2.RxMobius | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
import io.reactivex.ObservableTransformer | ||
import org.simple.clinic.facility.alertchange.AlertFacilityChangeEffect.LoadIsFacilityChangedStatus | ||
import org.simple.clinic.facility.alertchange.AlertFacilityChangeEffect.MarkFacilityChangedAsFalse | ||
import org.simple.clinic.facility.alertchange.AlertFacilityChangeEvent.FacilityChangedMarkedAsFalse | ||
import org.simple.clinic.facility.alertchange.AlertFacilityChangeEvent.IsFacilityChangedStatusLoaded | ||
import org.simple.clinic.util.scheduler.SchedulersProvider | ||
import javax.inject.Named | ||
|
||
class AlertFacilityChangeEffectHandler @AssistedInject constructor( | ||
@Named("is_facility_switched") | ||
private val isFacilitySwitchedPreference: Preference<Boolean>, | ||
private val schedulersProvider: SchedulersProvider, | ||
@Assisted private val viewEffectsConsumer: Consumer<AlertFacilityChangeViewEffect> | ||
) { | ||
|
||
@AssistedFactory | ||
interface Factory { | ||
fun create(viewEffectsConsumer: Consumer<AlertFacilityChangeViewEffect>) : AlertFacilityChangeEffectHandler | ||
} | ||
|
||
fun build(): ObservableTransformer<AlertFacilityChangeEffect, AlertFacilityChangeEvent> { | ||
return RxMobius | ||
.subtypeEffectHandler<AlertFacilityChangeEffect, AlertFacilityChangeEvent>() | ||
.addTransformer(LoadIsFacilityChangedStatus::class.java, loadFacilityChangedStatus()) | ||
.addTransformer(MarkFacilityChangedAsFalse::class.java, markFacilityChangedAsFalse()) | ||
.addConsumer(AlertFacilityChangeViewEffect::class.java, viewEffectsConsumer::accept) | ||
.build() | ||
} | ||
|
||
private fun markFacilityChangedAsFalse(): ObservableTransformer<MarkFacilityChangedAsFalse, AlertFacilityChangeEvent> { | ||
return ObservableTransformer { effects -> | ||
effects | ||
.observeOn(schedulersProvider.io()) | ||
.map { isFacilitySwitchedPreference.set(false) } | ||
.map { FacilityChangedMarkedAsFalse } | ||
} | ||
} | ||
|
||
private fun loadFacilityChangedStatus(): ObservableTransformer<LoadIsFacilityChangedStatus, AlertFacilityChangeEvent> { | ||
return ObservableTransformer { effects -> | ||
effects | ||
.observeOn(schedulersProvider.io()) | ||
.map { IsFacilityChangedStatusLoaded(isFacilitySwitchedPreference.get()) } | ||
} | ||
} | ||
} |
15 changes: 14 additions & 1 deletion
15
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
sealed class AlertFacilityChangeEvent | ||
import org.simple.clinic.widgets.UiEvent | ||
|
||
sealed interface AlertFacilityChangeEvent : UiEvent { | ||
|
||
data class IsFacilityChangedStatusLoaded(val isFacilityChanged: Boolean) : AlertFacilityChangeEvent | ||
|
||
data object FacilityChangedMarkedAsFalse : AlertFacilityChangeEvent | ||
|
||
data object YesButtonClicked : AlertFacilityChangeEvent { | ||
override val analyticsName: String = "Alert Facility Changed Sheet:Yes Button Clicked" | ||
} | ||
|
||
data object FacilityChanged : AlertFacilityChangeEvent | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeInit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
import com.spotify.mobius.First | ||
import com.spotify.mobius.Init | ||
import org.simple.clinic.facility.alertchange.AlertFacilityChangeEffect.LoadIsFacilityChangedStatus | ||
import org.simple.clinic.mobius.first | ||
|
||
class AlertFacilityChangeInit : Init<AlertFacilityChangeModel, AlertFacilityChangeEffect> { | ||
|
||
override fun init(model: AlertFacilityChangeModel): First<AlertFacilityChangeModel, AlertFacilityChangeEffect> { | ||
return first(model, LoadIsFacilityChangedStatus) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
interface AlertFacilityChangeUi { | ||
fun showFacilityChangeAlert() | ||
fun hideFacilityChangeAlert() | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeUiRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.simple.clinic.facility.alertchange | ||
|
||
import org.simple.clinic.mobius.ViewRenderer | ||
|
||
class AlertFacilityChangeUiRenderer( | ||
private val ui: AlertFacilityChangeUi | ||
) : ViewRenderer<AlertFacilityChangeModel> { | ||
|
||
override fun render(model: AlertFacilityChangeModel) { | ||
if (model.isFacilityChanged) { | ||
ui.showFacilityChangeAlert() | ||
} else { | ||
ui.hideFacilityChangeAlert() | ||
} | ||
} | ||
} |
Oops, something went wrong.