Giter Site home page Giter Site logo

amitshekhariitbhu / rxjava2-android-samples Goto Github PK

View Code? Open in Web Editor NEW
5.0K 187.0 1.1K 494 KB

RxJava 2 Android Examples - How to use RxJava 2 in Android

Home Page: https://amitshekhar.me

License: Apache License 2.0

Java 100.00%
rxjava android rxjava2 rxandroid example sample tutorial tutorials examples samples

rxjava2-android-samples's Introduction

Learning RxJava 2 for Android by example

This project is for :

  • who is migrating to RxJava 2
  • or just started with RxJava.

About me

Hi, I am Amit Shekhar, I have mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

You can connect with me on:

My Personal Blog - amitshekhar.me - High-quality content to learn Android concepts.

Just Build the project and start learning RxJava by examples.

RxJava 2.0 has been completely rewritten from scratch on top of the Reactive-Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries.

Using RxJava 2.0 Library in your application

Add this in your build.gradle

compile 'io.reactivex.rxjava2:rxjava:X.X.X'

If you are using RxAndroid also, then add the following

compile 'io.reactivex.rxjava2:rxandroid:X.X.X'

RxJava 2 Operators Examples present in this sample project:

  • Map -> transform the items emitted by an Observable by applying a function to each item. Blog: RxJava Operator Map vs FlatMap
  • Zip -> combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function
  • Filter -> emit only those items from an Observable that pass a predicate test
  • FlatMap -> transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable. Blog: RxJava Operator Map vs FlatMap
  • Take -> emit only the first n items emitted by an Observable. Blog for reference
  • Reduce -> apply a function to each item emitted by an Observable, sequentially, and emit the final value
  • Skip -> suppress the first n items emitted by an Observable
  • Buffer -> periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a time
  • Concat -> emit the emissions from two or more Observables without interleaving them. Blog for reference
  • Replay -> ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting items
  • Merge -> combine multiple Observables into one by merging their emissions
  • SwitchMap -> transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable

Highlights of the examples :

Find this project useful ? ❤️

  • Support it by clicking the ⭐ button on the upper right of this page. ✌️

Thanks

Amit Shekhar

You can connect with me on:

Read all of my blogs here.

License

   Copyright (C) 2022 Amit Shekhar

   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.

Contributing to RxJava 2 Android Samples

Just make pull request. You are in!

rxjava2-android-samples'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

rxjava2-android-samples's Issues

Simple Real-world app example

Hi
Great work you have done here. If possible can you include a real-world app example for clearer picture of RXJava2 can do? News feed reader maybe?

Thanks

Course Typo

qq 20171011153408

I don't known whether it's a typo as the arrow I point ?
I think it is subscriber and not publisher need to be handled,it is right ?

thx

pagination with Fast Networking

Hi @amitshekhariitbhu !
i want to use pagination example with Fast Networking. but it does not work.could you create an example for this demo.thanks
this is my code:
private void subscribeForData() {
Disposable disposable = paginator
.onBackpressureDrop()
.concatMap(new Function<Integer, Publisher<List>>() {
@OverRide
public Publisher<List> apply(@nonnull final Integer page) {
loading = true;
progressBar.setVisibility(View.VISIBLE);
return dataFromNetwork(page);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List>() {
@OverRide
public void accept(@nonnull List items) {
paginationAdapter.addItems(items);
paginationAdapter.notifyDataSetChanged();
loading = false;
progressBar.setVisibility(View.GONE);
}
});
compositeDisposable.add(disposable);
paginator.onNext(pageNumber);
}
private Flowable<List> dataFromNetwork(int page) {
return Rx2AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", String.valueOf(page))
.addQueryParameter("limit", "10")
.build()
.getObjectListFlowable(User.class);
}

Could you please add a complicated event bus(rxbus/rxbroadcast) sample?

Like Music Player
steps:
step1(listen to audio headphone jack plug in/plug out by system broadcast receiver)
step2(open Music Player Activity/view when head jack plugged in)
step3.1(listen to Play Button to Play Music | change to play UI(set textview1 to "play music"))
step3.2(listen to Pause Button to Pause Music | change to pause UI (set textview2 to "pause music"))
step4(when headphone jack plug out to Stop Music | change to stop UI (set textview3 to "stop music"))

In SearchActivity error?

When I click on keyboard button "actionSearch" observer call "onComplete" and observable do not react on text changed event.

flowable and singleobserver

Hello, thank you for your perfect repo, but I have a question about Flowable, why did you use SingleObserver with Flowable maybe there is no error but I think logically is not correct because Flowable introduced for supporting backpressure and singleObserver introduced for single observable.Do you agree?

ThrottleFirstExampleActivity注释写错了

private Observable getObservable() {
return Observable.create(new ObservableOnSubscribe() {
@OverRide
public void subscribe(ObservableEmitter emitter) throws Exception {
// send events with simulated time wait
//下面的注释是作者原注释,我觉得不太对,因为这个运行的结果是1,3,7被发送出来了
Thread.sleep(0);
emitter.onNext(1); // skip
emitter.onNext(2); // deliver
Thread.sleep(505);
emitter.onNext(3); // skip
Thread.sleep(99);
emitter.onNext(4); // skip
Thread.sleep(100);
emitter.onNext(5); // skip
emitter.onNext(6); // deliver
Thread.sleep(305);
emitter.onNext(7); // deliver
Thread.sleep(510);
emitter.onComplete();
}
});
}
下面的注释应该是ThrottleLast的结果,和ThrottleFirst的不符

In ReplayExampleActivity,the repaly error?

The log is :
First onSubscribe : false
First onNext value : 1
First onNext value : 2
First onNext value : 3
First onNext value : 4
First onComplete
Second onSubscribe : false
Second onNext value : 1
Second onNext value : 2
Second onNext value : 3
Second onNext value : 4
Second onComplete

It is different from the comment "it will emit 2, 3, 4 as (count = 3), retains the 3 values for replay"

Thread Interrupted

Any idea how to handle "thread interrupted"?

This happens due to calling the instant search api!

Thank you.

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.