AdministrativeUnitLocalDataSource

class AdministrativeUnitLocalDataSource @Inject constructor(administrativeUnitNameRetriever: AdministrativeUnitNameRetriever, administrativeUnitNameDataSource: AdministrativeUnitNameDataSource, cartographicBoundaryRetriever: CartographicBoundaryRetriever, cartographicBoundaryDataSource: CartographicBoundaryDataSource, externalScope: CoroutineScope, imageDataSource: ImageDataSource) : AdministrativeUnitDataSource

Responsible for interacting with retrievers and data sources of administrative unit names and cartographic boundaries. It creates new administrative unit names and cartographic boundaries each time a new image is added.

Constructors

Link copied to clipboard
@Inject
constructor(administrativeUnitNameRetriever: AdministrativeUnitNameRetriever, administrativeUnitNameDataSource: AdministrativeUnitNameDataSource, cartographicBoundaryRetriever: CartographicBoundaryRetriever, cartographicBoundaryDataSource: CartographicBoundaryDataSource, externalScope: CoroutineScope, imageDataSource: ImageDataSource)

Functions

Link copied to clipboard
open override fun retrieve(): Flow<List<AdministrativeUnit>>

The administrativeUnitsFlow is triggered in many ways:

open override fun retrieve(administrativeLevel: AdministrativeLevel): Flow<List<AdministrativeUnit>>
Link copied to clipboard
open override fun retrieveActiveRegionsWithin(boundingBox: BoundingBox): Flow<List<Region>>
Link copied to clipboard
open override fun retrieveCurrent(): Flow<AdministrativeUnit>

Merge the currentAdministrativeUnitIndexFlow with administrativeUnitsFlow to receive the newly updated flow of the current AdministrativeUnit. Both flows are necessary because with the currentAdministrativeUnitIndexFlow, it's possible to get the currently selected AdministrativeUnit when the user selects one on the screen. And the administrativeUnitsFlow keeps sending changes that happen on that AdministrativeUnit in real-time while the user is on the administrative unit screen. It's guaranteed that the Flow only emits the object when there's a new change in it, for example, when a new Image is added. This Flow always emits the same instance of AdministrativeUnit for each index repeatedly. Therefore, you can't compare objects if they are the same instance. To verify if the object really changed its contents, its hash code is annotated. So, the next time this same object tries to emit, the hash code is compared to see if there was really a change, and it is emitted again only if its contents changed.

Link copied to clipboard
open override fun updateCurrentIndex(index: Int)

Update the current index selected by the user. This lastAdministrativeUnitHashCode property is used to compare if the contents of the current AdministrativeUnit really changed. If the user goes back to the administrative units screen and selects the same one again, it won't emit it again. To solve that problem, the lastAdministrativeUnitHashCode is reset each time this method is called.