Previous post we set up the so called Pure Dependency Injection. Now let’s replace that with Dagger2 balantly.
Convert the composition roots into dagger’s @Modules.
Create @Component to hold each @Module.
Create @Scopes and use it to scope the objects we want only 1 instance in the component.
Now it looks like this:
This series of posts are my summary notes from the online course Dependency Injection in Android with Dagger 2 and Hilt.
I do believe if you have any doubts about Dagger2 in Android, run to get that course and watch it 3 times, I bet you will be better than 90% of the android developers on the market on this topic.
The first 1/3 of the course introduces the so called Pure Dependency Injection, which means not using any library like Dagger.
Often in project we want to declare some time constants, like
companion object { const val INTERVAL = 5 * 60 // 5 minutes } This is fine, but can we do better in Kotlin? What I want is this 5 minutes in seconds or 8 days in hours, and it is not hard to achieve it actually.
infix fun Number.daysIn(unit: TimeUnit): Long = daysFn(this, unit) infix fun Number.hoursIn(unit: TimeUnit) = hoursFn(this, unit) infix fun Number.
The old is the new new.
I really love 8-bit games, why not try to learn how to develop them? The best time to do this is when I was 10 years old after I got my first NES console, the second best time is now. So here we are, I’m documenting all the learning along the way in this blog.
First, let’s setup the dev environment.
Machine Here is the machine that I’m using for this, my newly acquired ThinkPad T60, with Zorin 32bit version installed.
Let’s build a sliding menu from scratch by hand.
First a glimpse of what the final result looks like.
Step 1: Horizontal Scroll View The secret is that this is just a customized HorizontalScrollView:
class SlidingMenu @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : HorizontalScrollView(context, attrs, defStyleAttr) { … } The view can be divided into 2 parts: menu view and content view, and they are just put next to each other.