Giter Site home page Giter Site logo

ezhome / android-rxpresenter Goto Github PK

View Code? Open in Web Editor NEW
20.0 17.0 4.0 122 KB

A Reactive Presenter library for MVP pattern for modern Android Apps

License: Apache License 2.0

Java 54.36% Kotlin 45.64%
android mvp-architecture mvp-android mvp-library rxjava-android android-mvp-architecture kotlin-android kotlin-library

android-rxpresenter's Introduction

Hex.pm Platform Download Build Status Android Arsenal

RxPresenter

A Reactive Presenter library for MVP pattern for modern Android Apps. This library follows the lifecycle of an android app component (Activity,AppCompatActivity,Fragment, DialogFragment). Specifically relies on RxLifecycle by Trello.


Contents

Usage

This library supports only the support Activity,AppCompatActivity, Fragment and DialogFragment. In order to be able to use the library, these app components must inherit one of the followings, MvpActivity, MvpFragment

Activity

bind(activity);

Fragment

bind(fragment);

Dialog Fragment

bind(dialogFragment);

Firstly you need to define an interface which representing a View in a MVP pattern and there is a 1-to-1 relationship and two way communication between View & Presenter. In our case this interface must extends MvpView eg.

interface DemoView extends MvpView {

}

Then you need to create a Presenter in the MVP pattern. In this library the Presenter must extend RxPresenter<V> where V is the View interface which we defined above. eg.

class DemoPresenter extends RxPresenter<DemoView> {

  DemoPresenter() {
  }
 }

The corresponding android app component must implements the View interface! After that you need just to initialise the presenter and bind(component) it to Fragment or DialogFragment. eg.

Without Dependency Injection

public class DemoFragment extends MvpFragment implements DemoView {

  private Presenter presenter = new DemoPresenter();

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.presenter.bind(this);
  }
}

With Dependency Injection - Dagger2

public class DemoFragment extends MvpFragment implements DemoView {

  @Inject Presenter presenter;

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Dagger2 injection code

    this.presenter.bind(this);
  }
}

After the line this.presenter.bind(this) the Presenter starts following the Android App Component's lifecycle and specifically on onViewCreated we bound the corresponding interface View automatically without the need to do it explicitly. Then the Presenter follows the typical lifecycle methods onResume, onPause, onDestroy.

RxPresenter exposes also helper methods which will help your RxJava observables to follow the Android App Component's lifecycle (with the use of RxLifecycle by Trello).

  1. By default stops emitting in FragmentEvent.DESTROY_VIEW and use a Subscriber<T> to "react"
bindLifecycle(@NonNull Observable<T> observable, Subscriber<T>... subscribers)
  1. By default stops emitting in FragmentEvent.DESTROY_VIEW and use an Action1<T> to "react"
bindLifecycle(@NonNull Observable<T> observable, Action1<T> action)
  1. Stops emitting on the provided FragmentEvent and use a Subscriber<T> to "react"
 bindUntilEvent(@NonNull Observable<T> observable, @NonNull FragmentEvent event, Subscriber<T>... subscribers)
  1. Stops emitting on the provided FragmentEvent and use an Action1<T> to "react"
 bindUntilEvent(@NonNull Observable<T> observable, @NonNull FragmentEvent event, Action1<T> action)

Download

The project is available on jCenter. In your app build.gradle (or explicit module) you must add this:

dependencies {
  //java
  compile 'com.ezhome:rxpresenter:1.3.0'

  //kotlin
  compile 'com.ezhome:rxpresenter-kotlin:1.3.0'
}

Tests

./gradlew :rxpresenter:test

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

License

See the LICENSE file for license rights and limitations (Apache license 2.0).

android-rxpresenter's People

Contributors

pawelnuzka avatar spirosoik avatar

Stargazers

 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

android-rxpresenter's Issues

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.