Git Product home page Git Product logo

stateflows's Introduction

State Flows

An Android Application written purely in Kotlin exploring various usages of Flows and Coroutines in a Real World App.

Medium Articles

Follow me on Medium for latest articles.

Medium Article
Form Validation using Mutable State Flows
Smart Listener for Shooting requests
Backoff and Retry Strategy

Cases

Form Validation

The Screen contains three input fields, the **Submit** button is only enabled once all the 3 fields are properly filled.
  • First Name must contain only alphabets.
  • Password must be atleast 8 characters long.
  • User Id must contain an underscore( _ )

Once all these fields are properly filled only then the Submit button is enabled. The Submit button disables again if any of the fields are edited and the conditions are not met.









Smart Listener for Shooting requests

For this we use an example of a search query. You don't want to shoot a request whenever the text is edited but wait untill a couple of seconds before shooting a netwiork request.

This way you reduce the number of requests and only return result for the latest text query. For Eg: User may type "Co"..."Coff"..."Coffee". You'd only want to shoot a request when the user has typed the whole word instead of sending a request for every input.

Backoff and Retry Strategy

You might come across a situation while developing an app where you’d want to retry a certain request when an Exception occurs without user’s intervention. A pragmatic example would be a case of an IO Exception.

Consider this use case. You want to fetch a list of dogs from the server, however, you get an IO exception due to a network issue. After getting an exception, you wait for a while and then retry. In case of an exception again , you might want to wait a little more than last time and then retry again.

Tech Stack

Roadmap (Features to be added )

  • Exponential Backoff for Network Requests

Find this repository useful? ❤️

Support it by starring this repository. ⭐
And follow me on Medium and Github

Issues and Contribution

Find any other use case scenario for Flows? Hit a PR!

Project Maintainers

This project is founded and actively maintained by Shivam Dhuria.

Credits

Got the idea from Kaushik Gopal

Libraries

  • Retrofit2 & OkHttp3 - construct the REST APIs and paging network data.
  • Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation.
  • Room - For storing Database.

stateflows's People

Contributors

shivamdhuria avatar

Stargazers

Binay Shaw avatar  avatar mnishig avatar Arda K. avatar  avatar Asif Javed avatar Behzod Halil avatar Hanantadk avatar Ara Park avatar 훈성 avatar Trung Nguyen avatar  avatar Paramjit Singh Rana avatar  avatar  avatar Jesús María avatar Govind Dixit avatar Matheus Lopes avatar Jesús Rodríguez avatar Fevzi Ömür Tekin avatar 吴上阿吉 avatar İbrahim Süren avatar Enes Zor avatar Taylan Sabırcan avatar Julsapargi Nursam avatar  avatar PawanKasar avatar Prasan avatar Sara Han avatar Kim Yong Dae avatar Aditya Mahakalkar avatar GeanCarlosBr avatar  avatar Thach Vo avatar Guan Yu avatar Richard Oruna avatar Wade avatar Osaigbovo Odiase avatar Xionghu avatar Kevin Zhou avatar  avatar mehrdadf7 avatar David Sierra avatar Safy avatar  avatar Segun Francis avatar  avatar

stateflows's Issues

How combine use one MutableStateFlow ? and let UI show multi error hint ?

Dear Sir

if mix _firstName & _password & _userID at one = MutableStateFlow(UIState)

like

https://github.com/ydhnwb/android-clean-architecture/blob/ab9ab0b69d43489709b0b7954c316366022e4d2a/app/src/main/java/com/ydhnwb/cleanarchitectureexercise/presentation/login/LoginViewModel.kt#L18

https://github.com/Shivamdhuria/stateFlows/blob/master/app/src/main/java/com/example/stateflow/backoff/data/ResultWrapper.kt

i want Validate "input " by combine

like :

    val flowEmail = flowOf(checkEmail(email))
    val flowPwd = flowOf(checkPwd(pwd))

  combine(flowEmail, flowPwd) { r1, r2 ->
            Timber.e("Show result1 $r1  result2 $r2")
            if (r1!=0){
                state.value = UIState.Error("werwerwer")
            }
            if(r2!=0){
                state.value = UIState.Error("ewewrewrewre")
            }
            return@combine (r1 == 0 && r2 == 0)
        } ....

when inputs (email & pwd) all error

the state.value has two times change

( the UI is hint "isLegalPassword" & "not email address" )

but UI (XXXFragmnet ) only get one change

how use combine & one MutableStateFlow show detail error ?

THX

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.