Skip to content

Commit

Permalink
Merge branch 'master' into sufy/1995/conditional-branches
Browse files Browse the repository at this point in the history
# Conflicts:
#	ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt
  • Loading branch information
sufyanAbbasi committed Feb 28, 2024
2 parents 933f24e + 3a628cf commit 369eaea
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 34 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ plugins {
id "com.github.ben-manes.versions" version "0.36.0"
id "org.jetbrains.kotlin.android" version "$kotlinVersion" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlinVersion"
id "com.ncorti.ktfmt.gradle" version "0.11.0"
id "com.ncorti.ktfmt.gradle" version "0.17.0"
id "com.google.dagger.hilt.android" version "$hiltVersion" apply false
id "io.gitlab.arturbosch.detekt" version "1.23.0"
id "io.gitlab.arturbosch.detekt" version "1.23.5"
}

allprojects {
Expand All @@ -85,7 +85,7 @@ subprojects {
}

detekt {
toolVersion = "1.23.0"
toolVersion = "1.23.5"

source = files("ground/src", "sharedTest/src")
allRules = true
Expand Down
4 changes: 1 addition & 3 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ style:
CanBeNonNullable:
active: true
CascadingCallWrapping:
active: true
active: false
includeElvis: true
ClassOrdering:
active: true
Expand Down Expand Up @@ -674,8 +674,6 @@ style:
active: true
OptionalUnit:
active: true
OptionalWhenBraces:
active: false
PreferToOverPairSyntax:
active: true
ProtectedMemberInFinalClass:
Expand Down
1 change: 1 addition & 0 deletions ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object Config {
// TODO(#1730): Make sub-paths configurable and stop hardcoding here.
const val DEFAULT_MOG_MIN_ZOOM = 8
const val DEFAULT_MOG_MAX_ZOOM = 14

fun getMogSources(path: String = "/offline-imagery/default/") =
listOf(
MogSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ constructor(
}

private fun getDirectionAfterSignIn(): NavDirections =
if (surveyRepository.activeSurvey != null) {
if (surveyRepository.selectedSurveyId != null) {
HomeScreenFragmentDirections.showHomeScreen()
} else {
SurveySelectorFragmentDirections.showSurveySelectorScreen(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ constructor(
}

surveyRepository.getOfflineSurvey(surveyId)
?: makeSurveyAvailableOffline(surveyId) ?: error("Survey $surveyId not found in remote db")
?: makeSurveyAvailableOffline(surveyId)
?: error("Survey $surveyId not found in remote db")

surveyRepository.selectedSurveyId = surveyId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import java.util.Date
* User details and timestamp for creation or modification of a model object.
*
* @property user the user initiating the related action. This can never be null, since users must
* always be logged in to make changes.
* always be logged in to make changes.
* @property clientTimestamp the time at which the user action was initiated, according to the
* user's device. Defaults to the current time if unspecified.
* user's device. Defaults to the current time if unspecified.
* @property serverTimestamp the time at which the server received the requested change according to
* the server's internal clock, or empty if the updated server time was not yet received.
* the server's internal clock, or empty if the updated server time was not yet received.
*/
data class AuditInfo(
val user: User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.google.android.ground.model.locationofinterest.LocationOfInterest
*
* @property created the user and time audit info pertaining to the creation of this submission.
* @property lastModified the user and time audit info pertaining to the last modification of this
* submission.
* submission.
*/
data class Submission
@JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.google.android.ground.model.submission
* An immutable map of task ids to submitted data values.
*
* @property data A map from task id to values. This map is mutable and therefore should never be
* exposed outside this class.
* exposed outside this class.
*/
// TODO: Merge into Submission?
data class SubmissionData(private val data: Map<String, Value?> = mapOf()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ abstract class LocalDataStoreModule {
@Binds
@Singleton
abstract fun offlineAreaStore(store: RoomOfflineAreaStore): LocalOfflineAreaStore

@Binds @Singleton abstract fun submissionStore(store: RoomSubmissionStore): LocalSubmissionStore

@Binds @Singleton abstract fun surveyStore(store: RoomSurveyStore): LocalSurveyStore

@Binds @Singleton abstract fun userStore(store: RoomUserStore): LocalUserStore

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,27 @@ import com.google.android.ground.persistence.local.room.fields.TileSetEntityStat
)
abstract class LocalDatabase : RoomDatabase() {
abstract fun locationOfInterestDao(): LocationOfInterestDao

abstract fun locationOfInterestMutationDao(): LocationOfInterestMutationDao

abstract fun taskDao(): TaskDao

abstract fun jobDao(): JobDao

abstract fun multipleChoiceDao(): MultipleChoiceDao

abstract fun optionDao(): OptionDao

abstract fun surveyDao(): SurveyDao

abstract fun tileSourceDao(): TileSourceDao

abstract fun submissionDao(): SubmissionDao

abstract fun submissionMutationDao(): SubmissionMutationDao

abstract fun offlineAreaDao(): OfflineAreaDao

abstract fun userDao(): UserDao
abstract fun conditionDao(): ConditionDao
abstract fun expressionDao(): ExpressionDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class RoomSubmissionStore @Inject internal constructor() : LocalSubmissionStore
): List<Submission> =
submissionDao
.findByLocationOfInterestId(locationOfInterest.id, jobId, EntityState.DEFAULT)
?.mapNotNull { logOnFailure { it.toModelObject(locationOfInterest) } }
?: listOf()
?.mapNotNull { logOnFailure { it.toModelObject(locationOfInterest) } } ?: listOf()

override suspend fun merge(model: Submission) {
submissionMutationDao
Expand All @@ -100,7 +99,7 @@ class RoomSubmissionStore @Inject internal constructor() : LocalSubmissionStore
* Applies mutation to submission in database or creates a new one.
*
* @return A Completable that emits an error if mutation type is "UPDATE" but entity does not
* exist, or if type is "CREATE" and entity already exists.
* exist, or if type is "CREATE" and entity already exists.
*/
override suspend fun apply(mutation: SubmissionMutation) {
when (mutation.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ constructor(
suspend fun getOfflineLoi(surveyId: String, locationOfInterest: String): LocationOfInterest =
localSurveyStore.getSurveyById(surveyId)?.let {
localLoiStore.getLocationOfInterest(it, locationOfInterest)
}
?: throw NotFoundException("Location of interest not found $locationOfInterest")
} ?: throw NotFoundException("Location of interest not found $locationOfInterest")

fun createLocationOfInterest(
geometry: Geometry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constructor(

/**
* @return [TermsOfService] from remote data store. Otherwise null if the request times out or
* network is unavailable.
* network is unavailable.
*/
suspend fun getTermsOfService(): TermsOfService? {
// TODO(#1691): Maybe parse the exception and display to the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.google.android.ground.ui.map.gms.mog
import android.util.LruCache
import com.google.android.ground.persistence.remote.RemoteStorageManager
import com.google.android.ground.ui.map.Bounds
import java.io.FileNotFoundException
import java.io.InputStream
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
Expand Down Expand Up @@ -50,10 +49,10 @@ class MogClient(val collection: MogCollection, val remoteStorageManager: RemoteS
* specified [tileBounds] and [zoomRange]s.
*
* @param tileBounds the bounds used to constrain which tiles are retrieved. Only requests for
* tiles within or overlapping these bounds are returned.
* tiles within or overlapping these bounds are returned.
* @param zoomRange the min. and max. zoom levels for which tile requests should be returned.
* Defaults to all available zoom levels in the collection ([MogSource.minZoom] to
* [MogSource.maxZoom]).
* Defaults to all available zoom levels in the collection ([MogSource.minZoom] to
* [MogSource.maxZoom]).
*/
suspend fun buildTilesRequests(
tileBounds: Bounds,
Expand Down Expand Up @@ -187,11 +186,11 @@ class MogClient(val collection: MogCollection, val remoteStorageManager: RemoteS

private suspend fun MogPathOrUrl.toUrl(): MogUrl? =
if (startsWith("/")) {
nullIfNotFound { remoteStorageManager.getDownloadUrl(this).toString() }
nullIfError { remoteStorageManager.getDownloadUrl(this).toString() }
} else this

private fun MogUrl.readMetadata(mogBounds: TileCoordinates): MogMetadata? =
nullIfNotFound { UrlInputStream(this) }?.use { this.readMogMetadataAndClose(mogBounds, it) }
nullIfError { UrlInputStream(this) }?.use { this.readMogMetadataAndClose(mogBounds, it) }

/** Reads the metadata from the specified input stream. */
private fun MogUrl.readMogMetadataAndClose(
Expand All @@ -208,9 +207,10 @@ class MogClient(val collection: MogCollection, val remoteStorageManager: RemoteS
}
}

private inline fun <T> nullIfNotFound(fn: () -> T) =
private inline fun <T> nullIfError(fn: () -> T) =
try {
fn()
} catch (_: FileNotFoundException) {
} catch (e: Exception) {
Timber.e(e)
null
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ data class MogImageMetadata(
// against accidental usage by throwing exception if called.
@Suppress("detekt:ExceptionRaisedInUnexpectedLocation")
override fun equals(other: Any?) = throw UnsupportedOperationException()

@Suppress("detekt:ExceptionRaisedInUnexpectedLocation")
override fun hashCode() = throw UnsupportedOperationException()

Expand All @@ -86,8 +87,7 @@ data class MogImageMetadata(
tiffTagToValue[TiffTag.ImageLength] as Int,
(tiffTagToValue[TiffTag.JPEGTables] as? List<*>)
?.map { (it as Int).toByte() }
?.toByteArray()
?: byteArrayOf(),
?.toByteArray() ?: byteArrayOf(),
(tiffTagToValue[TiffTag.GdalNodata] as? String)?.toIntOrNull()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data class MogTileMetadata(
// against accidental usage by throwing exception if called.
@Suppress("detekt:ExceptionRaisedInUnexpectedLocation")
override fun equals(other: Any?) = throw UnsupportedOperationException()

@Suppress("detekt:ExceptionRaisedInUnexpectedLocation")
override fun hashCode() = throw UnsupportedOperationException()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.google.android.ground.ui.map.gms.mog
open class MogTilesRequest(val sourceUrl: String, val tiles: List<MogTileMetadata>) {
val totalBytes: Int
get() = tiles.sumOf { it.byteRange.count() }

val byteRange: LongRange
get() = LongRange(tiles.first().byteRange.first, tiles.last().byteRange.last)

Expand All @@ -29,9 +30,7 @@ open class MogTilesRequest(val sourceUrl: String, val tiles: List<MogTileMetadat
if (other !is MogTilesRequest) return false

if (sourceUrl != other.sourceUrl) return false
if (tiles != other.tiles) return false

return true
return tiles == other.tiles
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const val READ_TIMEOUT_MS = 5 * 1000

/**
* @constructor Creates a [UrlInputStream] by opening a connection to an actual URL, requesting the
* specified [byteRange] if specified.
* specified [byteRange] if specified.
*/
class UrlInputStream(private val url: String, private val byteRange: LongRange? = null) :
InputStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ import javax.inject.Singleton
@Module
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [RemotePersistenceModule::class]
replaces = [RemotePersistenceModule::class],
)
abstract class TestRemoteStorageModule {
@Binds
@Singleton
abstract fun bindRemoteDataStore(remoteDataStore: FakeRemoteDataStore): RemoteDataStore

@Binds
@Singleton
abstract fun bindRemoteStorageManager(
remoteStorageManager: FakeRemoteStorageManager
): RemoteStorageManager

@Binds
@Singleton
abstract fun offlineUuidGenerator(uuidGenerator: FakeUuidGenerator): OfflineUuidGenerator
Expand Down

0 comments on commit 369eaea

Please sign in to comment.