Android Development

Where to Put observeOn in Rxjava2

Where to put observeOn matters!

Guowei Lv

1 minute read

Me: Why I have put the observeOn(AndroidSchedulars.mainThread()) but still onNext() is NOT called in android main thread?! Rx Master: Show me your code. Me: Here you are my master. I just want to wait for 5 seconds then call an api: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) fun networkObservable(): Observable<String> { return Observable.just("test").subscribeOn(Schedulers.io()) } Observable.timer(5, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .flatMap { _ -> networkObservable() } .subscribe(Consumer { Log.d("testtest", it) Log.d("testtest", Thread.

Android Design Pattern - Build a SOLID Image Loader

Develop a image loader guided by design patterns

Guowei Lv

6 minute read

SOLID Principles and Design Patterns play an important role in Android development. Lets take a look at how to design and implement an image loader step by step. This example comes from the book Android Source Code Design Patterns - Analysis and Practice. I also rewrote all the code from Java to Kotlin and made some bug fixes. Step 1: Make it work Requirement: Our first version of image loader will just use in-memory cache to cache images loaded from the Internet, we will ignore cache validation for now.

What the FlatMap?

Understand flatmap in RxJava

3 minute read

The operator flatmap in RxJava is a tough topic if you are not familiar with functional style. After reading all the articles and tutorials and even worked with RxJava for almost a year, I’m still not quite confident about it. I sure know how to and when to use it, but the understanding seems always shallow. Until I read the flatmap in the Structure and Interpretation of Computer Programs.

How to write maintainable RecyclerView

Write maintainable RecyclerView in Android

6 minute read

Google is famous for making complicated things. RecyclerView is not an exception. It is more flexible than the previous ListView I understand, but that also means that us developers need to understand more and do more work. I have seen gigantic adapters that have very complicated logic especially when there are multiple types that the RecyclerView is trying to handle. I think I happen to know one way to organize things a bit better so one can easily find what he/she is looking for.

Customize Android Seekbar Color

How to customize the colors for android seekbar

1 minute read

I was tasked to create a simple media player app for a shop demo, and I’m using the built-in SeekBar for the volume control. All goes well, until I want to change the color of it. The design has it like the thumb of the SeekBar is white, and first half is green and rest half is grey. It took me almost a whole day to find a satisfying anwser, come on Android!