Skip to content

Commit

Permalink
[Code health] Upgrade ktfmt-gradle and apply latest ktfmt AS plugin t…
Browse files Browse the repository at this point in the history
…o reduce formatting deltas between the two (#2456)

* Upgrade ktfmt Gradle plugin

* Format with ktfmt-gradle 0.18.0

* Format with AS ktfmt 1.1.0.49

* Format with ktfmt-gradle 0.18.0

* Format with AS ktfmt 1.1.0.49

* Format with ktfmt-gradle 0.18.0

* Format with AS ktfmt 1.1.0.49

* Format with ktfmt-gradle 0.18.0

---------

Co-authored-by: Shobhit Agarwal <ashobhit@google.com>
  • Loading branch information
gino-m and shobhitagarwal1612 authored May 2, 2024
1 parent 72e825f commit b68dc01
Show file tree
Hide file tree
Showing 161 changed files with 378 additions and 403 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ buildscript {
plugins {
id "org.jetbrains.kotlin.android" version "$kotlinVersion" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlinVersion"
id "com.ncorti.ktfmt.gradle" version "0.17.0"
id "com.ncorti.ktfmt.gradle" version "0.18.0"
id "com.google.dagger.hilt.android" version "$hiltVersion" apply false
id "io.gitlab.arturbosch.detekt" version "1.23.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ interface AutomatorRunner {

fun stringResource(
@StringRes resId: Int,
context: Context = InstrumentationRegistry.getInstrumentation().targetContext
context: Context = InstrumentationRegistry.getInstrumentation().targetContext,
): String = context.getString(resId)

fun byText(@StringRes resId: Int): BySelector = By.text(stringResource(resId))

fun <T : Any> byClass(kclass: KClass<T>): BySelector = By.clazz(kclass.java.name)

fun waitClickGone(
selector: BySelector,
timeout: Long = SHORT_TIMEOUT,
): Boolean {
fun waitClickGone(selector: BySelector, timeout: Long = SHORT_TIMEOUT): Boolean {
device.wait(Until.hasObject(selector), timeout)
device.findObject(selector)?.click()
return device.wait(Until.gone(selector), timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SetPreferencesRule : TestWatcher() {
super.starting(description)
EntryPointAccessors.fromApplication(
getApplicationContext(),
SetPreferencesRuleEntryPoint::class.java
SetPreferencesRuleEntryPoint::class.java,
)
.preferenceStorage()
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import javax.inject.Singleton
@Module
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [RemotePersistenceModule::class]
replaces = [RemotePersistenceModule::class],
)
abstract class TestRemoteStorageModule {
@Binds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ constructor(
else -> null
}
},
{ onUserSignInError(it) }
{ onUserSignInError(it) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SubmitDataUseCase
constructor(
private val locationOfInterestRepository: LocationOfInterestRepository,
private val submissionRepository: SubmissionRepository,
private val userRepository: UserRepository
private val userRepository: UserRepository,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ActivateSurveyUseCase
@Inject
constructor(
private val surveyRepository: SurveyRepository,
private val makeSurveyAvailableOffline: MakeSurveyAvailableOfflineUseCase
private val makeSurveyAvailableOffline: MakeSurveyAvailableOfflineUseCase,
) {
/**
* Sets the survey with the specified ID as the currently active. First attempts to load the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MakeSurveyAvailableOfflineUseCase
@Inject
constructor(
private val surveyRepository: SurveyRepository,
private val syncSurvey: SyncSurveyUseCase
private val syncSurvey: SyncSurveyUseCase,
) {
/**
* Makes the survey with the specified ID and related LOIs available offline. Subscribes to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReactivateLastSurveyUseCase
@Inject
constructor(
private val surveyRepository: SurveyRepository,
private val activateSurvey: ActivateSurveyUseCase
private val activateSurvey: ActivateSurveyUseCase,
) {
suspend operator fun invoke() {
// Do nothing if never activated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SyncSurveyUseCase
@Inject
constructor(
private val surveyRepository: SurveyRepository,
private val loiRepository: LocationOfInterestRepository
private val loiRepository: LocationOfInterestRepository,
) {
/**
* Downloads the survey with the specified ID and related LOIs from remote and inserts and/or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ import java.util.Date
data class AuditInfo(
val user: User,
val clientTimestamp: Date = Date(),
val serverTimestamp: Date? = null
val serverTimestamp: Date? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class Survey(
val jobMap: Map<String, Job>,
// TODO(#1730): Remove tileSources from survey.
val tileSources: List<TileSource> = listOf(),
val acl: Map<String, String> = mapOf()
val acl: Map<String, String> = mapOf(),
) {
val jobs: Collection<Job>
get() = jobMap.values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class SurveyListItem(
val id: String,
val title: String,
val description: String,
val availableOffline: Boolean
val availableOffline: Boolean,
)

fun Survey.toListItem(availableOffline: Boolean): SurveyListItem =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ constructor(
val email: String,
val displayName: String,
val photoUrl: String? = null,
val isAnonymous: Boolean = false
val isAnonymous: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class OfflineArea(
val bounds: Bounds,
val name: String,
/** The range of zoom levels downloaded. */
val zoomRange: IntRange
val zoomRange: IntRange,
) {
val tiles
get() = zoomRange.flatMap { TileCoordinates.withinBounds(bounds, it) }
Expand All @@ -34,6 +34,6 @@ data class OfflineArea(
PENDING,
IN_PROGRESS,
DOWNLOADED,
FAILED
FAILED,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ data class Job(
val style: Style? = null,
val name: String? = null,
val tasks: Map<String, Task> = mapOf(),
val strategy: DataCollectionStrategy = DataCollectionStrategy.UNKNOWN
val strategy: DataCollectionStrategy = DataCollectionStrategy.UNKNOWN,
) {
enum class DataCollectionStrategy {
PREDEFINED,
AD_HOC,
MIXED,
UNKNOWN
UNKNOWN,
}

class TaskNotFoundException(taskId: String) : Throwable(message = "unknown task $taskId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sealed class Mutation {
DELETE,

/** Indicates database skew or an implementation bug. */
UNKNOWN
UNKNOWN,
}

/** Status of mutation being applied to remote data store. */
Expand Down Expand Up @@ -73,7 +73,7 @@ sealed class Mutation {
COMPLETED,

/** Failed indicates all retries have failed. */
FAILED
FAILED,
}

override fun toString(): String = "$syncStatus $type $clientTimestamp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class SubmissionMutation(
override val lastError: String = "",
val job: Job,
val submissionId: String = "",
val deltas: List<ValueDelta> = listOf()
val deltas: List<ValueDelta> = listOf(),
) : Mutation() {

override fun toString(): String = super.toString() + "deltas= $deltas"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlinx.serialization.Serializable
@Serializable
class MultipleChoiceTaskData(
private val multipleChoice: MultipleChoice?,
val selectedOptionIds: List<String>
val selectedOptionIds: List<String>,
) : TaskData {

// TODO: Make these inner classes non-static and access Task directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ constructor(
val job: Job,
val created: AuditInfo,
val lastModified: AuditInfo,
val data: SubmissionData = SubmissionData()
val data: SubmissionData = SubmissionData(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.google.android.ground.model.submission.TaskData

/** The task ID. */
typealias TaskId = String

/** The selected values keyed by task ID. */
typealias TaskSelections = Map<String, TaskData>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constructor(
) {
enum class Cardinality {
SELECT_ONE,
SELECT_MULTIPLE
SELECT_MULTIPLE,
}

fun getOptionById(id: String): Option? = options.firstOrNull { it.id == id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ constructor(
TIME,
DROP_PIN,
DRAW_AREA,
CAPTURE_LOCATION
CAPTURE_LOCATION,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import com.google.android.ground.persistence.local.room.fields.TileSetEntityStat
ExpressionEntity::class,
],
version = Config.DB_VERSION,
exportSchema = false
exportSchema = false,
)
@TypeConverters(
TaskEntityType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object SubmissionDeltasConverter {
delta.taskId,
JSONObject()
.put(KEY_TASK_TYPE, delta.taskType.name)
.put(KEY_NEW_VALUE, ValueJsonConverter.toJsonObject(delta.newTaskData))
.put(KEY_NEW_VALUE, ValueJsonConverter.toJsonObject(delta.newTaskData)),
)
} catch (e: JSONException) {
Timber.e(e, "Error building JSON")
Expand All @@ -70,7 +70,7 @@ object SubmissionDeltasConverter {
ValueDelta(
taskId,
toEnum(Task.Type::class.java, jsonDelta.getString(KEY_TASK_TYPE)),
ValueJsonConverter.toResponse(task, jsonDelta[KEY_NEW_VALUE])
ValueJsonConverter.toResponse(task, jsonDelta[KEY_NEW_VALUE]),
)
)
} catch (e: LocalDataConsistencyException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ interface LocationOfInterestMutationDao : BaseDao<LocationOfInterestMutationEnti
)
suspend fun getMutations(
locationOfInterestId: String,
vararg allowedStates: MutationEntitySyncStatus
vararg allowedStates: MutationEntitySyncStatus,
): List<LocationOfInterestMutationEntity>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ interface SubmissionDao : BaseDao<SubmissionEntity> {
suspend fun findByLocationOfInterestId(
locationOfInterestId: String,
jobId: String,
state: EntityState
state: EntityState,
): List<SubmissionEntity>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface SubmissionMutationDao : BaseDao<SubmissionMutationEntity> {
)
suspend fun findByLocationOfInterestId(
locationOfInterestId: String,
vararg allowedStates: MutationEntitySyncStatus
vararg allowedStates: MutationEntitySyncStatus,
): List<SubmissionMutationEntity>

@Query(
Expand All @@ -45,7 +45,7 @@ interface SubmissionMutationDao : BaseDao<SubmissionMutationEntity> {
suspend fun getSubmissionMutationCount(
loiId: String,
mutationType: MutationEntityType,
vararg allowedStates: MutationEntitySyncStatus
vararg allowedStates: MutationEntitySyncStatus,
): Int

@Query(
Expand All @@ -54,7 +54,7 @@ interface SubmissionMutationDao : BaseDao<SubmissionMutationEntity> {
)
suspend fun findBySubmissionId(
submissionId: String,
vararg allowedStates: MutationEntitySyncStatus
vararg allowedStates: MutationEntitySyncStatus,
): List<SubmissionMutationEntity>?

@Query(
Expand All @@ -63,6 +63,6 @@ interface SubmissionMutationDao : BaseDao<SubmissionMutationEntity> {
)
fun findByLoiIdFlow(
locationOfInterestId: String,
vararg allowedStates: MutationEntitySyncStatus
vararg allowedStates: MutationEntitySyncStatus,
): Flow<List<SubmissionMutationEntity>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ data class AuditInfoEntity(
* Returns the time at which the server received the requested change according to the server's
* internal clock, or null if the updated server time was not yet received.
*/
val serverTimestamp: Long? = null
val serverTimestamp: Long? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import com.google.android.ground.persistence.local.room.fields.MatchEntityType
entity = TaskEntity::class,
parentColumns = ["id"],
childColumns = ["parent_task_id"],
onDelete = ForeignKey.CASCADE
onDelete = ForeignKey.CASCADE,
)
],
indices = [Index("parent_task_id")]
indices = [Index("parent_task_id")],
)
data class ConditionEntity(
@ColumnInfo(name = "parent_task_id") @PrimaryKey val parentTaskId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import com.google.android.ground.persistence.local.room.fields.ExpressionEntityT
entity = ConditionEntity::class,
parentColumns = ["parent_task_id"],
childColumns = ["parent_task_id"],
onDelete = ForeignKey.CASCADE
onDelete = ForeignKey.CASCADE,
)
],
indices = [Index("parent_task_id")]
indices = [Index("parent_task_id")],
)
data class ExpressionEntity(
@ColumnInfo(name = "parent_task_id") @PrimaryKey val parentTaskId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import androidx.room.*
entity = SurveyEntity::class,
parentColumns = ["id"],
childColumns = ["survey_id"],
onDelete = ForeignKey.CASCADE
onDelete = ForeignKey.CASCADE,
)
],
indices = [Index("survey_id")]
indices = [Index("survey_id")],
)
data class JobEntity(
@PrimaryKey @ColumnInfo(name = "id") val id: String,
@ColumnInfo(name = "name") val name: String?,
@ColumnInfo(name = "survey_id") val surveyId: String?,
@ColumnInfo(name = "strategy") val strategy: String,
@Embedded(prefix = "style_") val style: StyleEntity?
@Embedded(prefix = "style_") val style: StyleEntity?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import com.google.android.ground.persistence.local.room.fields.MultipleChoiceEnt
entity = TaskEntity::class,
parentColumns = ["id"],
childColumns = ["task_id"],
onDelete = ForeignKey.CASCADE
onDelete = ForeignKey.CASCADE,
)
],
indices = [Index("task_id")]
indices = [Index("task_id")],
)
data class MultipleChoiceEntity(
@ColumnInfo(name = "task_id") @PrimaryKey val taskId: String,
@ColumnInfo(name = "type") val type: MultipleChoiceEntityType,
@ColumnInfo(name = "has_other_option") val hasOtherOption: Boolean
@ColumnInfo(name = "has_other_option") val hasOtherOption: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ data class OfflineAreaEntity(
@ColumnInfo(name = "east") val east: Double,
@ColumnInfo(name = "west") val west: Double,
@ColumnInfo(name = "min_zoom") val minZoom: Int,
@ColumnInfo(name = "max_zoom") val maxZoom: Int
@ColumnInfo(name = "max_zoom") val maxZoom: Int,
)
Loading

0 comments on commit b68dc01

Please sign in to comment.