• This repository has been archived on 30/Jun/2022
  • Stars
    star
    128
  • Rank 280,177 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A UI-related rxjava component for android mvvm architecture

RxCommand

A command is an Observable triggered in response to some action, typicallyUI-related.

It manage the extra states, such as loading, enabled, errors for you, when using RxJava2 implement the functions of your ViewModel.

博客

Android 生命周期架构组件与 RxJava 完美协作

Code like this

ViewModel

public class MyViewModel extends ViewModel {

    public final RxCommand<List<User>> usersCommand;

    public MyViewModel(final UserRepository userRepository) {

        usersCommand = RxCommand.create(o -> {
                return userRepository.getUsers();
            });
    }
}

Activity

public class MyActivity extends AppCompatActivity {
    public void onCreate(Bundle savedInstanceState) {
        MyViewModel viewModel = ViewModelProviders.of(this).get(MyViewModel.class);

        viewModel.usersCommand
                .switchToLatest()
                .observeOn(AndroidSchedulers.mainThread())
                .compose(Live.bindLifecycle(this))
                .subscribe(users -> {
                    // update UI
                });

        viewModel.usersCommand
                .executing()
                .compose(Live.bindLifecycle(this))
                .subscribe(executing -> {
                    // show or hide loading
                })

        viewModel.usersCommand
                .errors()
                .compose(Live.bindLifecycle(this))
                .subscribe(throwable -> {
                    // show error message
                });
    }
}

Usage

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}
dependencies {

    //  using Support Library 26.1+
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.android.support:design:26.1.0'

    // RxJava
    compile 'io.reactivex.rxjava2:rxjava:2.1.0'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

    // Live
    compile 'com.shundaojia:live:1.0.2'

    // RxCommand
    compile 'com.shundaojia:rxcommand:1.2.2'
    compile 'android.arch.lifecycle:extensions:1.0.0' // for ViewModel

}

More Repositories

1

HBDNavigationBar

A custom UINavigationBar for smooth switching between various states, including bar style, bar tint color, background image, background alpha, bar hidden, title text attributes, tint color, shadow hidden...
Objective-C
1,625
star
2

AndroidNavigation

A library managing navigation, nested Fragment, StatusBar, Toolbar for Android
Java
710
star
3

hybrid-navigation

React Native Navigation that supports seamless navigation between Native and React.
Objective-C
313
star
4

react-native-modal-translucent

Remove the StatusBar background for Modal on Android
Java
204
star
5

MyApp

React Native 工程化实践
JavaScript
136
star
6

MyMina

小程序工程化实践
JavaScript
87
star
7

Live

A RxJava Transformer handle Android Lifecycle as same as LiveData.
Java
81
star
8

RNDemo

演示一些 ReactNative 相关的技巧,包含嵌套滚动,自定义下拉刷新,避免键盘遮挡,隐私政策等等。
TypeScript
37
star
9

react-native-toast-hybrid

A toast that can be used for react-native, while available for native android and ios
Objective-C
36
star
10

react-native-keyboard-insets

A powerful Keyboard Aware View for React Native
Java
25
star
11

HBDStatusBar

A library handling status bar hidden
Objective-C
22
star
12

android-modularization

An android modularization demo with dagger2
Java
16
star
13

RxCommand-Swift

A command is an observable triggered in response to some action, typically UI-related. Inspired by RACCommand.
Swift
10
star
14

react-native-platform

Platform tools for React Native.
Java
5
star
15

MonoDemo

Monorepo 在 React Native 项目的实践
TypeScript
4
star
16

react-native-create-lib

Tool to create a React Native library module or view module with a single command
JavaScript
3
star
17

react-native-create-app

Tool to create a React Native Project with a single command
JavaScript
2
star
18

react-native-recyclerview

2
star
19

RN063

演示 react-native-navigation-hybrid 如何和 react-native 0.63 集成
Java
1
star
20

OSSRH-69319

1
star