From 08443c684c38fe203570acc29a77462030b9a730 Mon Sep 17 00:00:00 2001 From: Sufyan Abbasi Date: Wed, 28 Feb 2024 00:23:54 -0800 Subject: [PATCH] Remove dependency on survey.tileSources, instead use default Firebase storage path: /offline-imagery/default. --- .../java/com/google/android/ground/Config.kt | 5 ++-- .../com/google/android/ground/model/Survey.kt | 1 + .../repository/OfflineAreaRepository.kt | 29 +++++++++---------- .../ground/ui/home/HomeScreenViewModel.kt | 5 ++-- .../selector/OfflineAreaSelectorViewModel.kt | 4 +-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/Config.kt b/ground/src/main/java/com/google/android/ground/Config.kt index 10f45bb180..12358fbf03 100644 --- a/ground/src/main/java/com/google/android/ground/Config.kt +++ b/ground/src/main/java/com/google/android/ground/Config.kt @@ -55,13 +55,14 @@ object Config { const val MAX_MEDIA_UPLOAD_RETRY_COUNT = 5 // TODO(#1730): Make sub-paths configurable and stop hardcoding here. + const val DEFAULT_MOG_TILE_URL = "/offline-imagery/default/" const val DEFAULT_MOG_MIN_ZOOM = 8 const val DEFAULT_MOG_MAX_ZOOM = 14 - fun getMogSources(path: String = "/offline-imagery/default/") = + fun getMogSources(path: String) = listOf( MogSource( - 0 ..< DEFAULT_MOG_MIN_ZOOM, + 0.., + // TODO(#1730): Allow tile source configuration from a non-survey accessible source. val tileSources: List = listOf(), val acl: Map = mapOf() ) { diff --git a/ground/src/main/java/com/google/android/ground/repository/OfflineAreaRepository.kt b/ground/src/main/java/com/google/android/ground/repository/OfflineAreaRepository.kt index d0ee6fa105..86d57d794a 100644 --- a/ground/src/main/java/com/google/android/ground/repository/OfflineAreaRepository.kt +++ b/ground/src/main/java/com/google/android/ground/repository/OfflineAreaRepository.kt @@ -33,15 +33,15 @@ import com.google.android.ground.ui.util.FileUtil import com.google.android.ground.util.ByteCount import com.google.android.ground.util.deleteIfEmpty import com.google.android.ground.util.rangeOf -import java.io.File -import javax.inject.Inject -import javax.inject.Singleton import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import timber.log.Timber +import java.io.File +import javax.inject.Inject +import javax.inject.Singleton /** * Corners of the viewport are scaled by this value when determining the name of downloaded areas. @@ -51,8 +51,7 @@ const val AREA_NAME_SENSITIVITY = 0.5 @Singleton class OfflineAreaRepository -@Inject -constructor( +@Inject constructor( private val localOfflineAreaStore: LocalOfflineAreaStore, private val surveyRepository: SurveyRepository, private val fileUtil: FileUtil, @@ -109,18 +108,16 @@ constructor( fun getOfflineTileSourcesFlow() = surveyRepository.activeSurveyFlow.combine(getOfflineAreaBounds()) { survey, bounds -> - applyBounds(survey?.tileSources, bounds) + applyBounds(getDefaultTileSources(), bounds) } private suspend fun applyBounds( - tileSources: List?, - bounds: List + tileSources: List?, bounds: List ): List = tileSources?.mapNotNull { tileSource -> toOfflineTileSource(tileSource, bounds) } ?: listOf() private suspend fun toOfflineTileSource( - tileSource: TileSource, - clipBounds: List + tileSource: TileSource, clipBounds: List ): TileSource? { if (tileSource.type != TileSource.Type.MOG_COLLECTION) return null return TileSource( @@ -143,15 +140,15 @@ constructor( return MogClient(mogCollection, remoteStorageManager) } - private fun getMogSources(): List = Config.getMogSources(getFirstTileSourceUrl()) + private fun getMogSources(): List = + Config.getMogSources(getDefaultTileSources().first().url) /** - * Returns the URL of the first tile source in the current survey, or throws an error if no survey - * is active or if no tile sources are defined. + * Returns the default configured tile sources. + * */ - private fun getFirstTileSourceUrl() = - surveyRepository.activeSurvey?.tileSources?.firstOrNull()?.url - ?: error("Survey has no tile sources") + fun getDefaultTileSources(): List = + listOf(TileSource(url = Config.DEFAULT_MOG_TILE_URL, type = TileSource.Type.MOG_COLLECTION)) suspend fun hasHiResImagery(bounds: Bounds): Boolean { val client = getMogClient() diff --git a/ground/src/main/java/com/google/android/ground/ui/home/HomeScreenViewModel.kt b/ground/src/main/java/com/google/android/ground/ui/home/HomeScreenViewModel.kt index 61824315d1..8a1968ff6d 100644 --- a/ground/src/main/java/com/google/android/ground/ui/home/HomeScreenViewModel.kt +++ b/ground/src/main/java/com/google/android/ground/ui/home/HomeScreenViewModel.kt @@ -22,12 +22,12 @@ import com.google.android.ground.repository.SurveyRepository import com.google.android.ground.ui.common.AbstractViewModel import com.google.android.ground.ui.common.Navigator import com.google.android.ground.ui.common.SharedViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch +import javax.inject.Inject @SharedViewModel class HomeScreenViewModel @@ -40,8 +40,9 @@ internal constructor( private val _openDrawerRequests: MutableSharedFlow = MutableSharedFlow() val openDrawerRequestsFlow: SharedFlow = _openDrawerRequests.asSharedFlow() + // TODO(#1730): Allow tile source configuration from a non-survey accessible source. val showOfflineAreaMenuItem: LiveData = - surveyRepository.activeSurveyFlow.map { it?.tileSources?.isNotEmpty() ?: false }.asLiveData() + surveyRepository.activeSurveyFlow.map { true }.asLiveData() fun openNavDrawer() { viewModelScope.launch { _openDrawerRequests.emit(Unit) } diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt index f04c45287b..0027f985d4 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt @@ -37,9 +37,9 @@ import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.MapType import com.google.android.ground.util.toMb import com.google.android.ground.util.toMbString -import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch +import javax.inject.Inject private const val MIN_DOWNLOAD_ZOOM_LEVEL = 9 private const val MAX_AREA_DOWNLOAD_SIZE_MB = 50 @@ -90,7 +90,7 @@ internal constructor( ) init { - remoteTileSources = surveyRepository.activeSurvey!!.tileSources + remoteTileSources = offlineAreaRepository.getDefaultTileSources() } fun onDownloadClick() {