Realm Guide: From Zero to Give Up

Curated list of realm learning resources

Guowei Lv

1 minute read

You know nothing about realm, then watch this video first -> Now you should know the basic basics, then take a look at the official doc. You think you know it all until you try to combine with RxJava. Now you are super puzzled, look at some examples with full source code. Finally you realize that you have to do all this in clean architecture and decided to give up by turning Realm into a NoSQL version SQLite.

Guowei Lv

2 minute read

In this article we talk about drawing text. Let’s see how to implement a view which simply displays some text. Let’s call it MyTextView. This is how it will look like: <!– Omitted constraintlayout related stuff–> <com.example.MyTextView.MyTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:background="@color/colorAccent" app:myTextColor="#000000" app:myText="Hello World! My love!" app:myTextSize="24sp" /> Let’s first define the custom attributes of the view, in values/attrs.xml <resources> <declare-styleable name="MyTextView"> <attr format="string" name="myText" /> <attr format="color" name="myTextColor" /> <attr format="dimension" name="myTextSize" /> </declare-styleable> </resources> Then in the MyTextView.

Guowei Lv

5 minute read

In this article we talk about animation, specifically property animation. ViewPropertyAnimator View has many properties, like position on screen, color and size. Property animation is the type of animation that animate on those properties. In other words, the animator’s job is to set a specific set of properties of the view to different values many many times in a short period of time. For example, the following code will move the view’s position 500px to the right:

Dagger Android Tutorial 4

How to do dagger-android

Guowei Lv

2 minute read

Convert RxJava stream into LiveData stream When we use Rxjava for handling api requests, it will return a RxJava Stream. But in the presentation layer we are using LiveData, this article shows you how to make them work together. The tool we are using here is LiveDataReactiveStreams. It is an adapter from LiveData to ReactiveStream and vice versa. This is how we do it in AuthViewModel. public class AuthViewModel extends ViewModel { private static final String TAG = "AuthViewModel"; private final AuthApi authApi; // 1.

Dagger Android Tutorial 3

How to do dagger-android

Guowei Lv

1 minute read

Inject Retrofit @Singleton The Retrofit instance should be a singleton in the scope of AppComponent. Provide the Retrofit instance in AppModule. @Singleton @Provides static Retrofit provideRetrofitInstance() { return new Retrofit.Builder().baseUrl(Constants.BASE_URL) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()).build(); } Under AuthActivity subcomponent, create a module called AuthModule, in it, provides the AuthApi instance. @Module public class AuthModule { @Provides static AuthApi provideAuthApi(Retrofit retrofit) { return retrofit.create(AuthApi.class); } } public interface AuthApi { @GET("/users/{id}") Flowable<User> getUser(@Path("id") int id); } @ContributesAndroidInjector(modules = {AuthModule.