Building a Crypto Tracker with Kotlin in Android (Part 3)
What Will I Learn?
- You will learn how to make various complex UI elements in Android with XML
- You will learn how to use dependency injection to create an activity with Android
- You will learn how to make a reactive splash screen activity in an Android Application 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 tutorial, we build out all of our XML layouts and we setup our splash screen activity using dependency injection. Seven different layouts were created for this application. We have a main skeleton layout which uses a Recycler View to hold all of the coin item components inside of it as a scrolling list. We then create our coin item components and an extended coin item component which will be used to display all of the data that we are bringing in from the API. These items use text views and linear layouts to mark each data field with a tag. We create two dialog boxes, one for a settings menu and another to allow the user to close out of the application in a clean way. We also create a splash screen activity layout which has a large image view on it and the title. The final layout in this application is just a smaller header layout which will serve as a title layout.
Having created our layouts, we then create the classes and interface needed for our Splash Screen activity. We create an interface for to implement functions that will either go forward to the Home Activity or present an error message to the user based on the internet connectivity of the device. If there is no network connection, the application will stay on the splash screen and a Snackbar will open at the bottom. This Snackbar will alert the user that there is no internet connection and it will allow the user reload the application.
Because we are using the dependency injection pattern in this application, we implement our activities in such a way that they are injected into the main activity based on the context of the application at a given moment. When the application starts, the splash screen is passed in as the main activity and it is swapped out with the home activity if we have network connectivity. In this way, it is also very easy for us to provide data to our activities from other areas of the application. We inject the main resource providers into the main activity and then inject the sub activities into the main activity as well. The application compiles and runs until it requests the main activity, which will be created in the final tutorial. If we disable the network connection on the device, then the application will not crash because the home activity is never requested.
The source code for this project can be found here
Video Tutorial
Curriculum
- Building a Crypto Tracker with Kotlin in Android (Part 1)
- Building a Crypto Tracker with Kotlin in Android (Part 2)
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
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
That was very fast. Thank you for your hard work.
Hey @ewq, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
This is a test comment, notify @kryzsec on discord if there are any errors please.
Being A SteemStem Member
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