Einar  Hintz

Einar Hintz

1593438420

Basics of Dagger Hilt and Implementation

In this tutorial, you will be learning about the new Dependency Injection ( DI ) in Android development called “Hilt”, which is built upon Dagger. I know you really want to know what hilt is all about, the benefits and how to implement it in your Android project. Let’s start

NOTE: I won’t be talking about Dependency Injection basics

What is Hilt?

Hilt is an opinionated Dependency Injection library for Android that reduces the boilerplate of using manual DI in your project. Hilt makes it easy to add dependency injection to your Android app.

Hilt provides a standard way to do DI injection in your application by providing containers to every Android component in your project and managing the container’s lifecycle automatically for you.

The Benefits of Hilt

  • Reusability of code.
  • Ease of refactoring.
  • Ease of testing.
  • Reduced boilerplate
  • Decoupled build dependencies
  • Simplified configuration
  • Improved testing
  • Standardized components

Setup

Hilt dependencies

To use Hilt, add the following build dependencies to the Android Gradle module’s build.gradle file:

dependencies {
 def hilt_jetpack = "1.0.0-alpha01"

 // Room
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    // Activity Ktx for by viewModels()
    implementation "androidx.activity:activity-ktx:1.1.0"
    //Dagger - Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_jetpack"
    kapt "androidx.hilt:hilt-compiler:$hilt_jetpack"
    // coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4"
    // ViewModel
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha04'
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
  // For instrumentation tests
  androidTestImplementation  'com.google.dagger:hilt-android-testing:<VERSION>'
  androidTestAnnotationProcessor 'com.google.dagger:hilt-android-compiler:<VERSION>'
  // For local unit tests
  testImplementation 'com.google.dagger:hilt-android-testing:<VERSION>'
  testAnnotationProcessor 'com.google.dagger:hilt-android-compiler:<VERSION>'
}

Then, to use the Gradle plugin in the app module, we specify it in the app/build.gradle file by adding the plugin to the top of the file, below the kotlin-kapt plugin:

...
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {
    ...
}

Now let’s understand some few terms in Hilt that will help you understand it and its implementations, below are a few of the terms.

Let’s build a simple Hilt todo android application using room that will add a todo and also list them

Kindly follow the simple steps to get it up and running.

Step 1:

Create an Entity Class

@Entity(tableName = "todo")
data class Todo(
    @PrimaryKey(autoGenerate = true)
    var id: Int? = null,
    var title: String? = null,
    var description: String? = null
)

Step 2:

Create a DAO

@Dao
interface TodoDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(todo: Todo)
    @Query("SELECT * FROM todo")
    fun getAllTodos(): LiveData<List<Todo>>
}

Step 3:

Create a database

@Database(entities = [Todo::class], version = 1, exportSchema = false)
abstract class AppDb : RoomDatabase() {
    abstract fun todoDao(): TodoDao
}

#androiddev #android-app-development #android

What is GEEK

Buddha Community

Basics of Dagger Hilt and Implementation

How to Convert Dagger-Android to Hilt

The new Hilt library is helping us to apply the _Dependency inversion principle _in the code, and structure it in a layered way. It defines a standard to do Dependency Injection by providing containers for every Android class in the project.

Hilt is created on top of the Android DI library Dagger, so it enjoys the scalability, runtime performance, and all the stuff that Dagger provides. It is also including managing lifecycles in the application automatically. Hilt library integrates Jetpack and Android framework classes. It removes most of the boilerplate code because the developer has bigger fish to fry - like defining and injecting bindings, but without managing the Dagger setup. Keep in mind that Hilt is still in alpha!

Note:Here I’ll focus on converting the **dagger-android **library to Hilt.


Our starting point will be build.gradle(:app) file - so, go back to the drawing board:

//Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

// Hilt ViewModel extension
    def hilt_jetpack_version = "1.0.0-alpha01"
    implementation "androidx.hilt:hilt-lifecycle- viewmodel:$hilt_jetpack_version"
    kapt "androidx.hilt:hilt-compiler:$hilt_jetpack_version"

// Hilt testing dependencies
    androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
    kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version"
    kaptAndroidTest "androidx.hilt:hilt-compiler:$hilt_jetpack_version"

#dagger-android #android #kotlin #dagger-hilt #dagger

Oda  Shields

Oda Shields

1625223360

Weather App with MVVM, Coroutine, LiveData, Retrofit 2 & Dagger-Hilt

Source Code: https://github.com/IsaiasCuvula/weather_app
Link: https://github.com/robertoduessmann/weather-api

Subscribe for more: https://www.youtube.com/channel/UChCgMnyGKOgEGDvubbjjr6A

Thanks for watching, leave a like, leave a comment…
Don’t forget to subscribe to the channels and click on the bell to activate notifications!

Website ----- https://www.bersyte.com/
Twitter ----- https://twitter.com/ICuvula
Instagram ----- https://www.instagram.com/isaias_cuvula/
My App ---- https://play.google.com/store/apps/details?id=com.bersyte.berlist

#Bersyte #AndroidDev #Kotlin

#dagger-hilt #livedata, #mvvm #oroutine #retrofit 2 & dagger-hilt

Tamia  Walter

Tamia Walter

1596260400

A Brief Intro to Dagger Hilt

**Dependency injection (DI), **in a nutshell, is a technique whereby one object provides or supplies the dependencies of another instead of creating it by themselves. This will let you have good architecture for your application and better code reusability.

In Android, Dagger is the dependency injection library that is recommended by Google for dependency injection. But let’s face it, there are a lot of overheads when setting up Dagger that beginners might shy away from.

This is where Dagger Hilt for Android comes in.

What is Dagger Hilt?

Hilt, built on top of Dagger, is now the new recommended DI library from Google which would help to simplify setting up Dagger in your applications.

The previous Components that we created in our app, exists now in the predefined components that are being provided to us, out of the box, by Hilt. So we won’t need to define these directly. The built-in components are also automatically integrated into the lifecycle of your app, which is really neat.

To check out these components, take a look here.

The Setup

We first need to add the following to our project level build.gradle

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'

Then in our module level build.gradle

apply plugin: 'dagger.hilt.android.plugin'

Finally, we can now add the required dependencies for us to use Hilt

implementation 'com.google.dagger:hilt-android:2.28-alpha'
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01'

When everything is synced up, we now need to annotate our application class with @HiltAndroidApp, this will generate the different Hilt components along with the base class of our application.

For our Activity/Fragment we would annotate it with@AndroidEntryPoint, this will generate the required component that will receive the dependencies that are going to be injected in our Activity/Fragment.

In cases that we have a class that has a required constructor argument

class SampleClass (val anotherSampleClass: AnotherSampleClass) {}

We can use Hilt modules to inject the required argument. Take a look at the sample below.

@Module
@InstallIn(ActivityComponent::class)
class SampleModule {

  @Provides
  fun provideAnotherSampleClass(...: ...) = AnotherSampleClass(...)
}

#dagger-hilt #android #dagger #android-app-development

Biju Augustian

Biju Augustian

1574339995

Learn Python Tutorial from Basic to Advance

Description
Become a Python Programmer and learn one of employer’s most requested skills of 21st century!

This is the most comprehensive, yet straight-forward, course for the Python programming language on Simpliv! Whether you have never programmed before, already know basic syntax, or want to learn about the advanced features of Python, this course is for you! In this course we will teach you Python 3. (Note, we also provide older Python 2 notes in case you need them)

With over 40 lectures and more than 3 hours of video this comprehensive course leaves no stone unturned! This course includes tests, and homework assignments as well as 3 major projects to create a Python project portfolio!

This course will teach you Python in a practical manner, with every lecture comes a full coding screencast and a corresponding code notebook! Learn in whatever manner is best for you!

We will start by helping you get Python installed on your computer, regardless of your operating system, whether its Linux, MacOS, or Windows, we’ve got you covered!

We cover a wide variety of topics, including:

Command Line Basics
Installing Python
Running Python Code
Strings
Lists
Dictionaries
Tuples
Sets
Number Data Types
Print Formatting
Functions
Scope
Built-in Functions
Debugging and Error Handling
Modules
External Modules
Object Oriented Programming
Inheritance
Polymorphism
File I/O
Web scrapping
Database Connection
Email sending
and much more!
Project that we will complete:

Guess the number
Guess the word using speech recognition
Love Calculator
google search in python
Image download from a link
Click and save image using openCV
Ludo game dice simulator
open wikipedia on command prompt
Password generator
QR code reader and generator
You will get lifetime access to over 40 lectures.

So what are you waiting for? Learn Python in a way that will advance your career and increase your knowledge, all in a fun and practical way!

Basic knowledge
Basic programming concept in any language will help but not require to attend this tutorial
What will you learn
Learn to use Python professionally, learning both Python 2 and Python 3!
Create games with Python, like Tic Tac Toe and Blackjack!
Learn advanced Python features, like the collections module and how to work with timestamps!
Learn to use Object Oriented Programming with classes!
Understand complex topics, like decorators.
Understand how to use both the pycharm and create .py files
Get an understanding of how to create GUIs in the pycharm!
Build a complete understanding of Python from the ground up!

#Learn Python #Learn Python from Basic #Python from Basic to Advance #Python from Basic to Advance with Projects #Learn Python from Basic to Advance with Projects in a day

Oda  Shields

Oda Shields

1625650140

Retrofit 2 with Dagger-Hilt for dependency injection. MVVM, Coroutine, LiveData & @ GET,..

Source code: https://github.com/IsaiasCuvula/retrofit_dagger_hilt_mvvm_live_data_coroutine

Subscribe for more: https://www.youtube.com/channel/UChCgMnyGKOgEGDvubbjjr6A

Thanks for watching, leave a like, leave a comment…
Don’t forget to subscribe to the channels and click on the bell to activate notifications!

Website ----- https://www.bersyte.com/
Twitter ----- https://twitter.com/ICuvula
Instagram ----- https://www.instagram.com/isaias_cuvula/
My App ---- https://play.google.com/store/apps/details?id=com.bersyte.berlist

#Bersyte #Kotlin #AndroidDev

#dagger-hilt #mvvm #coroutine #livedata #get