Giter Site home page Giter Site logo

rxbinding's Introduction

RxBinding

RxJava binding APIs for Android UI widgets from the platform and support libraries.

Download

Platform bindings:

implementation 'com.jakewharton.rxbinding4:rxbinding:4.0.0'

AndroidX library bindings:

implementation 'com.jakewharton.rxbinding4:rxbinding-core:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-appcompat:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-drawerlayout:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-leanback:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-recyclerview:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-slidingpanelayout:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-swiperefreshlayout:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-viewpager:4.0.0'
implementation 'com.jakewharton.rxbinding4:rxbinding-viewpager2:4.0.0'

Google 'material' library bindings:

implementation 'com.jakewharton.rxbinding4:rxbinding-material:4.0.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright (C) 2015 Jake Wharton

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.

rxbinding's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxbinding's Issues

Restore null checks. Auto-generate null check unit tests.

The support annotations are too easily fooled. Let's restore all the null checking.

In addition, the build plugin should be augmented to generate unit tests for every method that has a @NonNull annotation where it verifies that passing null throws a NullPointerException with a message of foo == null where "foo" is replaced with the name of the argument.

java.util.NoSuchElementException: No event found while waiting for OnNext

5 tests fail. The errors are all similar.

java.util.NoSuchElementException: No event found while waiting for OnNext
at com.jakewharton.rxbinding.RecordingObserver.takeEvent(RecordingObserver.java:40)
at com.jakewharton.rxbinding.RecordingObserver.takeNext(RecordingObserver.java:48)
at com.jakewharton.rxbinding.widget.RxAdapterViewTest.itemSelections(RxAdapterViewTest.java:49)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:257)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:228)

Do I miss something?

Plugin expansion to add factory method structure checks.

Expand the buildSrc plugin to verify certain commonalities to these factory methods:

  • @CheckResult on method
  • @NonNull on method (#20)
  • @NonNull on all parameters (#20)
  • Action1 return types use a wildcard bound (? super Integer)
  • Second parameters which are a Func1 use a wildcard for first parameterized type (? super ViewEvent)

RxDialog oneliners

For your Q&D needs, it is possible to spin an observable dialog in a single line. This is helpful to quickly create a picker for yes/no, date, number, decimal or single element in a list. i.e. button click flatmap into confirmation dialog flatmap into execute action.

Is that within scope of this library, or as a helper would it live outside?

RxView.bindView(View view, Observable<T> source)

When I updated to RxAndroid 1.0.0 I missed ViewObservable.bindView(View view, Observable<T> source). Will it be added here? Is there another way I'm not seeing to replace this API?

https://github.com/ReactiveX/RxAndroid/blob/4bff437edfa24dde62c90d44b019b9a35855db6a/rxandroid/src/main/java/rx/android/view/ViewObservable.java

I often used a combination of this to attach observables to items in my adapters.

ViewObservable.bindView(myView, Observable.interval(500, TimeUnit.MILLISECONDS))
        .subscribe(/* do something with myView */);

Manually unsubscribing looks like unnecessary extra effort.

"Generic" View Actions?

I am sure this has been discussed in the past, but I could not find any reference to it. The proposal is to provide a way for "generic" Actions to be so that any custom View is already Rx-ready as long as it follows certain naming conventions. I have in mind something along the lines of:

 /**
   * An action which sets the specified property of {@code view}. The View is expected to have a setter of the form set[propertyName] in camel-case.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
   * to free this reference.
   */
  public static Action1<?> property(final View view, final String prop) {
    checkNotNull(view, "view == null");
    return new Action1<Object>() {
      @Override public void call(Object value) {
        final Method method = view.getClass().getDeclaredMethod(Utils.getMethodNameForProperty(prop), new Class[]{value.getClass()});
        method.invoke(view, value);
      }
    };
  }

Some observations about this in no particular order:

  • A useful way to bind any property of any custom View to some value
  • Roughly comparable to utilities available in ReactiveCocoa (example - RAC() macro) although the language capabilities are a whole lot different in these two cases
  • Reflection! Ugly, not type-safe.
  • That requirement about having a setter for the property - again not pretty ... ...
  • ... ... but, you probably already follow it if you are using the Property Animation framework (does this use reflection too BTW?Just curious)

RxSeekBar flaky test on CI

com.jakewharton.rxbinding.widget.RxSeekBarTest > changeEvents[test(AVD) - 4.3] FAILED 
    java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
    at android.os.Parcel.readException(Parcel.java:1431)
com.jakewharton.rxbinding.widget.RxSeekBarTest > changes[test(AVD) - 4.3] FAILED 
    java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
    at android.os.Parcel.readException(Parcel.java:1431)

Script to generate kotlin bindings.

The Kotlin bindings are fun, but are completely mechanical in how they are created. There's no reason they should be created by hand and doing so is an error-prone endeavor. Write a script that parses the Java declarations and automatically generates them for all modules. Care must be taken for all the variations of things like Javadoc, generics, and multiple arguments.

Representative sample of some sort.

  • Use Toolbar, react to action item presses.
  • Use SwipeRefreshLayout, react to pull-to-refresh
  • Use EditText, react to text typing
  • Use TextViews, bind text to a composite stream

This, or some handful of our operators, should be combined in a representative sample to showcase the ease of binding and composition afforded by these APIs to solve complex interaction problems.

Other support libs

Any plans (or are you open) to support other modules as well? Specifically looking at appcompat, recyclerview, and the design lib.

Why Action1<? super Throwable> ? instead of Action1<Throwable>

Why not this method just return Action1<Throwable> ?
I don't understand it, can anybody explain it for me? Thanks!
https://github.com/JakeWharton/NotRxAndroid/blob/5c0ba7dff90aa69b936059d6c35e6c2b23370900/rxandroid/src/main/java/rx/android/util/RxLog.java#L55

  public static Action1<? super Throwable> error(final String tag, final String message) {
    checkNotNull(tag, "tag == null");
    checkNotNull(message, "message == null");

    final RxAndroidLogHook logHook = RxAndroidPlugins.getInstance().getLogHook();
    return new Action1<Throwable>() {
      @Override public void call(Throwable throwable) {
        logHook.log(Log.ERROR, tag, message, throwable);
      }
    };
  }

Scroll views support

I have a fork which implements scroll events for ScrollView and HorizontalScrollView.
Since it requires the use of subclasses of these (because there is no listener interface for scroll events in the system classes), it felt of limited use and I didn't think of integrating it upstream.

It is pretty convenient though, and as I was thinking of extracting it to its own project with a dependency on RxBinding (easier maintenance), I thought I'd check first if there would be any value in merging it here.

Why RxSeekBar.changeEvents return SeekBarChangeEvent

Why this method return SeekBarChangeEvent instead SeekBarProgressChangeEvent?
SeekBarProgressChangeEvent is created after all so I see no reason why?

As a temporary workaround I use Observable.cast operator, but this is right behavior?

Release Kotlin snapshot

It appears that only the Java artifacts have been released to the snapshot repo. Do you plan to release the Kotlin version to snapshots as well?

Allow HandlerScheduler to run immediately if on the correct thread

Great to see the ideas in this project! I wanted to submit one more idea for feedback:

By default, the HandlerScheduler always calls postDelayed, even if delayTime <= 0 && Looper.myLooper() == handler.getLooper().

I've found it useful to have a scheduler that behaves more like Schedulers.immediate() in this scenario. The main benefits are immediate execution with no delay (nothing to schedule) and preservation of the call stack when debugging.

There's already enough hooks to swap out the default scheduler, but I'd be curious to see if anybody else finds this idea valuable and if it would be reasonable to make it the default behavior.

API 14

Back with this again, sorry again :/

All the current tests pass whenever I try with API 14, and I can't find any significant UI changes between 14 and 15 that would impose a limitation on this library in the future.

Totally understand if you'd rather not though, just putting it up for consideration!

Rename HandlerSchedulers into AndroidSchedulers?

Probably, AndroidSchedulers is better name for factory of Rx Schedulers for Android App than HandlerSchedulers. Yes, internally these Schedulers use Handler but it's just an implementation detail.

Also, AndroidSchedulers is already well known brand class by RxAndroid community, users and even those who don't use RxAndroid, but has seen tons of examples in the internet, so new API won't be so "breaking" for them (I won't be surprised if most of RxAndroid users use only schedulers).

rxMenuItem

Noticed that there isn't any support for MenuItem's. If this has slipped your mind then let this issue serve as a helpful reminder, else remove.

Error:Failed to resolve: rxbinding-root:rxbinding:unspecified

When I Setting at Android Studio.

dependencies {
 ...
   'com.jakewharton.rxbinding:rxbinding:0.1.0'
   'com.jakewharton.rxbinding:rxbinding-support-v4:0.1.0'
}

Error occur. right this.

Error:Failed to resolve: rxbinding-root:rxbinding:unspecified

how to fix it?

RxTextView.textChanges emits mutable CharSequence

RxTextView.textChanges(searchEditText)
          .delay(2, TimeUnit.SECONDS)
          .subscrite(
              ret -> {}
          )

I bind the text changes event with a edittext widget. When I input some text to the edittext quickly, the ret always be the string that is the final text I writing. I think it's wrong.

In my opinion, the ret will be the sequences which I write.

Add Javadoc about set vs. add methods

There should be a warning on each method about which can only be applied to a view once (those which use setters behind the scenes) vs. those which can be applied multiple times (those which use add/remove behind the scenes).

RxTextView.textChangesWithBefore

New to RxJava and RxBinding, I started out by doing some user input validation previously implemented via TextWatcher. I realized while attempting to leverage the filter operator that the Observable returned from RxTextView.textChanges only emits the new text. Would it be beneficial to add a similar Observable that also emitted the before value (from TextWatcher#beforeTextChanged)?

Why minSdkVersion 15?

Is there any important reasons for 15 api version as minimum?
RxAndroid 0.24.0 worked well with 9 api level.

Samples

Can you share some sample to this library?

Expose view properties as subjects?

Case study: The checked-ness of a CompoundButton.

We currently have two methods, one for reading and one for writing (RxCompoundButton.checkedChanges and RxCompoundButton.setChecked, respectively). These are two halves of the same coin which could potentially be more easily represented in a property-like fashion of Subject<Boolean, Boolean>. This would allow a single point of observation and subscription.

Currently there are two overloads for all property reads: one which observes a zero or one allocation value (e.g., the Boolean checked-ness in this example) and one which wraps all emissions in an event object (e.g., CheckedChangedEvent in this example). This would mean that we'd actually need two overloads for the property, Subject<Boolean, Boolean> and Subject<CheckedChangedEvent, Boolean> which is slightly unfortunate (but certainly no more than it currently is).

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.