Posts

Showing posts from February, 2026

MVI / MVVM - Examples

Image
This is the accompanying examples post to  MVI - Overview with Linked Examples . These should be read together starting with that post first. Our Examples We will look at two examples of  MVI  to help explain the concepts. For the purpose of these examples, I will avoid explaining all the layout details. Instead, I will just focus on the organization and how we connect the UI and data. You can always check the full code GitHub Gists to see exactly how everything fits together. Example 1: MVI - Basic Color Selector We have a very simple color selector. This example is too basic to understand the benefits of  MVI , but it does clearly demonstrate how it works. We have our data class and action interface: Basic Color Selector - Data UiState  tracks the state of the UI for our Composable to display the data. data class UiState( val color : Color = noColor , ) UiAction  is used to pass actions from the UI to the ViewModel. interface UiAction { object Cle...

MVI - Overview with Linked Examples

Image
Below, I will focus mainly on MVI , but I will also try to highlight the difference between it and MVVM . If you think you understand the difference but are not 100% sure, I hope this helps bring a little clarity. There will be short code samples later to try and highlight the difference. This blog post is by no means exhaustive, but should serve as a good introduction and overview with relevant links for the details. This blog targets everyone from newer Android Compose programmers to more experienced developers. For the newer programmer, the introduction of this concept should help you organize your code better.  For the more experienced developers, this should serve as a good review and may give additional insights or clarification when explaining these concepts to others. There are also a couple of other posts I have planned that extend on this theme that should be interesting to intermediate to more advanced developers. All the code examples  and related explanations have...

MVI - Desired State Pattern

Image
In this blog entry, I want to briefly look at a pattern for dealing with  progressive asynchronous state changes . For the example, we will have an engine and software to mange the startup and shutdown. We'll be using this with MVI Android Compose. The handling of the engine itself is very basic. We need to know if it is stopped or running . But, we also need to know if it between those states. We need starting and stopping  states as well. This is mainly aimed at intermediate to advanced programmers, but the MVI covered and thinking behind everything should also be of interest to anyone. Why? I had no intention of writing this blog post originally, but I came across this while working on another post. I was interested in the Reducer pattern; a way of handling all UI state updates in one function. For that post, I originally created a UI example for a car's audio / electronic / engine; however, the engine part of that didn't really work very well and I came across the Desi...

DataStore / SharedPreferences 2026 - Bonus!

Image
DataStore / SharedPreferences - BONUS! Compose Only - Introduction I had no intentions of writing a third part to this series ( part 1  / part 2 )... but then needed to add the ability to quickly save values to a project I am testing. Why not use my previous versions? Well, the project is a single file of Composable objects so I didn't want to add a ViewModel or any extra complications. What you might learn from this: Beginner to Intermediate programmers are likely to pick up a few interesting points from this related to remember functions, debouncing , and how the initial DataStore loading works. Experienced programmers will likely not see much new, but may want to copy / paste this solution to quickly throw into existing projects. You may want to skim read and focus on any points you find interesting. It should be a quick read / refresher. As usual, I'm using objects to wrap things. Read this if you want to know  why I wrap examples in objects . Simple Overview This...