Functional Programming
is a model of programming that transform and compose stream of immutable sequences by applying map, filter and reduce. Events are immutable because you can't change history.Reactive Programming
is a model of programming focuses on data flow and change propagation.ReactiveX
is an API that focuses on asynchronous composition and manipulation of observable streams of data or events by using a combination of the Observer pattern, Iterator pattern, and features of Functional Programming.RxJava
is the open-source implementation ofReactiveX
in Java.RxJava
is a Java VM implementation ofReactiveX
(Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.RxAndroid
is a lightweight extension to RxJava that providers a Scheduler for Android’s Main Thread, as well as the ability to create a Scheduler that runs on any given Android Handler class.- The two main classes are
Observable
andSubscriber
. - `O
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Subscription emailSubscription = | |
emailChangeObservable | |
.doOnNext(new Action1<CharSequence>() { | |
@Override | |
public void call(CharSequence charSequence) { | |
hideEmailError(); | |
} | |
}) | |
.debounce(400, TimeUnit.MILLISECONDS) | |
.filter(new Func1<CharSequence, Boolean>() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object EmailUtils { | |
fun getEmailIntent(context: Context): Intent { | |
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")) | |
val bodyText = getEmailBody(context) | |
val emailAddy = EMAIL_SUPPORT | |
val subject = context.resources.getString(R.string.email_subject) | |
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(emailAddy)) | |
intent.putExtra(Intent.EXTRA_SUBJECT, subject) | |
intent.putExtra(Intent.EXTRA_TEXT, bodyText) | |
return intent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.getsomeheadspace.android.foundation.utils | |
// https://proandroiddev.com/briefly-about-rxjava-logging-20308b013e6d | |
import io.reactivex.* | |
import timber.log.Timber | |
inline fun <reified T> printEvent(tag: String, success: T?, error: Throwable?) = | |
when { | |
success == null && error == null -> Timber.d("$tag Complete") /* Only with Maybe */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RxImageView extends ImageView { | |
// region Member Variables | |
private PublishSubject<Boolean> publishSubject = PublishSubject.create(); | |
// endregion | |
// region Constructors | |
public RxImageView(Context context) { | |
super(context); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RoundedBitmapDrawableUtility { | |
public static RoundedBitmapDrawable getRoundedSquareBitmapDrawable(Context context, Bitmap originalBitmap, int cornerRadius){ | |
return getRoundedSquareBitmapDrawable(context, originalBitmap, cornerRadius, -1, -1); | |
} | |
public static RoundedBitmapDrawable getRoundedSquareBitmapDrawable(Context context, Bitmap originalBitmap, int cornerRadius, int borderWidth, int borderColor){ | |
int originalBitmapWidth = originalBitmap.getWidth(); | |
int originalBitmapHeight = originalBitmap.getHeight(); |
while true; do
./adb shell input swipe 100 400 4000 400 400;
done
- A
dependency
is a coupling between two classes usually because one of them uses the other to do something. Dependency injection
consists of passing dependencies (inject them) via constructor in order to extract the task of creating modules out from other modules. Objects are instantiated somewhere else and passed as constructor attributes when creating the current object.- A
dependency injector
is another module in our app that is in charge of providing instances of the rest of modules and inject their dependencies. It's responsibility is the creation of modules is localized in a single point in our app, and we have full control over it. Dagger
is a dependency injector designed for low-end devices. Most dependency injectors rely on reflection to create and inject dependencies. Reflection is very time consuming on low-end devices, and specially on old android versions. Dagger, however, uses a pre-compiler that creates all the classes it needs to work. That way, no reflection is needed. Dagger is
-
http://engineering.rallyhealth.com/mobile/rxjava/reactive/2017/03/15/migrating-to-rxjava-2.html
-
https://blog.mindorks.com/migrating-from-rxjava1-to-rxjava2-5dac0a94b4aa
-
https://blog.kaush.co/2017/06/21/rxjava1-rxjava2-migration-understanding-changes/
-
http://www.nurkiewicz.com/2017/08/1x-to-2x-migration-observable-vs.html
-
https://caster.io/lessons/rxjava-2-migrating-your-first-stream-from-rxjava-1/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomTextView extends AppCompatTextView { | |
public CustomTextView(Context context) { | |
super(context); | |
init(context,null); | |
} | |
public CustomTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(context, attrs); | |
} |