Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on survey.tileSources, instead use default Firebase storage imagery path #2271

Merged
merged 12 commits into from
Mar 1, 2024
Merged
3 changes: 2 additions & 1 deletion ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ 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/"
gino-m marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class Survey(
val title: String,
val description: String,
val jobMap: Map<String, Job>,
// TODO(#1730): Allow tile source configuration from a non-survey accessible source.
sufyanAbbasi marked this conversation as resolved.
Show resolved Hide resolved
val tileSources: List<TileSource> = listOf(),
val acl: Map<String, String> = mapOf()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ constructor(

fun getOfflineTileSourcesFlow() =
surveyRepository.activeSurveyFlow.combine(getOfflineAreaBounds()) { survey, bounds ->
applyBounds(survey?.tileSources, bounds)
applyBounds(getDefaultTileSources(), bounds)
}

private suspend fun applyBounds(
Expand Down Expand Up @@ -143,15 +143,12 @@ constructor(
return MogClient(mogCollection, remoteStorageManager)
}

private fun getMogSources(): List<MogSource> = Config.getMogSources(getFirstTileSourceUrl())
private fun getMogSources(): List<MogSource> =
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.
*/
private fun getFirstTileSourceUrl() =
surveyRepository.activeSurvey?.tileSources?.firstOrNull()?.url
?: error("Survey has no tile sources")
/** Returns the default configured tile sources. */
fun getDefaultTileSources(): List<TileSource> =
listOf(TileSource(url = Config.DEFAULT_MOG_TILE_URL, type = TileSource.Type.MOG_COLLECTION))

suspend fun hasHiResImagery(bounds: Bounds): Boolean {
val client = getMogClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ class HomeScreenViewModel
@Inject
internal constructor(
private val navigator: Navigator,
private val surveyRepository: SurveyRepository,
surveyRepository: SurveyRepository,
) : AbstractViewModel() {

private val _openDrawerRequests: MutableSharedFlow<Unit> = MutableSharedFlow()
val openDrawerRequestsFlow: SharedFlow<Unit> = _openDrawerRequests.asSharedFlow()

// TODO(#1730): Allow tile source configuration from a non-survey accessible source.
val showOfflineAreaMenuItem: LiveData<Boolean> =
sufyanAbbasi marked this conversation as resolved.
Show resolved Hide resolved
surveyRepository.activeSurveyFlow.map { it?.tileSources?.isNotEmpty() ?: false }.asLiveData()
surveyRepository.activeSurveyFlow.map { true }.asLiveData()

fun openNavDrawer() {
viewModelScope.launch { _openDrawerRequests.emit(Unit) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal constructor(
)

init {
remoteTileSources = surveyRepository.activeSurvey!!.tileSources
remoteTileSources = offlineAreaRepository.getDefaultTileSources()
}

fun onDownloadClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ import com.google.android.ground.ui.common.Navigator
import com.sharedtest.FakeData
import com.squareup.picasso.Picasso
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceUntilIdle
import org.hamcrest.CoreMatchers.not
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.RobolectricTestRunner
import javax.inject.Inject

abstract class AbstractHomeScreenFragmentTest : BaseHiltTest() {

@Inject lateinit var localSurveyStore: LocalSurveyStore
@Inject
lateinit var localSurveyStore: LocalSurveyStore
private lateinit var fragment: HomeScreenFragment
private var initializedPicasso = false

Expand Down Expand Up @@ -119,7 +119,8 @@ abstract class AbstractHomeScreenFragmentTest : BaseHiltTest() {
@RunWith(RobolectricTestRunner::class)
class HomeScreenFragmentTest : AbstractHomeScreenFragmentTest() {

@Inject lateinit var surveyRepository: SurveyRepository
@Inject
lateinit var surveyRepository: SurveyRepository

private val surveyWithoutBasemap: Survey =
Survey(
Expand All @@ -134,27 +135,17 @@ class HomeScreenFragmentTest : AbstractHomeScreenFragmentTest() {
private val surveyWithTileSources: Survey =
surveyWithoutBasemap.copy(
tileSources =
listOf(
TileSource("http://google.com", TileSource.Type.MOG_COLLECTION),
),
listOf(
TileSource("http://google.com", TileSource.Type.MOG_COLLECTION),
),
id = "SURVEY_WITH_TILE_SOURCES"
)

@Test
fun offlineMapImageryMenuIsDisabledWhenActiveSurveyHasNoBasemap() = runWithTestDispatcher {
fun `offline map imagery menu is always enabled`() = runWithTestDispatcher {
surveyRepository.selectedSurveyId = surveyWithoutBasemap.id
advanceUntilIdle()

openDrawer()
onView(withId(R.id.nav_offline_areas)).check(matches(not(isEnabled())))
}

@Test
fun offlineMapImageryMenuIsEnabledWhenActiveSurveyHasBasemap() = runWithTestDispatcher {
localSurveyStore.insertOrUpdateSurvey(surveyWithTileSources)
surveyRepository.selectedSurveyId = surveyWithTileSources.id
advanceUntilIdle()

openDrawer()
onView(withId(R.id.nav_offline_areas)).check(matches(isEnabled()))
}
Expand All @@ -171,8 +162,11 @@ class NavigationDrawerItemClickTest(
private val testLabel: String
) : AbstractHomeScreenFragmentTest() {

@Inject lateinit var navigator: Navigator
@Inject lateinit var surveyRepository: SurveyRepository
@Inject
lateinit var navigator: Navigator

@Inject
lateinit var surveyRepository: SurveyRepository

@Test
fun clickDrawerMenuItem() = runWithTestDispatcher {
Expand Down Expand Up @@ -219,19 +213,12 @@ class NavigationDrawerItemClickTest(
true,
"Clicking 'sync status' should navigate to fragment"
),
arrayOf(
"Offline map imagery",
TEST_SURVEY_WITHOUT_OFFLINE_TILES,
null,
false,
"Clicking 'offline map imagery' when survey doesn't have offline tiles should do nothing"
),
arrayOf(
"Offline map imagery",
TEST_SURVEY_WITH_OFFLINE_TILES,
HomeScreenFragmentDirections.showOfflineAreas(),
true,
"Clicking 'offline map imagery' when survey has offline tiles should navigate to fragment"
"Clicking 'offline map imagery' should navigate to fragment"
),
arrayOf(
"Settings",
Expand Down