WEBVTT

00:00.120 --> 00:01.120
Welcome back.

00:01.160 --> 00:04.520
We created the location repository interface.

00:04.520 --> 00:13.600
Now let's create a class that implements this interface location repository implementation.

00:13.600 --> 00:20.760
Click okay and this class implements this location repository interface.

00:20.760 --> 00:23.880
Use our friend inject annotation.

00:23.920 --> 00:25.600
Inject the constructor.

00:25.720 --> 00:31.000
And with what we need to inject we need to inject it with context.

00:31.000 --> 00:36.480
So add application context private val context.

00:36.520 --> 00:41.240
It's of type context Alt+ enter to import the inject.

00:41.240 --> 00:42.920
And here we go okay.

00:43.160 --> 00:50.280
So this is our class location repository implementation that extends from Location repository.

00:50.480 --> 00:56.360
Now we need to implement the members two variables and two functions here.

00:56.400 --> 01:02.040
Let's start with you can use like this Alt+ enter to implement the members.

01:02.040 --> 01:04.420
But I don't need this.

01:04.420 --> 01:08.540
I need to go through every parameter step by step.

01:08.580 --> 01:11.180
Let's start with the first variable.

01:11.180 --> 01:12.380
User location.

01:12.420 --> 01:14.180
Private val.

01:14.300 --> 01:15.420
User location.

01:15.420 --> 01:21.340
It's of type immutable state flow of lat long and the default value is null.

01:21.380 --> 01:24.740
Import the mutable state flow and lat long.

01:24.780 --> 01:33.340
Now override val user location type state flow of lat long.

01:33.380 --> 01:42.700
And what we need to do is to get the user location dot as state flow.

01:42.740 --> 01:45.020
Let me explain what we've done here.

01:45.140 --> 01:54.020
The purpose behind creating this is creating a read only or read write backing property.

01:54.060 --> 01:58.780
User location and read only public property called user location.

01:58.780 --> 02:09.370
So this is for read write backing property and this is for read only public property following the unidirectional

02:09.370 --> 02:11.090
data flow principle.

02:11.210 --> 02:16.410
So internally we are going to update the underscore user location.

02:16.570 --> 02:20.850
External component only read via user location.

02:21.010 --> 02:22.690
So this is for public.

02:22.930 --> 02:24.770
And this is for private.

02:24.810 --> 02:27.730
This is read only and this is read.

02:27.730 --> 02:36.890
Write the mutable state flow immutable holder for state that emits updates to collectors and Latlong

02:37.130 --> 02:43.690
type parameter typically contains a latlong nullable when no location available.

02:43.930 --> 02:46.010
Null is the initial value.

02:46.130 --> 02:48.570
No known location.

02:48.570 --> 02:59.370
The state of flow exposed via as state flow function, which converts mutable flow to immutable, preventing

02:59.370 --> 03:05.450
external modification, and still reflects all updates from the source.

03:05.810 --> 03:10.390
So using this we achieve immutability.

03:10.430 --> 03:11.630
Write access.

03:11.630 --> 03:12.790
Read access.

03:12.830 --> 03:15.510
Thread safety and initial value.

03:15.550 --> 03:20.510
Why this is important and why we use this pattern for encapsulation.

03:20.510 --> 03:26.310
Internal implementation can change without affecting clients and external components.

03:26.310 --> 03:28.950
Can't modify the state directly.

03:29.150 --> 03:34.750
Then we need to create the second variable which is has location permission.

03:34.910 --> 03:43.510
You notice that we used this and the color violet is changed and replacing the grey start with override.

03:43.550 --> 03:48.830
Val has location permission which is a mutable state of.

03:49.350 --> 03:52.470
And let me change it to false.

03:52.510 --> 03:55.150
Okay, this is our value.

03:55.190 --> 03:59.670
I am setting it to false as the initial value.

03:59.710 --> 04:02.270
Okay, those are the variables.

04:02.470 --> 04:05.350
Now let's continue with the functions.
