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.

Dagger Android Tutorial 2

How to do dagger-android

Guowei Lv

3 minute read

In this article we show how to inject into ViewModels. Note that we will not dive too deep into the inner workings of things, since they are extremely complex. If you want to get some level of insight into the topic read this article. But I try to give the clean solution and how you can put it in your head. First a few words about the ViewModel in android MVVM architecture.

Dagger Android Tutorial 1

How to do dagger-android

Guowei Lv

2 minute read

Warning: Google thinks you should avoid dagger-android for new projects. Watch Here But, if you are using it now, here are some notes on how to approach it. This is basically a text version of these videos Application Component Pretty much every app will have an application component, whose scope will be the lifetime of the application. First, create the AppComponent //1. Include this 'AndroidSupportInjectionModule', this is required @Component(modules = {AndroidSupportInjectionModule.