1

Please does anyone have a link to a resource that helps in learning how to create an app using mvi design pattern but all code should be in Java and not Kotlin

1 Answer 1

1

Before you click! This is in Kotlin -> https://tech.olx.com/mvi-architecture-in-android-a-simple-livedata-based-approach-b4b23896fd32 But if you actually look at the code snippets there is not a single line that doesn't have an obvious Java counter part. There is not a single Kotlin exclusive item like Flow, Scoping, Coroutine anywhere.

You don't need to learn Kotlin to understand it, just read it.

The article explains MVI as a modified way to use a MVVM.

It has 2 (ViewState/ViewEffect) components that are observed by the view (Fragment/Activity)

It has 1 (ViewEvent) component that is used by the view to trigger changes in the observed components above.

ViewState : It contains your data, like a List, like a boolean that determines if something is enabled, etc... When there is a change in any state data, like an update to the List, the observer receives everything, and updates everything.

ViewEffect : These are one off "effects" like starting an animation, making a toast. You will update this with new data when you not concerned about the state of the effect. Like I don't care if there is another toast on the screen, atm. Just make a new one with new information, and show it.

ViewEvent : This allows the ViewModel to receive events from the view and start the "update" process. If a button is clicked in the view all the view would do is send a ViewEvent to the ViewModel stating what has been clicked. Then the ViewModel updates the ViewState/ViewEffect based on the ViewEvent received, which then propagates to the view.

Sign up to request clarification or add additional context in comments.

3 Comments

have you done this in plain java before, if so a link to the code will be highly appreciated. also is there any way to have an equivalent of data class and sealed class in java as that of kotlin
data = POJO and sealed = abstract. Here is the rest of the conversions. medium.com/asos-techblog/…
thanks, this is surely a life saver, time to play around with mvi in java. lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.