All Projects → guidovezzoni → Repofactory

guidovezzoni / Repofactory

Licence: apache-2.0
A flexible solution for creating a repository pattern

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Repofactory

MVVM-Demo
This demo for MVVM Design pattern for android
Stars: ✭ 20 (+25%)
Mutual labels:  rxjava2, retrofit2, repository-pattern
GithubApp-android-architecture
Let's learn a deep look at the Android architecture
Stars: ✭ 16 (+0%)
Mutual labels:  rxjava2, retrofit2, repository-pattern
mvp-android-template
MVP Android Template to give you a Quick Head Start for your next Android Project. It implements MVP Architecture using Dagger2, Room, RxJava2 , Retrofit2
Stars: ✭ 20 (+25%)
Mutual labels:  rxjava2, retrofit2, repository-pattern
Ganhuoio
基于Gank.IO提供的API的第三方客户端(RxJava+Retrofit)
Stars: ✭ 727 (+4443.75%)
Mutual labels:  rxjava2, retrofit2
News Sample App
A sample news app which demonstrates clean architecture and best practices for developing android app
Stars: ✭ 334 (+1987.5%)
Mutual labels:  rxjava2, retrofit2
Kotlinmvp
🔥 基于Kotlin+MVP+Retrofit+RxJava+Glide 等架构实现短视频类小项目,简约风格及详细注释,欢迎 star or fork!
Stars: ✭ 3,488 (+21700%)
Mutual labels:  rxjava2, retrofit2
Mvp Dagger2 Rxjava2
Android 基本mvp+dagger(dagger2.android)+rxjava2+retrofit+ormdb框架。简单组件化架构 with Base Activity,Presenter ,View,Model 的抽象封装,http 请求封装&错误统一处理
Stars: ✭ 274 (+1612.5%)
Mutual labels:  rxjava2, retrofit2
Paonet
【MVVM+RxJava2+AspectJ】泡网第三方客户端,网站主页:http://www.jcodecraeer.com/index.php
Stars: ✭ 374 (+2237.5%)
Mutual labels:  rxjava2, retrofit2
Seeweather
⛅ [@deprecated]RxJava+RxBus+Retrofit+Glide+Material Design Weather App
Stars: ✭ 3,481 (+21656.25%)
Mutual labels:  rxjava2, retrofit2
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+42331.25%)
Mutual labels:  rxjava2, retrofit2
Mvvmarms
Android MVVM Architecture Components based on MVPArms and Android Architecture Components.
Stars: ✭ 425 (+2556.25%)
Mutual labels:  rxjava2, retrofit2
Moviehub
Showcases popular movies, tv shows, and people from The Movie Database
Stars: ✭ 325 (+1931.25%)
Mutual labels:  rxjava2, retrofit2
Crazydaily
[开源项目] 一款程序员日常放松的App,基于Material Design + MVP-Clean + Weex + Flutter + RxJava2 + Retrofit + Dagger2 + Glide + Okhttp + MTRVA + BRVAH + 炫酷控件 + 炫酷动画
Stars: ✭ 294 (+1737.5%)
Mutual labels:  rxjava2, retrofit2
Rx Mvp
RxJava2+Retrofit2+RxLifecycle2+OkHttp3 封装RHttp 使用MVP模式构建项目
Stars: ✭ 343 (+2043.75%)
Mutual labels:  rxjava2, retrofit2
Kotlin Android Mvvm Starter
Android Kotlin Starter is a starter project which implements MVVM Pattern.
Stars: ✭ 276 (+1625%)
Mutual labels:  rxjava2, retrofit2
Androidproject
Android 技术中台,但愿人长久,搬砖不再有
Stars: ✭ 4,398 (+27387.5%)
Mutual labels:  rxjava2, retrofit2
Devring
安卓基础开发库,包含各常用模块,让开发简单点。
Stars: ✭ 414 (+2487.5%)
Mutual labels:  rxjava2, retrofit2
Offlinesampleapp
Sample Offline-First MVVM app that uses Android Priority Job Queue, Room, Retrofit2, LiveData, LifecycleObserver, RxJava2, Dagger Android
Stars: ✭ 653 (+3981.25%)
Mutual labels:  rxjava2, retrofit2
V9porn
9*Porn Android 客户端,突破游客每天观看10次视频的限制,还可以下载视频
Stars: ✭ 4,507 (+28068.75%)
Mutual labels:  rxjava2, retrofit2
Kotlin Android Mvp Starter
Create/Generate your kotlin MVP projects easily
Stars: ✭ 270 (+1587.5%)
Mutual labels:  rxjava2, retrofit2

Codacy Badge Android Arsenal

RepoFactory

A flexible solution for creating a repository pattern in your Android apps.

Based on RxJava and Retrofit you can either instantiate a ready-made one or build your own.

Getting started

The idea behind this library is to provide a simple way to instantiate a repository pattern, providing a parameter to define the type of repository.

The following steps describe how to implement a ready-made repository pattern.

1) Define type of data involved

a. model returned by the endpoint call, the same class will be used for caching the response - <M> in the code

b. any parameters required for the endpoint call - <P> in the code. It can be Void if no params are required. In case of multiple parameters, then Pair or Triple (from Kotlin or java) can be used, or any other Tuple defined in other libraries. The only limitation is that methods equals and hashCode must be overridden. This is because this class will be used as key for the HashMap that handles the cache.

c. type of repository chosen. Currently it can be:

  • NO_CACHE: the repository simply triggers a network call for each request
  • SINGLE_LEVEL_CACHE: a one-level memory cache is present and will be used until the response associated with a specific value of parameters doesn't expire

2) Instantiate the factory and declare a Repository<return_type, parameters>

    private final RepoFactory repoFactory = new RepoFactory();
    private final Repository<ForecastResponse, String> weatherForecastRepo;

3) Instantiate the repository defining the endpoint call

        weatherForecastRepo = repoFactory.createRepo(RepoType.SINGLE_LEVEL_CACHE,
                location -> interfaceApi.getForecast(location);

4) Define the Single to which subscribe

    public Single<ForecastResponse> getForecast(String location) {
        return weatherForecastRepo.get();
    }

Custom implementations

If any part of the architecture needs to be customised for specific needs - either the network datasource or the cache or the repository itself - the RepoFactory class can be derived and its method overridden as required. See RepoFactory.java for more info.

Gradle

Add the JitPack repository in your root build.gradle at the end of repositories:

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

Add the dependency

dependencies {
            implementation 'com.github.guidovezzoni:repofactory:1.0.0'
	}

Additional features

These features are likely to be included in future releases:

  • 3 level cache
  • periodical removal of expired cache

Known Issues

Cache validity setup

The Repository interface doesn't give access to setCacheValidity() so currently the only way to do that is

((SingleLevelCacheRepository) weatherForecastRepo).setCacheValidity(TimeUnit.MINUTES.toMillis(1));

I'm still figuring out the best way to do it

Usage of non hashable classes

When parameter <P> uses a class for which methods equals and hashCode have not been overridden, cache won't work properly.

Expired cache entries are not removed

Expired cache entries can build up in time if the parameters change frequently and values are not refreshed

Bugs and Feedback

For bugs, questions and discussions please use the GitHub Issues .

History

Version Date Issues Notes
1.0.1 28/05/2019 008,009,F010 Some Kotlin files converted, minor changes
1.0.0 01/05/2019 First Release
0.1.2_alpha 01/05/2019 Minor changes, documentation improvements
0.1.1_alpha 28/04/2019 Fixed: network call always executed
0.1.0_alpha 26/04/2019 First alpha release

License

   Copyright 2019 Guido Vezzoni

   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.
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].