Welcome back.
We succeeded in getting all the markers from Firebase Firestore database.
Now let's fetch the current location of the user inside the repositories.
Package.
Create a new Kotlin interface named as Location Repository.
Hit enter.
This interface contains two variables and two functions.
The first variable is called user location.
It's of type stateflow of lat long and val has location permissions.
It's of type mutable state of type boolean.
Let me import the Stateflow.
The left lung.
The mutable state.
Create the two functions.
Start location updates and function stop location updates.
The location repository interface defines a contract for managing device location updates in an Android
application using modern Kotlin coroutines and state management patterns.
This interface abstracts location tracking.
Start or stop updates.
Current location exposure as a reactive stream has location permission used for permission.
State management.
The state of flow A hot observable flow that always holds the latest value.
The Latlong location data class typically latitude and longitude, nullable when no location is available.
Purpose of this provides the app with real time location updates.
Automatically notifies observers when location changes.
Has location permission which is of type Boolean mutable state Boolean.
Jetpack composes observable state holder tracks whether the location permissions are granted.
Can trigger permission requests when false y.
Mutable state optimized for compose UI recomposition.
When permission state changes, the start location updates function starts listening for location updates
and stop location updates.
Stops location updates to save battery when location is no longer needed or the app goes to background,
it's very important and critical for preventing battery drain.
So the purpose of creating this interface is to use the user location, has location permissions, start
location updates, and stop location updates.
Why we use the Stateflow and mutable state.
The state flow automatically clean up tied to a coroutine scope lifecycle.
Reactive UI compose can collect and recompose on changes.
Single source of truth always holds the latest location and why.
Mutable state for permissions compose integration directly works with remember and recomposition and
simple state permission state is binary granted or not granted.
Okay, now in the next video we'll continue with um with the default location repository or the location
repository implementation.
And we're going to use those variables and functions.