Skip to content

Commit

Permalink
增加联表校验示例代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Jun 10, 2018
1 parent 08d3e42 commit 05a4cd0
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@

package com.xuexiang.rxutil2demo.activity;

import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.xuexiang.rxutil2.RxBindingUtils;
import com.xuexiang.rxutil2.rxjava.DisposablePool;
import com.xuexiang.rxutil2.subsciber.SimpleThrowableAction;
import com.xuexiang.rxutil2demo.R;
import com.xuexiang.rxutil2demo.base.BaseActivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.Consumer;

/**
Expand All @@ -41,6 +47,13 @@ public class RxBindingActivity extends BaseActivity {
@BindView(R.id.et_input)
EditText mEtInput;

@BindView(R.id.et_username)
EditText mEtUsername;
@BindView(R.id.et_password)
EditText mEtPassword;
@BindView(R.id.btn_login)
Button mBtnLogin;

/**
* 布局的资源id
*
Expand Down Expand Up @@ -71,18 +84,37 @@ public void accept(Object o) {
}
});


DisposablePool.get().add(RxBindingUtils.textChanges(mEtInput, 1, TimeUnit.SECONDS, new Consumer<CharSequence>() {
@Override
public void accept(CharSequence charSequence) throws Exception {
toast("输入内容:" + charSequence);
}
}), "textChanges");

DisposablePool.get().add(Observable.combineLatest(RxBindingUtils.textChanges(mEtUsername), RxBindingUtils.textChanges(mEtPassword), new BiFunction<CharSequence, CharSequence, Boolean>() {
@Override
public Boolean apply(CharSequence charSequence, CharSequence charSequence2) {
return !TextUtils.isEmpty(mEtUsername.getText()) && !TextUtils.isEmpty(mEtPassword.getText());
}
}).subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception{
mBtnLogin.setEnabled(aBoolean);
}
}, new SimpleThrowableAction("RxBindingActivity")), "combineLatest");


}

@Override
protected void onDestroy() {
DisposablePool.get().remove("textChanges");
DisposablePool.get().remove("combineLatest");
super.onDestroy();
}

@OnClick(R.id.btn_login)
public void onViewClicked() {
toast("登录");
}
}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_rxbinding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="多次点击处理" />

<View
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>

<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="20"
android:hint="请输入用户名"
android:inputType="textPersonName" />

<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="20"
android:hint="请输入秘密"
android:inputType="textPassword" />

<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录" />
</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
apply from: 'https://raw.githubusercontent.com/xuexiangjys/XUtil/master/versions.gradle'
apply from: './versions.gradle'
addRepos(repositories) //增加代码仓库

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public static Disposable setItemClicks(AdapterView<?> view, long duration, TimeU
}

//========================变化事件=============================//
/**
* 简单的文字变化监听
*
* @param textView 监听控件
* @return
*/
public static Observable<CharSequence> textChanges(TextView textView) {
return RxTextView.textChanges(textView);
}

/**
* 简单的文字变化监听
Expand Down
182 changes: 182 additions & 0 deletions versions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/**
* Shared file between builds so that they can all use the same dependencies and
* maven repositories.
**/
ext.deps = [:]
def versions = [:]
versions.android_gradle_plugin = "3.0.1"
versions.android_maven_gradle_plugin = "2.0"
versions.gradle_bintray_plugin = "1.8.0"
versions.arch_core = "1.1.0"
versions.room = "1.1.0-alpha1"
versions.lifecycle = "1.1.0"
versions.support = "27.1.1"
versions.dagger = "2.11"
versions.junit = "4.12"
versions.espresso = "3.0.2"
versions.retrofit = "2.3.0"
versions.okhttp_logging_interceptor = "3.9.0"
versions.mockwebserver = "3.8.1"
versions.apache_commons = "2.5"
versions.mockito = "2.7.19"
versions.mockito_all = "1.10.19"
versions.dexmaker = "2.2.0"
versions.constraint_layout = "1.0.2"
versions.glide = "3.8.0"
versions.timber = "4.5.1"
versions.rxjava2 = "2.1.3"
versions.rx_android = "2.0.1"
versions.atsl_runner = "1.0.1"
versions.atsl_rules = "1.0.1"
versions.hamcrest = "1.3"
versions.kotlin = "1.2.20"
versions.paging = "1.0.0-alpha5"
versions.butterknife = "8.8.1"
versions.runner = "1.0.1"
versions.gson = "2.8.2"
versions.okhttp3 = "3.9.1"
versions.nineoldandroids = "2.4.0"
versions.calligraphy = "2.3.0"
versions.godeye = "1.7.4"

def deps = [:]

def support = [:]
support.annotations = "com.android.support:support-annotations:$versions.support"
support.app_compat = "com.android.support:appcompat-v7:$versions.support"
support.recyclerview = "com.android.support:recyclerview-v7:$versions.support"
support.cardview = "com.android.support:cardview-v7:$versions.support"
support.design = "com.android.support:design:$versions.support"
support.v4 = "com.android.support:support-v4:$versions.support"
support.core_utils = "com.android.support:support-core-utils:$versions.support"
deps.support = support

def room = [:]
room.runtime = "android.arch.persistence.room:runtime:$versions.room"
room.compiler = "android.arch.persistence.room:compiler:$versions.room"
room.rxjava2 = "android.arch.persistence.room:rxjava2:$versions.room"
room.testing = "android.arch.persistence.room:testing:$versions.room"
deps.room = room

def lifecycle = [:]
lifecycle.runtime = "android.arch.lifecycle:runtime:$versions.lifecycle"
lifecycle.extensions = "android.arch.lifecycle:extensions:$versions.lifecycle"
lifecycle.java8 = "android.arch.lifecycle:common-java8:$versions.lifecycle"
lifecycle.compiler = "android.arch.lifecycle:compiler:$versions.lifecycle"
deps.lifecycle = lifecycle

def arch_core = [:]
arch_core.testing = "android.arch.core:core-testing:$versions.arch_core"
deps.arch_core = arch_core

def retrofit = [:]
retrofit.runtime = "com.squareup.retrofit2:retrofit:$versions.retrofit"
retrofit.gson = "com.squareup.retrofit2:converter-gson:$versions.retrofit"
retrofit.mock = "com.squareup.retrofit2:retrofit-mock:$versions.retrofit"
deps.retrofit = retrofit
deps.okhttp_logging_interceptor = "com.squareup.okhttp3:logging-interceptor:${versions.okhttp_logging_interceptor}"

def dagger = [:]
dagger.runtime = "com.google.dagger:dagger:$versions.dagger"
dagger.android = "com.google.dagger:dagger-android:$versions.dagger"
dagger.android_support = "com.google.dagger:dagger-android-support:$versions.dagger"
dagger.compiler = "com.google.dagger:dagger-compiler:$versions.dagger"
dagger.android_support_compiler = "com.google.dagger:dagger-android-processor:$versions.dagger"

deps.dagger = dagger

def butterknife = [:]
butterknife.runtime = "com.jakewharton:butterknife:$versions.butterknife"
butterknife.compiler = "com.jakewharton:butterknife-compiler:$versions.butterknife"

deps.butterknife = butterknife

def arouter = [:]
arouter.api = "com.alibaba:arouter-api:1.3.1"
arouter.compiler = "com.alibaba:arouter-compiler:1.1.4"

deps.arouter = arouter

def espresso = [:]
espresso.core = "com.android.support.test.espresso:espresso-core:$versions.espresso"
espresso.contrib = "com.android.support.test.espresso:espresso-contrib:$versions.espresso"
espresso.intents = "com.android.support.test.espresso:espresso-intents:$versions.espresso"
deps.espresso = espresso

def atsl = [:]
atsl.runner = "com.android.support.test:runner:$versions.atsl_runner"
atsl.rules = "com.android.support.test:rules:$versions.atsl_runner"
deps.atsl = atsl

def mockito = [:]
mockito.core = "org.mockito:mockito-core:$versions.mockito"
mockito.all = "org.mockito:mockito-all:$versions.mockito_all"
deps.mockito = mockito

def kotlin = [:]
kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jre7:$versions.kotlin"
kotlin.test = "org.jetbrains.kotlin:kotlin-test-junit:$versions.kotlin"
kotlin.plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"

deps.kotlin = kotlin

def godeye = [:]
godeye.core = "cn.hikyson.godeye:godeye-core:$versions.godeye"
godeye.toolbox = "cn.hikyson.godeye:godeye-toolbox:$versions.godeye"
godeye.monitor = "cn.hikyson.godeye:godeye-monitor:$versions.godeye"
godeye.monitor_no_op = "cn.hikyson.godeye:godeye-monitor-no-op:$versions.godeye"

deps.godeye = godeye

deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
deps.android_maven_gradle_plugin = "com.github.dcendents:android-maven-gradle-plugin:$versions.android_maven_gradle_plugin"
deps.gradle_bintray_plugin = "com.jfrog.bintray.gradle:gradle-bintray-plugin:$versions.gradle_bintray_plugin"
deps.freeline_gradle_plugin = "com.antfortune.freeline:gradle:0.8.8"
deps.paging = "android.arch.paging:runtime:$versions.paging"
deps.glide = "com.github.bumptech.glide:glide:$versions.glide"
deps.dexmaker = "com.linkedin.dexmaker:dexmaker-mockito:$versions.dexmaker"
deps.constraint_layout = "com.android.support.constraint:constraint-layout:$versions.constraint_layout"
deps.timber = "com.jakewharton.timber:timber:$versions.timber"
deps.junit = "junit:junit:$versions.junit"
deps.runner = "com.android.support.test:runner:$versions.runner"
deps.mock_web_server = "com.squareup.okhttp3:mockwebserver:$versions.mockwebserver"
deps.rxjava2 = "io.reactivex.rxjava2:rxjava:$versions.rxjava2"
deps.rx_android = "io.reactivex.rxjava2:rxandroid:$versions.rx_android"
deps.hamcrest = "org.hamcrest:hamcrest-all:$versions.hamcrest"
deps.gson = "com.google.code.gson:gson:$versions.gson"
deps.okhttp3 = "com.squareup.okhttp3:okhttp:$versions.okhttp3"
deps.nineoldandroids = "com.nineoldandroids:library:$versions.nineoldandroids"
deps.calligraphy = "uk.co.chrisjenx:calligraphy:$versions.calligraphy"

ext.deps = deps

def build_versions = [:]
build_versions.min_sdk = 19
build_versions.target_sdk = 27
build_versions.build_tools = "27.0.3"
ext.build_versions = build_versions

def app_release = [:]
app_release.storeFile = "../keystores/android.keystore"
app_release.storePassword = "xuexiang"
app_release.keyAlias = "android.keystore"
app_release.keyPassword = "xuexiang"

ext.app_release = app_release

//默认添加代码仓库路径
def addRepos(RepositoryHandler handler) {
handler.google()
handler.jcenter()
handler.mavenCentral()
//Add the JitPack repository
handler.maven { url "https://jitpack.io" }
//Add the aliyun repository
handler.maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
//Add the Local repository
handler.maven{ url 'LocalRepository'}
}

ext.addRepos = this.&addRepos


0 comments on commit 05a4cd0

Please sign in to comment.