Giter Site home page Giter Site logo

boilerplatekkmvp's Introduction

BoilerplateKKMVP

- This project is deprecated. Please use https://github.com/Shhatrat/BoilerplateKKMVP2

Welcome to my boilerplate Android project. Firstly, why I named it KKMVP?

Kotlin

Koin

ModelViewPresenter

Repository contains branches:

  • addon/RestApi simple example and logic for using REST api.
  • addon/BaseViews simple classes (such as adapters) for reducing boilerplate code
  • addon/AndroidWear simple boilerplate for standalone Android Wear app
  • addon/Realm simple example of using Realm DB
  • addon/Room simple example of using Room DB

You can easily merge it into master.

Technologies and patterns used

  • MVP with contracts
  • 100% Kotlin
  • AndroidX
  • Retrofit2 and OkHttp addon/RestApi
  • RxJava2
  • Koin (DI)
  • Support libraries
  • Picasso
  • Realm addon/Realm
  • Room addon/Room
  • Android O support

MVP with contracts

This pattern allow us to easy hermetization beetween Views and Presenters.

interface ExampleContract{
    interface IView: MvpView{
        fun showDataFromRest(value: String)
    }
    interface IPresenter<in T:MvpView>: Presenter<T>{
        fun getDataFromRest("time please")
    }
}

Interface IView should be implement by inheritance BaseActivity or BaseFragment class. This solution forces us to attach and detach presenter object in proper moment of Activity of Fragment lifecycle.

interface BasePresenterHandle{
     fun attachPresenter()
     fun detachPresenter()
}

Interface IPresenter should be implement by inheritance BasePresenter class. BasePresenter contains subscriptions variable (CompositeDisposable), every RxJava's Disposable should be add to it (preventing memory leaks).

Every Presenter's interface should be bind to implmentation by factory in mvpModule file.

...
    factory { ApiPresenter(get()) }     bind ApiContract.IPresenter::class
...

then, presenter in IView implementation should be injected this way:

    private val presenter by inject<ExContract.IPresenter<ExContract.IView>>()
    
    override fun attachPresenter() {
        presenter.attachView(this)
    }

    override fun detachPresenter() {
        presenter.detachView()
    }

See com.shhatrat.boilerplate_kkmvp.ui.ex for more details and example.

How-to

  • clone this repository
  • optionally merge branches which you need
  • in app/build.gradle change applicationId to your package
  • in strings.xml change app_name
  • change Boilerplate.ktclass name to other
  • change com.shhatrat.boilerplate_kkmbp package to your package
  • remove .git files and directories

TODO

  • example example/pollutionApp

boilerplatekkmvp's People

Contributors

shhatrat avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.