Coder Social home page Coder Social logo

ffgiraldez / reactive-mvvm-android Goto Github PK

View Code? Open in Web Editor NEW
637.0 637.0 77.0 514 KB

My way to MVVM using KotlinX Coroutines and Android data-binding

License: Apache License 2.0

Kotlin 100.00%
android-databinding architecture-components arrow-kt coroutines-flow functional-reactive-programming koin kotlin kotlin-coroutines kotlin-flow kotlin-functional-programming livedata mvvm room viewmodel

reactive-mvvm-android's Introduction

Reactive MVVM

My way to MVVM using KotlinX Coroutines with Android databinding

Summary

Dependencies

  • architecture components
    • livedata
    • room
    • viewmodel
  • kotlinx coroutines
  • floating search
  • okhttp
  • retrofit
  • koin
  • picasso

Testing

TODO LIST

  • Better UI, with Material Design concepts and so on
  • Add unit tests, allways fail on that :(

Developed By

Fernando Franco Giráldez - [email protected]

Follow me on Twitter Add me to Linkedin

License

Copyright 2019 Fernando Franco Giráldez
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

reactive-mvvm-android's People

Contributors

aeroechelon avatar bryant1410 avatar ffgiraldez avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactive-mvvm-android's Issues

Add CI verification

Use Github actions, Travis or whatever to ensure changes does not break anything

Refactor viewmodels

Viewmodels share lot of logic, loading, list and query properties, probably I could extract it and keep that logic into a single place

Add offline support

keep a cached list of suggestion and search results in order to allow an offline search.

Better error handling

Handle gracefully connectivity errors, especially when no data available offline.

Define a ComicError sealed class with 2 branches NetworkError and EmptyError

the idea is that QueryViewModel.results property now will be an LiveData<Either<ComicError,T>> instead of LiveData<T>, create a new ViewState QueryViewState.Error that contains a ComicError now on UI implementation handle it accordingly, for suggestions, for example, could be

@BindingAdapter("suggestions")
fun bindSuggestions(search: FloatingSearchView, liveData: List<Either<ComicError,String>?) = liveData?.let { 
    when (it) {
        is Left -> QuerySearchSuggestion(it.a.toHumanError())
        is Rigth -> it.b.map { QuerySearchSuggestion(it) }
    }.let { search.swapSuggestions(it) }
}

fun ComicError.toHumanError(): String = when(this) {
    is NetworkError -> "no internet conection"
    is EmptyError -> "search without results"
}

the search feature will be a more "harder" as the UI change, when a ComicError happens, the list could be hidden and display an icon with text that change based on it, as properties could be observed by more than one observer, actual @BindingAdapter will update adapter on Right values and hide the list on Left one, and create a new one to the error view that update the text/icon on Left values and hide it on Right

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency io.arrow-kt:arrow-fx to v0.12.1
  • fix(deps): update dependency io.arrow-kt:arrow-fx-coroutines to v0.13.3
  • fix(deps): update dependency org.mockito:mockito-core to v3.12.4
  • fix(deps): update junit5 monorepo to v5.10.2 (org.junit.jupiter:junit-jupiter-params, org.junit.jupiter:junit-jupiter-engine, org.junit.jupiter:junit-jupiter-api)
  • fix(deps): update kotlin monorepo to v1.9.23 (org.jetbrains.kotlin:kotlin-stdlib-jdk7, org.jetbrains.kotlin:kotlin-gradle-plugin)
  • fix(deps): update okhttp monorepo to v4.12.0 (com.squareup.okhttp3:logging-interceptor, com.squareup.okhttp3:okhttp)
  • fix(deps): update versions.androidx_lifecycle to v2.7.0 (androidx.lifecycle:lifecycle-viewmodel-ktx, androidx.lifecycle:lifecycle-livedata-ktx)
  • fix(deps): update versions.androidx_room to v2.6.1 (androidx.room:room-testing, androidx.room:room-compiler, androidx.room:room-ktx)
  • fix(deps): update versions.coroutines to v1.8.0 (org.jetbrains.kotlinx:kotlinx-coroutines-test, org.jetbrains.kotlinx:kotlinx-coroutines-core)
  • fix(deps): update versions.kotest to v4.6.4 (io.kotest:kotest-property-jvm, io.kotest:kotest-assertions-core-jvm, io.kotest:kotest-runner-junit5-jvm)
  • fix(deps): update versions.retrofit to v2.11.0 (com.squareup.retrofit2:converter-gson, com.squareup.retrofit2:retrofit)
  • chore(deps): update dependency gradle to v8
  • fix(deps): update dependency app.cash.turbine:turbine to v1
  • fix(deps): update dependency com.android.tools.build:gradle to v8
  • fix(deps): update dependency io.arrow-kt:arrow-core to v1
  • fix(deps): update dependency io.arrow-kt:arrow-fx-coroutines to v1
  • fix(deps): update dependency org.mockito:mockito-core to v5
  • fix(deps): update versions.kotest to v5 (major) (io.kotest:kotest-property-jvm, io.kotest:kotest-assertions-core-jvm, io.kotest:kotest-runner-junit5-jvm)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gradle
gradle.properties
dependencies.gradle
  • com.android.tools.build:gradle 4.0.1
  • org.jetbrains.kotlin:kotlin-gradle-plugin 1.4.10
  • de.mannodermaus.gradle.plugins:android-junit5 1.6.2.0
  • androidx.lifecycle:lifecycle-livedata-ktx 2.2.0
  • androidx.lifecycle:lifecycle-viewmodel-ktx 2.2.0
  • androidx.test:core-ktx 1.3.0
  • androidx.room:room-ktx 2.2.5
  • androidx.room:room-compiler 2.2.5
  • androidx.room:room-testing 2.2.5
  • androidx.constraintlayout:constraintlayout 2.0.0
  • io.arrow-kt:arrow-core 0.11.0
  • io.arrow-kt:arrow-fx 0.11.0
  • io.arrow-kt:arrow-fx-coroutines 0.11.0
  • com.google.android.material:material 1.2.1
  • com.github.arimorty:floatingsearchview 2.1.1
  • org.junit.jupiter:junit-jupiter-api 5.6.2
  • org.junit.jupiter:junit-jupiter-engine 5.6.2
  • org.junit.jupiter:junit-jupiter-params 5.6.2
  • com.squareup.okhttp3:okhttp 4.9.0
  • com.squareup.okhttp3:logging-interceptor 4.9.0
  • org.koin:koin-core 2.2.0-beta-1
  • org.koin:koin-android 2.2.0-beta-1
  • org.koin:koin-androidx-viewmodel 2.2.0-beta-1
  • org.koin:koin-test 2.2.0-beta-1
  • org.jetbrains.kotlin:kotlin-stdlib-jdk7 1.4.10
  • org.jetbrains.kotlinx:kotlinx-coroutines-core 1.3.9
  • org.jetbrains.kotlinx:kotlinx-coroutines-test 1.3.9
  • io.kotest:kotest-runner-junit5-jvm 4.2.5
  • io.kotest:kotest-assertions-core-jvm 4.2.5
  • io.kotest:kotest-property-jvm 4.2.5
  • org.mockito:mockito-core 3.5.13
  • com.nhaarman.mockitokotlin2:mockito-kotlin 2.2.0
  • com.squareup.picasso:picasso 2.8
  • com.squareup.retrofit2:retrofit 2.9.0
  • com.squareup.retrofit2:converter-gson 2.9.0
  • com.facebook.stetho:stetho 1.5.1
  • app.cash.turbine:turbine 0.2.1
settings.gradle
build.gradle
app/build.gradle
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 7.5.1

  • Check this box to trigger a request for Renovate to run again on this repository

Add unit test

Unit test viewmodels & repository

  • #28 viewmodel test suite
  • #29 UI test suite
  • repository test suite

RecyclerView.bindResults parameter name check please

hello ,
While I was looking at your app source,
I registered an issue because the name of the parameter seemed to be strange.

RecyclerView.bindResults(error: List) Unit = with(adapter as QueryVolumeAdapter)

I think the other name would be better because the item exists...

Give StateFlow a try

Update Viewmodels with StateFlow<T> once get data-binding integration in order to remove LiveData

Refactor repository

Repository actually use API and Database implementation details, create some data source and abstract access to them.

Update project

A long time has past and this project needs an update.
This is the list of changes I want to do:

  • Let's do it in Kotlin.
  • Use the last android Gradle plugin (3.1 at this moment)
  • Use RxJava 2
  • Use Architecture component ViewModels
  • Use LiveData instead of custom machinery to observe properties.

Give a co-routines a try

Actually using rx to observe changes on bbdd and call network api, probably we could use LiveData + coroutines and remove rx dependency

interface SuspendDao
suspend fun <A> SuspendDao.async(block: SuspendDao.() -> LiveData<A>) : LiveData<A> =
    suspendCoroutine { block() }

val result: LiveData<QueryEntity> = suggestionDao.async { findQueryByTerm("thor") }

improve UI

Need to review and update UI to a more sophisticated screen.

also, add some gif videos that show the app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.