All Projects → hadiyarajesh → Flower

hadiyarajesh / Flower

Licence: mit
Super cool android library to manage database caching and networking with ease.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Flower

GitHubApplication
GitHubApplication 📱 is an Android application built to demonstrate the use of modern Android development tools - (Kotlin, Coroutines, Hilt, LiveData, View binding, Data Store, Architecture components, MVVM, Room, Retrofit, Navigation).
Stars: ✭ 11 (-87.21%)
Mutual labels:  coroutines, retrofit2
Playandroid
🔥🔥🔥 Kotlin + MVVM + LCE版玩安卓,暗黑模式、横竖屏、无网、弱网、无数据、加载失败等等各种情况,协程、Room、Hilt、DataStore、LiveData、Retrofit、屏幕适配、本地缓存、多语言切换、多 lib,你想要的我都有!!!
Stars: ✭ 414 (+381.4%)
Mutual labels:  coroutines, retrofit2
Kotlin Modular Tdd Coroutines Mvvm
A sample Kotlin app which was built with modular structure, Kotlin DSL, Kotlin Coroutines, TDD and MVVM patterns.
Stars: ✭ 256 (+197.67%)
Mutual labels:  coroutines, retrofit2
GitKtDroid
A sample Android application📱 built with Kotlin for #30DaysOfKotlin
Stars: ✭ 53 (-38.37%)
Mutual labels:  coroutines, retrofit2
Kotlin Coroutines Retrofit
Kotlin Coroutines await() extension for Retrofit Call
Stars: ✭ 812 (+844.19%)
Mutual labels:  coroutines, retrofit2
Paging-3-Sample
This app is created as a sample app which loads movies from Tmdb api and uses Paging 3 library to show it in a Recycler view.
Stars: ✭ 96 (+11.63%)
Mutual labels:  coroutines, retrofit2
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (+231.4%)
Mutual labels:  coroutines, retrofit2
bitcoin-market-android
Bitcoin Market app shows you the current Bitcoin market price and price chart of different time intervals 💰
Stars: ✭ 284 (+230.23%)
Mutual labels:  coroutines, retrofit2
News
A sample News 🗞 app built using Modern Android Development [Architecture Components, Coroutines, Retrofit, Room, Kotlin, Dagger]
Stars: ✭ 774 (+800%)
Mutual labels:  coroutines, retrofit2
Wanandroidclient
【暂停更新】Try to build a www.wanandroid.com client for kotlin.
Stars: ✭ 616 (+616.28%)
Mutual labels:  coroutines, retrofit2
NYTimesMostPopularArticles
A simple app to hit the NY Times Most Popular Articles API and show a list of articles, that shows details when items on the list are tapped (a typical master/detail app), also user able to browse/ add articles to favorite list that implements MVVM architecture using Dagger2, Retrofit, Coroutines, LiveData, RoomDatabase, Database Debugging, Data…
Stars: ✭ 38 (-55.81%)
Mutual labels:  coroutines, retrofit2
Mvvm Kotlin Android Architecture
MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit5
Stars: ✭ 1,014 (+1079.07%)
Mutual labels:  coroutines, retrofit2
Compose-BreakingBad
🧪 ☠︎ Jetpack Compose - Breaking Bad ☢︎
Stars: ✭ 26 (-69.77%)
Mutual labels:  coroutines, retrofit2
Retrofit2-Flow-Call-Adapter
A Retrofit 2 adapter for Kotlin Flows.
Stars: ✭ 41 (-52.33%)
Mutual labels:  coroutines, retrofit2
DirectCurrencyConverter
Currency Converter App for Android showing usage of Flow, Live Data, Coroutines, Hilt - (Clean Architecture)
Stars: ✭ 40 (-53.49%)
Mutual labels:  coroutines, retrofit2
Kotlinjetpackinaction
🔥🔥 Kotlin Jetpack zero to hero. 新手到高手
Stars: ✭ 264 (+206.98%)
Mutual labels:  coroutines, retrofit2
Superhero-App
🦸🏻‍♂️🦹🏻‍♀️Superhero app built with Kotlin, ViewModel, LiveData, ViewBinding, Room, and Hilt
Stars: ✭ 27 (-68.6%)
Mutual labels:  coroutines, retrofit2
Stars
An android application build with a clean architecture approach and Star wars API
Stars: ✭ 54 (-37.21%)
Mutual labels:  coroutines, retrofit2
Notykt
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.
Stars: ✭ 543 (+531.4%)
Mutual labels:  coroutines, retrofit2
Marvelheroes
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.
Stars: ✭ 826 (+860.47%)
Mutual labels:  coroutines, retrofit2

Flower

Super cool library for Android to manage database caching and networking with ease. It helps you to handle all scenario of API request(success/error/loading) in one place along with database caching. It's inspired from Google's Github Browser Sample. It's built on top of Retrofit and use powerful and elegant kotlin flow api.

You can find companion medium article here

Installation

Add JitPack to your project level build.gradle file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add Gradle dependency as

dependencies {
    implementation 'com.github.hadiyarajesh:flower:1.0.0'
}

Usage

Prerequisite

  • Your Room Dao method must return Flow<YourModelClass>
  • Your Retrofit API method must return Flow<ApiResponse<YourModelClass>>
  • Add FlowCallAdapterFactory as CallAdapterFactory in your retrofit builder

1. In Repository class

Return the networkBoundResource() function from repository. This function takes following functions as parameter

  • fetchFromLocal - It fecth data from local database
  • shouldFetchFromRemote - It decide whether network request should be made or use local persistent data if available
  • fetchFromRemote - It perform network request operation
  • processRemoteResponse - It process result of network response (if requires)
  • saveRemoteData - It saves result of network request to local persistent database
  • onFetchFailed - It handle network request failure scenario (Non HTTP 200..300 response, exceptions etc)
fun getSomething(): Flow<Resource<YourModelclass>> {
    return networkBoundResources(
        fetchFromLocal = { yourDaoclass.getFromDatabase() },
        shouldFetchFromRemote = { it == null },
        fetchFromRemote = { apiInterface.getFromRemote() },
        processRemoteResponse = { },
        saveRemoteData = { yourDaoclass.saveYourData(it) },
        onFetchFailed {-, _ -> }
    ).flowOn(Dispatchers.IO)
}

2. In View Model class

Collect/transform flow to get 3 different state of request: LOADING, SUCCESS or ERROR

val someVariable: LiveData<Resource<YourModelClass>> = repository.getSomething().map {
    when (it.status) {
        Resource.Status.LOADING -> {
            Resource.loading(null)
        }
        Resource.Status.SUCCESS -> {
            Resource.success(it.data)
        }
        Resource.Status.ERROR -> {
            Resource.error(it.message!!, null)
        }
}.asLiveData(viewModelScope.coroutineContext)

3. In Activity/Fragment class

Observe it in your Activity/Fragment as

viewModel.someVariable.observer(this, Observer {
    when (it.status) {
        Resource.Status.LOADING -> {
            //Show loading message
        }
        Resource.Status.SUCCESS -> {
            //Show success message
        }
        Resource.Status.ERROR -> {
            //Show error message
        }
    }
})

Sample

Sample app is provided here. It fetch random quote from remote api and save it to local persistent database in order to display it on UI.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].