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

[REPRO] AS ktfmt deltas #2412

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object Config {
fun getMogSources(path: String) =
listOf(
MogSource(
0 ..< DEFAULT_MOG_MIN_ZOOM,
0..<DEFAULT_MOG_MIN_ZOOM,
"$path/$DEFAULT_MOG_MIN_ZOOM/overview.tif",
),
MogSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import timber.log.Timber
@HiltAndroidApp
class GroundApplication : MultiDexApplication(), Configuration.Provider {

@Inject lateinit var crashReportingTree: CrashReportingTree
@Inject lateinit var workerFactory: HiltWorkerFactory
@Inject
lateinit var crashReportingTree: CrashReportingTree
@Inject
lateinit var workerFactory: HiltWorkerFactory

override val workManagerConfiguration: Configuration
get() = Configuration.Builder().setWorkerFactory(workerFactory).build()
Expand Down
18 changes: 12 additions & 6 deletions ground/src/main/java/com/google/android/ground/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ import timber.log.Timber
*/
@AndroidEntryPoint
class MainActivity : AbstractActivity() {
@Inject lateinit var activityStreams: ActivityStreams
@Inject lateinit var viewModelFactory: ViewModelFactory
@Inject lateinit var settingsManager: SettingsManager
@Inject lateinit var navigator: Navigator
@Inject lateinit var userRepository: UserRepository
@Inject lateinit var popups: EphemeralPopups
@Inject
lateinit var activityStreams: ActivityStreams
@Inject
lateinit var viewModelFactory: ViewModelFactory
@Inject
lateinit var settingsManager: SettingsManager
@Inject
lateinit var navigator: Navigator
@Inject
lateinit var userRepository: UserRepository
@Inject
lateinit var popups: EphemeralPopups

private lateinit var viewModel: MainViewModel
private lateinit var navHostFragment: NavHostFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,31 @@ object CoroutineDispatchersModule {
@Provides
fun provideDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default

@IoDispatcher @Provides fun provideIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
@IoDispatcher
@Provides
fun provideIoDispatcher(): CoroutineDispatcher = Dispatchers.IO

@MainDispatcher @Provides fun provideMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
@MainDispatcher
@Provides
fun provideMainDispatcher(): CoroutineDispatcher = Dispatchers.Main

@MainImmediateDispatcher
@Provides
fun provideMainImmediateDispatcher(): CoroutineDispatcher = Dispatchers.Main.immediate
}

@Retention(AnnotationRetention.RUNTIME) @Qualifier annotation class DefaultDispatcher
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class DefaultDispatcher

@Retention(AnnotationRetention.RUNTIME) @Qualifier annotation class IoDispatcher
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class IoDispatcher

@Retention(AnnotationRetention.RUNTIME) @Qualifier annotation class MainDispatcher
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class MainDispatcher

@Retention(AnnotationRetention.BINARY) @Qualifier annotation class MainImmediateDispatcher
@Retention(AnnotationRetention.BINARY)
@Qualifier
annotation class MainImmediateDispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ object CoroutinesScopesModule {
* Scope for jobs which need to outlive the lifecycle of specific view components. Use this scope to
* bind jobs to the application's lifecycle instead.
*/
@Retention(AnnotationRetention.RUNTIME) @Qualifier annotation class ApplicationScope
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope

@Retention(AnnotationRetention.RUNTIME) @Qualifier annotation class MainScope
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class MainScope
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.model.task
import kotlinx.serialization.Serializable

/** Describes a single valid option to a multiple choice question. */
@Serializable data class Option(val id: String, val code: String, val label: String)
@Serializable
data class Option(val id: String, val code: String, val label: String)
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ abstract class LocalDataStoreModule {
@Singleton
abstract fun offlineAreaStore(store: RoomOfflineAreaStore): LocalOfflineAreaStore

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

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

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

companion object {
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IntEnum {

@JvmStatic
fun <E> fromInt(values: Array<E>, intValue: Int, defaultValue: E): E where
E : Enum<E>,
E : IntEnum = values.firstOrNull { it.intValue() == intValue } ?: defaultValue
E : Enum<E>,
E : IntEnum = values.firstOrNull { it.intValue() == intValue } ?: defaultValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ import com.google.android.ground.persistence.local.room.fields.TileSetEntityStat
*/
@Database(
entities =
[
DraftSubmissionEntity::class,
LocationOfInterestEntity::class,
LocationOfInterestMutationEntity::class,
TaskEntity::class,
JobEntity::class,
MultipleChoiceEntity::class,
OptionEntity::class,
SurveyEntity::class,
TileSourceEntity::class,
SubmissionEntity::class,
SubmissionMutationEntity::class,
OfflineAreaEntity::class,
UserEntity::class,
ConditionEntity::class,
ExpressionEntity::class,
],
[
DraftSubmissionEntity::class,
LocationOfInterestEntity::class,
LocationOfInterestMutationEntity::class,
TaskEntity::class,
JobEntity::class,
MultipleChoiceEntity::class,
OptionEntity::class,
SurveyEntity::class,
TileSourceEntity::class,
SubmissionEntity::class,
SubmissionMutationEntity::class,
OfflineAreaEntity::class,
UserEntity::class,
ConditionEntity::class,
ExpressionEntity::class,
],
version = Config.DB_VERSION,
exportSchema = false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ fun JobEntityAndRelations.toModelObject(): Job {
style = jobEntity.style?.toModelObject(),
name = jobEntity.name,
strategy =
jobEntity.strategy.let {
try {
DataCollectionStrategy.valueOf(it)
} catch (e: IllegalArgumentException) {
Timber.e("unknown data collection strategy $it")
DataCollectionStrategy.UNKNOWN
}
},
jobEntity.strategy.let {
try {
DataCollectionStrategy.valueOf(it)
} catch (e: IllegalArgumentException) {
Timber.e("unknown data collection strategy $it")
DataCollectionStrategy.UNKNOWN
}
},
tasks = taskMap.toPersistentMap(),
)
}
Expand Down Expand Up @@ -169,10 +169,10 @@ fun LocationOfInterestEntity.toModelObject(survey: Survey): LocationOfInterest =
properties = properties,
isPredefined = isPredefined,
job =
survey.getJob(jobId = jobId)
?: throw LocalDataConsistencyException(
"Unknown jobId ${this.jobId} in location of interest ${this.id}"
),
survey.getJob(jobId = jobId)
?: throw LocalDataConsistencyException(
"Unknown jobId ${this.jobId} in location of interest ${this.id}"
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import timber.log.Timber

object JsonArrayTypeConverter {

@TypeConverter fun toString(jsonArray: JSONArray?): String? = jsonArray?.toString()
@TypeConverter
fun toString(jsonArray: JSONArray?): String? = jsonArray?.toString()

@TypeConverter
fun fromString(jsonString: String?): JSONArray? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import timber.log.Timber

object JsonObjectTypeConverter {

@JvmStatic @TypeConverter fun toString(jsonObject: JSONObject?): String? = jsonObject?.toString()
@JvmStatic
@TypeConverter
fun toString(jsonObject: JSONObject?): String? = jsonObject?.toString()

@JvmStatic
@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import com.google.android.ground.model.job.Style

object StyleTypeConverter {

@TypeConverter fun toString(style: Style?): String? = style?.color
@TypeConverter
fun toString(style: Style?): String? = style?.color

@TypeConverter fun fromString(color: String?): Style? = color?.let { Style(it) }
@TypeConverter
fun fromString(color: String?): Style? = color?.let { Style(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal object ValueJsonConverter {
put("altitude", value.altitude)
put("geometry", GeometryWrapperTypeConverter.toString(value.geometry))
}

else -> throw UnsupportedOperationException("Unimplemented value class ${value.javaClass}")
}
}
Expand Down Expand Up @@ -91,40 +92,48 @@ internal object ValueJsonConverter {
DataStoreException.checkType(String::class.java, obj)
TextResponse.fromString(obj as String)
}

Task.Type.MULTIPLE_CHOICE -> {
DataStoreException.checkType(JSONArray::class.java, obj)
MultipleChoiceResponse.fromList(task.multipleChoice, toList(obj as JSONArray))
}

Task.Type.NUMBER -> {
DataStoreException.checkType(Number::class.java, obj)
NumberResponse.fromNumber(obj.toString())
}

Task.Type.DATE -> {
DataStoreException.checkType(String::class.java, obj)
DateResponse.fromDate(isoStringToDate(obj as String))
}

Task.Type.TIME -> {
DataStoreException.checkType(String::class.java, obj)
TimeResponse.fromDate(isoStringToDate(obj as String))
}

Task.Type.DRAW_AREA -> {
DataStoreException.checkType(String::class.java, obj)
val geometry = GeometryWrapperTypeConverter.fromString(obj as String)?.getGeometry()
DataStoreException.checkNotNull(geometry, "Missing geometry in draw area task result")
DataStoreException.checkType(Polygon::class.java, geometry!!)
DrawAreaTaskResult(geometry as Polygon)
}

Task.Type.DROP_PIN -> {
DataStoreException.checkType(String::class.java, obj)
val geometry = GeometryWrapperTypeConverter.fromString(obj as String)?.getGeometry()
DataStoreException.checkNotNull(geometry, "Missing geometry in drop pin task result")
DataStoreException.checkType(Point::class.java, geometry!!)
DropPinTaskResult(geometry as Point)
}

Task.Type.CAPTURE_LOCATION -> {
DataStoreException.checkType(JSONObject::class.java, obj)
captureLocationResultFromJsonObject(obj as JSONObject).getOrThrow()
}

Task.Type.UNKNOWN -> {
throw DataStoreException("Unknown type in task: " + obj.javaClass.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ import androidx.room.Update
*/
interface BaseDao<E> {

@Insert suspend fun insert(entity: E)
@Insert
suspend fun insert(entity: E)

@Update suspend fun update(entity: E): Int
@Update
suspend fun update(entity: E): Int

@Update suspend fun updateAll(entities: List<E>)
@Update
suspend fun updateAll(entities: List<E>)

@Delete suspend fun delete(entity: E)
@Delete
suspend fun delete(entity: E)
}

/** Try to update the specified entity, and if it doesn't yet exist, create it. Main-safe. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.persistence.local.room.dao
import androidx.room.Dao
import com.google.android.ground.persistence.local.room.entity.ConditionEntity

@Dao interface ConditionDao : BaseDao<ConditionEntity>
@Dao
interface ConditionDao : BaseDao<ConditionEntity>
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ interface DraftSubmissionDao : BaseDao<DraftSubmissionEntity> {
@Query("SELECT * FROM draft_submission WHERE id = :draftSubmissionId")
suspend fun findById(draftSubmissionId: String): DraftSubmissionEntity?

@Query("DELETE FROM draft_submission") fun delete()
@Query("DELETE FROM draft_submission")
fun delete()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.persistence.local.room.dao
import androidx.room.Dao
import com.google.android.ground.persistence.local.room.entity.ExpressionEntity

@Dao interface ExpressionDao : BaseDao<ExpressionEntity>
@Dao
interface ExpressionDao : BaseDao<ExpressionEntity>
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.persistence.local.room.dao
import androidx.room.Dao
import com.google.android.ground.persistence.local.room.entity.MultipleChoiceEntity

@Dao interface MultipleChoiceDao : BaseDao<MultipleChoiceEntity>
@Dao
interface MultipleChoiceDao : BaseDao<MultipleChoiceEntity>
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import kotlinx.coroutines.flow.Flow
/** Provides read/write operations for writing [OfflineAreaEntity] to the local db. */
@Dao
interface OfflineAreaDao : BaseDao<OfflineAreaEntity> {
@Query("SELECT * FROM offline_area") fun findAll(): Flow<List<OfflineAreaEntity>>
@Query("SELECT * FROM offline_area")
fun findAll(): Flow<List<OfflineAreaEntity>>

@Query("SELECT * FROM offline_area WHERE id = :id")
suspend fun findById(id: String): OfflineAreaEntity?

@Query("DELETE FROM offline_area WHERE id = :id") suspend fun deleteById(id: String)
@Query("DELETE FROM offline_area WHERE id = :id")
suspend fun deleteById(id: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.persistence.local.room.dao
import androidx.room.Dao
import com.google.android.ground.persistence.local.room.entity.OptionEntity

@Dao interface OptionDao : BaseDao<OptionEntity>
@Dao
interface OptionDao : BaseDao<OptionEntity>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import kotlinx.coroutines.flow.Flow

@Dao
interface SurveyDao : BaseDao<SurveyEntity> {
@Transaction @Query("SELECT * FROM survey") fun getAll(): Flow<List<SurveyEntityAndRelations>>
@Transaction
@Query("SELECT * FROM survey")
fun getAll(): Flow<List<SurveyEntityAndRelations>>

@Transaction
@Query("SELECT * FROM survey WHERE id = :id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package com.google.android.ground.persistence.local.room.dao
import androidx.room.Dao
import com.google.android.ground.persistence.local.room.entity.TaskEntity

@Dao interface TaskDao : BaseDao<TaskEntity>
@Dao
interface TaskDao : BaseDao<TaskEntity>
Loading