Building a Crypto Tracker with Kotlin in Android (Part 2)
What Will I Learn?
- You will learn how to implement and use Dagger 2 in Android with Kotlin
- You will learn how to use Android Shared Preferences to build a key-value data store
- You will learn how to use OkHttp3 and Retrofit with Kotlin
Requirements
- Android Studio 3.0 or Android Studio Canary
- A basic understanding of the Android ecosystem
- A fair understanding of Kotlin or the Java programming language
Difficulty
- Intermediate
Description
In this second video tutorial, we continue to build out our Cryptocurrency Tracker Application with Kotlin in Android. First, we start by creating a small Key-Value store using the Android Shared Preferences class library. This is a fairly light document storage option that exists as a native library in the Android ecosystem. It allows us to store our Cryptocurrency data in small documents on the user's device.
We build out an abstract class to use as a skeleton mold for the rest of our activities in this application. Using abstract classes in this way has various advantages and it allows us to save code and avoid boilerplate by letting us implement super methods in one place. We also create abstract functions to initialize the injection of data, the setup of our layouts and the inflation of our views.
We create a few dagger dependency injection modules and a dagger component which implements these modules. These modules allow us to define a bunch of singleton objects that let us serve consistent state across all of the activities in our application. We make use of the OkHttp3 client to handle Http Requests and Responses, create a cache as well as build out a connection pool. We then also add on the Retrofit client to call a GET method on the coinmarketcap API and serve the response data as GSON objects to our parcelable data model.
The resulting providers are then added to our component which implements a function that allows us to inject them into our main activity. Dagger 2 generates code that gives the injected classes access to these providers and their state. The Dependency Injection Pattern will allow us to easily implement the other activities in our Application and give them these features.
The source code for this project can be found here
Video Tutorial
Curriculum
Related Content
- Android Applications in Kotlin
- Desktop Applications in Kotlin
- Intro to Kotlin Series
- Intro to Kotlin (Basic Types, Type Inference, Casting and Strings)
- Intro to Kotlin (Basic Operations and Collections)
- Intro to Kotlin (Control Flow and Conditionals)
- Intro to Kotlin (Functions in Kotlin)
- Intro to Kotlin (Advanced Functions)
- Intro to Kotlin (Classes, Visibility Modifiers, Objects)
- Intro to Kotlin (Nullables, Data Classes, Enum Classes and Sealed Classes)
- Intro to Kotlin (Interfaces, Inheritance, Type Alias and Abstract Classes)
Posted on Utopian.io - Rewarding Open Source Contributors
Being A SteemStem Member
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank you for your hard work.
@tensor, No matter approved or not, I upvote and support you.
Thank you for that, it is a little disconcerting however that you posted this 1 minute after I posted this video and content which means you didn't read it.
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Tensor from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
Hey @tensor I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x