WEBVTT

00:00.040 --> 00:00.920
Welcome back.

00:00.960 --> 00:03.320
We finished from Uber Clue map.

00:03.320 --> 00:10.120
We created the box that contains Google Map, expandable fab and disappearing scale bar Composables.

00:10.160 --> 00:13.600
Now let's move to the Firebase section.

00:13.600 --> 00:20.400
We need to create Firebase Firestore database that stores markers.

00:20.400 --> 00:28.200
So when the user requests a ride his current location will be uploaded to the markers collection in

00:28.200 --> 00:30.280
Firebase Firestore database.

00:30.560 --> 00:38.440
Then received and retrieved by the driver in order to display the markers for the driver.

00:38.440 --> 00:43.720
So we have two types the driver and the user or a customer okay.

00:43.920 --> 00:47.560
So we have two types of permissions or users.

00:47.600 --> 00:54.480
The customer the the one who need a drive driver and the driver itself okay.

00:54.680 --> 01:01.900
So we need to upload the marker to Firebase Firestore following the MVVM architecture we're going to

01:01.900 --> 01:06.060
start with the new package called repository.

01:06.060 --> 01:11.220
So create a new repository package I'll name it as repositories.

01:11.380 --> 01:15.140
Inside this repository create a new Kotlin.

01:15.380 --> 01:20.220
You can create them in one file or you can make them in a separate file.

01:20.220 --> 01:24.700
We need the marker repository and the marker repository implementation.

01:24.700 --> 01:28.420
The first one is interface and the second one is a class.

01:28.620 --> 01:36.300
So as we learned before we have the interface for the repository and its implementation, which is a

01:36.300 --> 01:41.340
class I prefer to make everything separate and very clear.

01:41.460 --> 01:45.300
So let's start with marker repository.

01:45.300 --> 01:51.180
This interface for now has one function called add marker.

01:51.460 --> 01:59.180
So marker is of type lat long and name it's of type string.

01:59.220 --> 02:04.160
We can add more more parameters, but for now, it's good.

02:04.200 --> 02:06.720
Now let's create its implementation.

02:06.840 --> 02:14.240
Kotlin new class named as marker repository implementation.

02:14.240 --> 02:24.600
This class needs to inject the constructor and as we learned before we need to set the firebase which

02:24.600 --> 02:27.560
is Firebase Firestore parameter.

02:27.560 --> 02:30.440
If you have any question please don't be shy.

02:30.640 --> 02:33.720
Ask me and I'll respond.

02:33.720 --> 02:42.160
Also if you have any doubt you can refer to the previous examples and the previous sections in order

02:42.160 --> 02:44.960
to learn more about dependency injection.

02:44.960 --> 02:50.280
But don't worry I will lecture here in a quick recap.

02:50.400 --> 02:51.640
What we've done here.

02:51.640 --> 02:55.200
We created the marker repository interface.

02:55.240 --> 03:03.540
Marker repository is a Kotlin interface, which is for example, a contract that defines what methods

03:03.580 --> 03:05.620
a class should implement.

03:05.660 --> 03:13.940
The suspend function means this function is a suspending function, so it can be called inside a coroutine.

03:14.260 --> 03:17.820
It takes a marker object Latlong.

03:18.060 --> 03:23.060
Latitude and longitude coordinates and the name which is of type string.

03:23.300 --> 03:26.020
It doesn't return any thing.

03:26.340 --> 03:35.140
The marker repository implementation is a class that implements the marker repository interface.

03:35.140 --> 03:43.100
The inject constructor tells a dependency injection framework, which is in this case the hilt framework.

03:43.140 --> 03:44.940
How to create this class?

03:45.140 --> 03:51.380
It needs a Firebase Firestore instance passed in automatically.

03:51.580 --> 03:53.020
Firebase Firestore.

03:53.100 --> 04:01.380
This is the Firebase Firestore database object from the Firebase SDK used to read or write data in your

04:01.420 --> 04:03.480
Firestore Database.

04:03.480 --> 04:11.200
So the first step is creating this interface to define what your repository does.

04:11.240 --> 04:19.600
The capability to add a marker without carrying how it does it makes your code testable and swappable.

04:19.800 --> 04:27.320
You can later have Firebase marker repository that tries to Firebase uh, also saving a local database

04:27.320 --> 04:29.280
or for testing.

04:29.320 --> 04:29.840
Okay.

04:29.960 --> 04:36.440
So we're going to use it as a marker in order to insert markers into database.

04:36.440 --> 04:41.920
So we use this clean architecture interface defines what you can do.

04:42.160 --> 04:44.920
This interface defines what you can do.

04:45.320 --> 04:51.520
The repository implementation defines how you do it okay.

04:51.720 --> 04:55.760
The interface defines what you can do like adding markers.

04:56.160 --> 05:01.440
The implementation defines how you do it okay.

05:01.480 --> 05:05.940
Here we need to implement the function add marker.

05:05.940 --> 05:11.660
And here we're going to define how we can do it how we can add markers.

05:11.660 --> 05:19.660
So I want from you to understand concepts guys I'm not uh I don't uh want from you to copy and paste

05:19.660 --> 05:21.620
codes or follow me typing.

05:21.620 --> 05:24.580
I want from you to understand concepts.

05:24.580 --> 05:28.100
So here we are defining what you can do.

05:28.340 --> 05:29.220
Add marker.

05:29.220 --> 05:30.300
Remove marker.

05:30.300 --> 05:31.420
Delete database.

05:31.420 --> 05:32.660
Delete markers.

05:33.300 --> 05:34.660
Clean architecture.

05:34.820 --> 05:37.900
Clean the whole map, draw Polylines.

05:38.060 --> 05:43.540
Here inside the implementation we define how we can do it.

05:43.820 --> 05:46.660
So we have this red line.

05:46.660 --> 05:54.140
This arrow we need to implement members which is the add marker inherited from marker repository okay.

05:54.300 --> 05:58.500
In the next video we're going to continue with this add marker.

05:58.500 --> 06:05.380
And we're going to define how we can do the add marker function.
