|
// -------------------------------------------------------------------- |
|
// *** Shared *** |
|
// -------------------------------------------------------------------- |
|
|
|
|
|
// -------------------------------------------------------------------- |
|
// View.kt |
|
// -------------------------------------------------------------------- |
|
|
|
/** |
|
Shared interactors can reference properties and methods |
|
defined in their RIB's View interface. RIBs can specialize |
|
their own View interfaces to enable specific interaction |
|
on the view layer. |
|
*/ |
|
|
|
interface View: Presenter { |
|
val isUserInteractionEnabled: Bool |
|
val isHidden: Bool |
|
val alpha: Double |
|
} |
|
|
|
// -------------------------------------------------------------------- |
|
// Result.kt |
|
// -------------------------------------------------------------------- |
|
|
|
enum class Result { |
|
SUCCESS, |
|
ERROR |
|
} |
|
|
|
interface Resultable<Result> { |
|
fun getResult(): Result |
|
} |
|
|
|
// -------------------------------------------------------------------- |
|
// ChangePasswordView.kt |
|
// -------------------------------------------------------------------- |
|
|
|
/** |
|
Both Android and iOS views must implement the protocol defined below |
|
in order to attach the shared ChangePassword router (possible to have |
|
compile-time guardrails around this?). |
|
*/ |
|
|
|
interface ChangePasswordPresenter: View { |
|
val passwordFieldObservable: Observable<String> |
|
val didSubmitObservable: Observable<Void> |
|
val isSubmitEnabled: Bool |
|
} |
|
|
|
// -------------------------------------------------------------------- |
|
// ChangePasswordInteractor.kt |
|
// -------------------------------------------------------------------- |
|
|
|
@RibInteractor |
|
class ChangePasswordInteractor : Interactor<ChangePasswordPresenter, ChangePasswordRouter>() { |
|
lateinit var presenter: ChangePasswordPresenter |
|
lateinit var listener: Listener |
|
var result: ChangePasswordResultable<Result> |
|
|
|
override fun didBecomeActive(savedInstanceState: Bundle?) { |
|
super.didBecomeActive(savedInstanceState) |
|
|
|
presenter.passwordFieldObservable |
|
.observeOn(mainThreadScheduler) |
|
.autoDisposable(this) |
|
.subscribe { password -> |
|
presenter.isSubmitEnabled = !password.isEmpty |
|
} |
|
|
|
presenter.didSubmitObservable |
|
.observeOn(mainThreadScheduler) |
|
.autoDisposable(this) |
|
.subscribe { _ -> |
|
presenter.isUserInteractionEnabled = false |
|
|
|
val res = result.getResult() { res -> |
|
if (res == SUCCESS) { |
|
listener.changePasswordDidFinish() |
|
} else if (res == ERROR) { |
|
// Handle the failure |
|
presenter.isUserInteractionEnabled = true |
|
} |
|
} |
|
} |
|
} |
|
|
|
interface Listener { |
|
fun changePasswordDidFinish() |
|
} |
|
} |
|
|
|
|
|
|
|
// -------------------------------------------------------------------- |
|
// *** iOS *** |
|
// -------------------------------------------------------------------- |
|
|
|
|