{"id":18753031,"url":"https://github.com/spotify/mobius-android-sample","last_synced_at":"2025-04-13T00:31:31.198Z","repository":{"id":47290848,"uuid":"137746205","full_name":"spotify/mobius-android-sample","owner":"spotify","description":"Android Architecture Blueprint sample app implementation using Mobius","archived":false,"fork":false,"pushed_at":"2023-03-18T20:05:46.000Z","size":1816,"stargazers_count":69,"open_issues_count":3,"forks_count":20,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-05T17:13:43.477Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spotify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-18T11:58:15.000Z","updated_at":"2024-09-20T20:16:27.000Z","dependencies_parsed_at":"2023-02-15T10:01:41.008Z","dependency_job_id":null,"html_url":"https://github.com/spotify/mobius-android-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fmobius-android-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fmobius-android-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fmobius-android-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fmobius-android-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spotify","download_url":"https://codeload.github.com/spotify/mobius-android-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650590,"owners_count":21139670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:23:54.155Z","updated_at":"2025-04-13T00:31:30.326Z","avatar_url":"https://github.com/spotify.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TODO-MOBIUS\n\n### Summary\n\nThis sample is based on the [TODO-MVP-RXJAVA](https://github.com/googlesamples/android-architecture/tree/todo-mvp-rxjava) project from the Android Architecture Blueprints repository. It converts the code from MVP using RxJava to a [Mobius](https://github.com/spotify/mobius) implementation.\n\nCompared to the TODO-MVP-RXJAVA, this project implements all business logic and presentation logic as pure functions, and utilizes Mobius to manage state and side-effects. Presenters are called ViewDataMappers and they are pure functions that accept `Model` instances and return `ViewData` objects that are then bound to the UI. Furthermore, views were extracted into separate classes used by fragments. Data Source implementations were reused.\n\nThe ``TasksRepository`` class has been removed as its responsibility is achieved using a Mobius update function.\n\nThe project contains four features. Each feature's implementation is a little unique to show the different approaches to modeling in Mobius. Here are the highlights:\n* Tasks List: This uses a Data class as the `Model`. It also has a `ViewData` class that encapsulates what the view should render. A pure function that maps `Model` instances to `ViewData` ones is applied for every `Model` update and the resulting `ViewData` object is passed to the View for rendering.\n* Add/Edit Task: Also uses a Data class as the `Model` but binds that model directly to the View without the need for `ViewData`\n* Task Details: Same as Tasks List\n* Statistics: This uses a Sum Type as the `Model` to represent the different states.\n\nEach feature is divided into the following package structure:\n- featurename.domain: Contains all things describing the domain of the feature. The definition of the ``Model``, Logic (``Init``/``Update`` functions), ``Event``s and ``Effect``s that describe the feature.\n- featurename.effecthandlers: Contains the definition of all effect handlers that execute effects the logic functions dispatch.\n- featurename.view: Contains all things that have to do with presentation logic (i.e. ViewDataMappers), the definition of ViewData types, and the views implementation.\n- featurename: Contains the feature's Fragment/Activity that is responsible for creating a ``MobiusLoop.Controller``, connecting it to the View and managing it.\n\nFeatures in this project treat `Fragment`s as builders that are only responsible for managing lifecycle and creating dependencies. Each `Fragment` creates a `MobiusLoop.Controller` and connects it to the view, which is now a separate `Views` class, owned by the `Fragment`. Once a `MobiusLoop.Controller` is started, it'll start the `MobiusLoop` which kicks things off by invoking the `Init` function. The `Init` and `Update` functions define how state should evolve and what effects should happen. The UI is purely derived from the representation of state, i.e. the `Model`. There are helper methods that turn `Model`s into `Bundle`s and vice versa. These are used for state restore.\n\nMobius uses a computation thread to process events, i.e. invoke `Init`/`Update` functions. This thread is synchronized and events are processed one at a time. It also utilizes an `ExecutorService` to process effects returned by the logic functions. `MobiusLoop.Controller` makes sure `Model` updates are delivered on the main thread for rendering.\n\nThere's a helper builder accessible through `RxMobius.subtypeEffectHandler()` that allows you to specify an effect handler per effect type. Here's the definition of the effect handlers for the AddEditTask feature\n```java\nObservableTransformer\u003cAddEditTaskEffect, AddEditTaskEvent\u003e effectHandler =\n     RxMobius.\u003cAddEditTaskEffect, AddEditTaskEvent\u003esubtypeEffectHandler()\n       .addAction(NotifyEmptyTaskNotAllowed.class, showEmptyTaskError, mainThread()) // where showEmptyTaskError is an Action implementation\n       .addAction(Exit.class, showTasksList, mainThread()) // where showTasksList is an Action implementation\n       .addFunction(CreateTask.class, createTaskHandler(remoteSource, localSource)) // where createTaskHandler returns an Function\u003cCreateTask, AddEditTaskEvent\u003e\n       .addFunction(SaveTask.class, saveTaskHandler(remoteSource, localSource)) //where saveTaskHandler returns an Function\u003cSaveTask, AddEditTaskEvent\u003e\n       .build();\n```\nFor more information about Effect Handlers, please refer to the [Mobius Wiki](https://github.com/spotify/mobius/wiki/Mobius-and-RxJava#rxmobiussubtypeeffecthandler)\n\n### Dependencies\n\n* [Mobius 1.2.0](https://github.com/spotify/mobius)\n* [DataEnum 1.3.1](https://github.com/spotify/DataEnum)\n* [AutoValue 1.6.0](https://github.com/google/auto/tree/master/value)\n* [HamcrestPojo 1.1.1](https://github.com/spotify/java-hamcrest)\n* [RxJava 2.x](https://github.com/ReactiveX/RxJava)\n* [RxAndroid 2.x](https://github.com/ReactiveX/RxAndroid)\n* [SqlBrite 2.x](https://github.com/square/sqlbrite)\n\n## Features\n\n### Complexity - understandability\n\n#### Use of architectural frameworks/libraries/tools:\n\nMobius simplifies building of business logic by turning it into a synchronous pure function.\n\n#### Conceptual complexity\n\nA couple of new concepts that need to be learned such as Pure functions and Sum Types.\n\n### Testability\n\n#### Unit testing\n\nVery High. For the following reasons:\n* Logic is written as pure functions which are the easiest form of functions to test. Consequently tests can be written in a BDD behavior specification style. Furthermore, TDD becomes a lot simpler since there's no need for mocks/fakes/stubs.\n* Each effect handler has a single responsibility and the least amount of logic needed to perform the requested effect. This makes them a lot simpler and consequently easier to reason about and test.\n\n#### UI testing\nUI testing can be split into two categories of tests:\n* Presentation: Since presentation logic is also defined as a Pure function, testing it becomes very simple.\n* View: Same as TODO-MVP-RXJAVA. This implementation does not change anything with regards to integration/end to end testing.\n\n### Maintainability\n\n#### Ease of amending or adding a feature\n\nHigh.\n\n#### Learning cost\n\n* Low as Pure functions are easy to write/test\n* Medium as RxJava is not trivial. There are, however, several utilities in the framework that help build RxJava chains for users. It's worth mentioning that Mobius as a framework can also be used in apps that do not utilize RxJava.\n\n## External contributors\nMobius Implementation:\n* [Ahmed Nawara](https://github.com/anawara)\n* [Marcus Forsell Stahre](https://github.com/togi)\n* [Petter Måhlén](https://github.com/pettermahlen)\n\nOriginal Implementation:\n* [Voicu Klein](https://github.com/kleinsenberg)\n* [Erik Hellman](https://github.com/erikhellman)\n\nThis project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.\n\n[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fmobius-android-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspotify%2Fmobius-android-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fmobius-android-sample/lists"}