WEBVTT

00:00.120 --> 00:05.200
We created map view model, marker repository and Firebase module.

00:05.240 --> 00:07.640
Now let's move to the Uber clone map.

00:07.920 --> 00:12.360
And inside this composable function we need to test the code.

00:12.360 --> 00:15.640
So testing add marker function.

00:15.680 --> 00:18.680
Start with val view model.

00:18.680 --> 00:26.200
It's of type map view model equals to Hillthe view model Hillthe view model function.

00:26.240 --> 00:33.600
Retrieves the view model instance automatically uses Hillthe to create and inject dependencies into

00:33.600 --> 00:34.000
it.

00:34.040 --> 00:40.640
Makes sure it's tied to the life cycle of the current nav Backstack entry.

00:40.680 --> 00:49.840
Like a screen because you write val view model, it's of type map view model compose knows which view

00:49.880 --> 00:58.120
model you want, which is the map view model, and hilt will find the hilt view model annotation on

00:58.160 --> 00:59.440
map view model.

00:59.480 --> 01:02.510
See what dependencies it needs.

01:02.510 --> 01:06.550
In the constructor, create and inject them.

01:06.550 --> 01:08.910
So back to the map view model.

01:08.950 --> 01:11.870
Here we have the marker repository.

01:12.070 --> 01:20.190
Here it will create this repository and use it in order to make the code work smoothly.

01:20.230 --> 01:27.990
The ViewModel returned is scooped the Composables nav and or navigation graph entry or the parent lifecycle

01:27.990 --> 01:28.510
owner.

01:28.710 --> 01:32.910
So when you navigate away, the ViewModel is cleared.

01:32.950 --> 01:44.110
This line of code tells hilt hey hilt, please give me the map ViewModel for this screen with everything

01:44.270 --> 01:46.150
it needs injected.

01:46.190 --> 01:48.950
Okay, so back to the map ViewModel.

01:49.270 --> 01:53.150
The only thing we need to inject is the marker repository.

01:53.350 --> 02:00.230
This is a very important step in order to create the ViewModel and tell hilt that.

02:00.350 --> 02:09.380
Go and create this function and and create an instance of map ViewModel and injective map marker repository.

02:09.420 --> 02:14.220
Let's call the ViewModel dot add marker.

02:14.260 --> 02:17.140
Here we need to pass four parameters.

02:17.340 --> 02:18.580
Lat long.

02:18.780 --> 02:25.900
This is for San Francisco, the marker name San Francisco on success.

02:25.940 --> 02:28.580
What we need to do handle success.

02:28.620 --> 02:33.940
Exception show an error message alt press enter to import that long.

02:33.980 --> 02:34.900
And here we go.

02:35.100 --> 02:43.620
You can make for example log dot v tag is the tag and marker added successfully.

02:43.660 --> 02:50.140
Okay, this is how we handle the call of ViewModel and creation of it.

02:50.180 --> 02:52.140
Let's test our application.

02:52.140 --> 02:53.140
Run the app.

02:53.300 --> 02:54.060
Here we go.

02:54.300 --> 02:56.220
And the app crashes.

02:56.340 --> 02:58.060
Let's see in the Logcat.

02:58.100 --> 03:01.020
What is the error given component?

03:01.020 --> 03:05.250
Mainactivity doesn't implement Interface dagger.

03:05.650 --> 03:16.130
So what we need to do is going to is to go to main activity class and name it as and mark it as with

03:16.170 --> 03:19.570
Android entry point annotation Alt+.

03:19.570 --> 03:28.610
Enter Android entry point annotation marks and Android framework class so hilt can inject dependencies

03:28.610 --> 03:29.490
into it.

03:29.530 --> 03:34.850
It simply says hey hilt, I want to inject stuff here.

03:35.010 --> 03:43.170
You put Android entry point annotation on any class where you want to inject fields with inject annotation

03:43.210 --> 03:50.810
activities, fragments, services, broadcast receivers, jetpack compose, Composables and others.

03:50.930 --> 03:58.850
So we put it on activities, broadcast receivers, services, fragments and in this case using Jetpack

03:58.850 --> 04:02.050
Compose, we put it in the main activity.

04:02.090 --> 04:09.480
When you add Android entry point annotation health generates code behind the scenes.

04:09.640 --> 04:14.800
It sets up the dependency container for the Android component.

04:15.000 --> 04:21.200
You can now use inject annotation to get dependencies without Android Entrypoint.

04:21.240 --> 04:26.720
Hilt will not work and you'll get an error as I showed you.

04:27.720 --> 04:30.000
Now let's run our application.

04:30.360 --> 04:33.280
Also, the errors persist.

04:33.400 --> 04:35.160
Scroll down and see.

04:35.200 --> 04:37.000
Unable to start activity.

04:37.160 --> 04:38.400
Main activity.

04:38.640 --> 04:45.360
And did you forget to specify your application's class name in your manifests?

04:45.560 --> 04:49.080
So here we need to create the hilt.

04:49.080 --> 04:53.160
Activity must be attached to hilt Android application.

04:53.160 --> 04:56.440
In the next video we're gonna solve this error.
