Skip to content

Commit

Permalink
Merge pull request #2340 from CruGlobal/renovate/ktlint
Browse files Browse the repository at this point in the history
Update dependency com.pinterest:ktlint to v0.48.2
  • Loading branch information
frett authored Mar 7, 2023
2 parents 4ab71ac + 7b07bfd commit bf94791
Show file tree
Hide file tree
Showing 39 changed files with 228 additions and 122 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
insert_final_newline=true

[*.{kt,kts}]
ij_kotlin_imports_layout=*,^
ij_kotlin_allow_trailing_comma=true
# ij_kotlin_allow_trailing_comma_on_call_site=true
indent_size=4
ktlint_code_style=android
ktlint_standard_filename = disabled
ktlint_standard_spacing-between-declarations-with-annotations = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
max_line_length = 120
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ abstract class BasePlatformActivity<B : ViewBinding> protected constructor(@Layo

private fun SwipeRefreshSyncHelper.triggerSync(force: Boolean = false) {
onSyncData(this, force)
if (handleChildrenSyncs) supportFragmentManager.fragments.filterIsInstance<BasePlatformFragment<*>>()
.forEach { with(it) { triggerSync(force) } }
if (handleChildrenSyncs) {
supportFragmentManager.fragments.filterIsInstance<BasePlatformFragment<*>>()
.forEach { with(it) { triggerSync(force) } }
}
updateState()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ internal fun ToolDetailsActions(
contentDescription = null
)
Text(
stringResource(
if (isAdded) R.string.action_tools_remove_favorite
else R.string.action_tools_add_favorite
),
stringResource(if (isAdded) R.string.action_tools_remove_favorite else R.string.action_tools_add_favorite),
modifier = Modifier.padding(start = 4.dp)
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ godtoolsShared = "0.8.2-SNAPSHOT"
google-auto-value = "1.10.1"
gtoSupport = "4.0.0-SNAPSHOT"
jacoco = "0.8.8"
ktlint = "0.45.2"
ktlint = "0.48.2"
kotlin = "1.8.10"
kotlinCoroutines = "1.6.4"
lottie = "6.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ class GodToolsAccountManager @VisibleForTesting internal constructor(
internal constructor(providers: Set<@JvmSuppressWildcards AccountProvider>) :
this(providers.sortedWith(Ordered.COMPARATOR))

// region Active Provider
@VisibleForTesting
internal suspend fun activeProvider() = providers.firstOrNull { it.isAuthenticated() }

@VisibleForTesting
internal val activeProviderFlow =
combine(providers.map { p -> p.isAuthenticatedFlow().map { p to it } }) {
it.firstNotNullOfOrNull { (p, isAuthed) -> if (isAuthed) p else null }
}.stateIn(coroutineScope, SharingStarted.Eagerly, null)
// endregion Active Provider

suspend fun isAuthenticated() = activeProvider()?.isAuthenticated() ?: false
suspend fun userId() = activeProvider()?.userId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ internal class OktaAccountProvider @Inject constructor(
familyName = userInfo?.familyName,
email = idToken?.email ?: userInfo?.email
)
} else null
} else {
null
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ class AppsFlyerAnalyticsService @VisibleForTesting internal constructor(
@WorkerThread
@Subscribe(threadMode = ThreadMode.ASYNC)
fun onAnalyticsScreenEvent(event: AnalyticsScreenEvent) {
if (event.isForSystem(AnalyticsSystem.APPSFLYER))
appsFlyer.logEvent(app, event.screen, emptyMap())
if (event.isForSystem(AnalyticsSystem.APPSFLYER)) appsFlyer.logEvent(app, event.screen, emptyMap())
}

@WorkerThread
@Subscribe(threadMode = ThreadMode.ASYNC)
fun onAnalyticsActionEvent(event: AnalyticsActionEvent) {
if (event.isForSystem(AnalyticsSystem.APPSFLYER))
appsFlyer.logEvent(app, event.action, emptyMap())
if (event.isForSystem(AnalyticsSystem.APPSFLYER)) appsFlyer.logEvent(app, event.action, emptyMap())
}
// endregion Analytics Events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class FirebaseAnalyticsService @VisibleForTesting internal constructor(
@MainThread
@Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
fun onAnalyticsEvent(event: AnalyticsBaseEvent) {
if (event.isForSystem(AnalyticsSystem.FIREBASE)) when (event) {
if (!event.isForSystem(AnalyticsSystem.FIREBASE)) return
when (event) {
is AnalyticsScreenEvent -> handleScreenEvent(event)
is AnalyticsActionEvent -> handleActionEvent(event)
}
Expand Down Expand Up @@ -114,7 +115,8 @@ class FirebaseAnalyticsService @VisibleForTesting internal constructor(
firebase.setUserProperty(USER_PROP_APP_NAME, VALUE_APP_NAME_GODTOOLS)
firebase.setUserProperty(PARAM_CONTENT_LANGUAGE, Locale.getDefault().toLanguageTag())
firebase.setUserProperty(
USER_PROP_APP_TYPE, if (InstantApps.isInstantApp(app)) VALUE_APP_TYPE_INSTANT else VALUE_APP_TYPE_INSTALLED
USER_PROP_APP_TYPE,
if (InstantApps.isInstantApp(app)) VALUE_APP_TYPE_INSTANT else VALUE_APP_TYPE_INSTALLED
)
firebase.setUserProperty(USER_PROP_DEBUG, BuildConfig.DEBUG.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ fun Locale.getDisplayName(context: Context? = null, defaultName: String? = null,
?: defaultName
// just rely on Locale.getDisplayName() which will default to the language code at this point
?: run {
Timber.tag("LocaleUtils").e(
RuntimeException("Unable to find display name for $this"),
"LocaleUtils.getDisplayName(%s, %s)", this, inLocale
)
val e = RuntimeException("Unable to find display name for $this")
Timber.tag("LocaleUtils").e(e, "LocaleUtils.getDisplayName(%s, %s)", this, inLocale)
if (inLocale != null) getDisplayName(inLocale) else displayName
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class LocaleUtilsGetDisplayNameTest {
val resources = context.resources
every {
resources.getIdentifier(
"$STRING_RES_LANGUAGE_NAME_PREFIX${locale.toString().lowercase(Locale.ENGLISH)}", "string", PACKAGE_NAME
"$STRING_RES_LANGUAGE_NAME_PREFIX${locale.toString().lowercase(Locale.ENGLISH)}",
"string",
PACKAGE_NAME
)
} returns id
return every { resources.getString(id) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import java.util.Locale
import org.cru.godtools.model.TrainingTip

@Entity(tableName = "training_tips")
internal class TrainingTipEntity(@PrimaryKey @Embedded val key: Key) {
internal class TrainingTipEntity(
@PrimaryKey
@Embedded
val key: Key,
) {
internal data class Key(val tool: String, val locale: Locale, val tipId: String)

var isCompleted = false
Expand All @@ -17,6 +21,6 @@ internal class TrainingTipEntity(@PrimaryKey @Embedded val key: Key) {
tool = key.tool,
locale = key.locale,
tipId = key.tipId,
isCompleted = isCompleted
isCompleted = isCompleted,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,39 @@ class GodToolsDao @Inject internal constructor(
) : AbstractDao(database), CoroutinesAsyncDao, CoroutinesFlowDao, LiveDataDao {
init {
registerType(
Tool::class.java, ToolTable.TABLE_NAME, ToolTable.PROJECTION_ALL, ToolMapper,
Tool::class.java,
ToolTable.TABLE_NAME,
ToolTable.PROJECTION_ALL,
ToolMapper,
ToolTable.SQL_WHERE_PRIMARY_KEY
)
registerType(
Attachment::class.java, AttachmentTable.TABLE_NAME, AttachmentTable.PROJECTION_ALL, AttachmentMapper,
Attachment::class.java,
AttachmentTable.TABLE_NAME,
AttachmentTable.PROJECTION_ALL,
AttachmentMapper,
AttachmentTable.SQL_WHERE_PRIMARY_KEY
)
registerType(
Translation::class.java, TranslationTable.TABLE_NAME, TranslationTable.PROJECTION_ALL, TranslationMapper,
Translation::class.java,
TranslationTable.TABLE_NAME,
TranslationTable.PROJECTION_ALL,
TranslationMapper,
TranslationTable.SQL_WHERE_PRIMARY_KEY
)
registerType(
LocalFile::class.java, LocalFileTable.TABLE_NAME, LocalFileTable.PROJECTION_ALL, LocalFileMapper,
LocalFile::class.java,
LocalFileTable.TABLE_NAME,
LocalFileTable.PROJECTION_ALL,
LocalFileMapper,
LocalFileTable.SQL_WHERE_PRIMARY_KEY
)
registerType(
TranslationFile::class.java, TranslationFileTable.TABLE_NAME, TranslationFileTable.PROJECTION_ALL,
TranslationFileMapper, TranslationFileTable.SQL_WHERE_PRIMARY_KEY
TranslationFile::class.java,
TranslationFileTable.TABLE_NAME,
TranslationFileTable.PROJECTION_ALL,
TranslationFileMapper,
TranslationFileTable.SQL_WHERE_PRIMARY_KEY
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ class GodToolsDatabase @Inject internal constructor(
UserCounterTable.COLUMN_DECAYED_COUNT,
UserCounterTable.COLUMN_DELTA
),
null, emptyArray(), null, null, null
null,
emptyArray(),
null,
null,
null
).use {
while (it.moveToNext()) {
roomDb.userCountersRepository.migrateCounter(
Expand All @@ -131,7 +135,11 @@ class GodToolsDatabase @Inject internal constructor(
GlobalActivityAnalyticsTable.COLUMN_LAUNCHES,
GlobalActivityAnalyticsTable.COLUMN_GOSPEL_PRESENTATIONS
),
null, emptyArray(), null, null, null
null,
emptyArray(),
null,
null,
null
).use {
if (it.moveToFirst()) {
roomDb.globalActivityDao.insertOrIgnore(
Expand All @@ -156,7 +164,11 @@ class GodToolsDatabase @Inject internal constructor(
TrainingTipTable.COLUMN_TIP_ID,
TrainingTipTable.COLUMN_IS_COMPLETED
),
null, emptyArray(), null, null, null
null,
emptyArray(),
null,
null,
null
).use {
while (it.moveToNext()) {
roomDb.trainingTipDao.insertOrIgnoreBlocking(
Expand Down Expand Up @@ -187,7 +199,11 @@ class GodToolsDatabase @Inject internal constructor(
FollowupTable.COLUMN_DESTINATION,
FollowupTable.COLUMN_CREATE_TIME
),
null, emptyArray(), null, null, null
null,
emptyArray(),
null,
null,
null
).use {
while (it.moveToNext()) {
roomDb.followupsDao.insertBlocking(
Expand All @@ -213,7 +229,11 @@ class GodToolsDatabase @Inject internal constructor(
LanguageTable.COLUMN_CODE,
LanguageTable.COLUMN_NAME
),
null, emptyArray(), null, null, null
null,
emptyArray(),
null,
null,
null
).use {
roomDb.languagesDao.insertOrIgnoreLanguages(
it.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ internal class LegacyAttachmentsRepository @Inject constructor(private val dao:
attachments.forEach {
dao.updateOrInsert(
it,
AttachmentTable.COLUMN_TOOL, AttachmentTable.COLUMN_FILENAME, AttachmentTable.COLUMN_SHA256
AttachmentTable.COLUMN_TOOL,
AttachmentTable.COLUMN_FILENAME,
AttachmentTable.COLUMN_SHA256
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class GodToolsDownloadManager @VisibleForTesting internal constructor(
private val translationsRepository: TranslationsRepository,
private val workManager: Lazy<WorkManager>,
private val coroutineScope: CoroutineScope,
private val ioDispatcher: CoroutineContext = Dispatchers.IO
private val ioDispatcher: CoroutineContext = Dispatchers.IO,
) {
@Inject
internal constructor(
Expand All @@ -96,7 +96,7 @@ class GodToolsDownloadManager @VisibleForTesting internal constructor(
manifestParser: ManifestParser,
translationsApi: TranslationsApi,
translationsRepository: TranslationsRepository,
workManager: Lazy<WorkManager>
workManager: Lazy<WorkManager>,
) : this(
attachmentsApi,
attachmentsRepository,
Expand Down Expand Up @@ -322,7 +322,9 @@ class GodToolsDownloadManager @VisibleForTesting internal constructor(
if (body != null) {
body.byteStream().extractZipFor(translation, body.contentLength())
true
} else false
} else {
false
}
} catch (e: IOException) {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ internal class SyncRepository @Inject constructor(
toolsRepository.storeToolFromSync(tool)

// persist related included objects
if (includes.include(Tool.JSON_LATEST_TRANSLATIONS)) tool.latestTranslations?.let { translations ->
storeTranslations(
translations,
includes = includes.descendant(Tool.JSON_LATEST_TRANSLATIONS),
existing = tool.code?.let { code ->
BaseSyncTasks.index(
Query.select<Translation>().where(TranslationTable.FIELD_TOOL.eq(code)).get(dao)
)
}
)
if (includes.include(Tool.JSON_LATEST_TRANSLATIONS)) {
tool.latestTranslations?.let { translations ->
storeTranslations(
translations,
includes = includes.descendant(Tool.JSON_LATEST_TRANSLATIONS),
existing = tool.code?.let { code ->
BaseSyncTasks.index(
Query.select<Translation>().where(TranslationTable.FIELD_TOOL.eq(code)).get(dao)
)
}
)
}
}
if (includes.include(Tool.JSON_ATTACHMENTS)) tool.attachments?.let { attachments ->
attachmentsRepository.storeAttachmentsFromSync(attachments)
attachmentsRepository.removeAttachmentsMissingFromSync(tool.id, attachments)
if (includes.include(Tool.JSON_ATTACHMENTS)) {
tool.attachments?.let { attachments ->
attachmentsRepository.storeAttachmentsFromSync(attachments)
attachmentsRepository.removeAttachmentsMissingFromSync(tool.id, attachments)
}
}
if (includes.include(Tool.JSON_METATOOL)) {
tool.metatool?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ private const val STALE_DURATION_GLOBAL_ACTIVITY = DAY_IN_MS
internal class AnalyticsSyncTasks @Inject internal constructor(
private val analyticsApi: AnalyticsApi,
private val globalActivityRepository: GlobalActivityRepository,
private val lastSyncTimeRepository: LastSyncTimeRepository
private val lastSyncTimeRepository: LastSyncTimeRepository,
) : BaseSyncTasks() {
private val globalActivityMutex = Mutex()

suspend fun syncGlobalActivity(force: Boolean): Boolean = globalActivityMutex.withLock {
// short-circuit if we aren't forcing a sync and the data isn't stale
if (!force && !lastSyncTimeRepository
.isLastSyncStale(SYNC_TIME_GLOBAL_ACTIVITY, staleAfter = STALE_DURATION_GLOBAL_ACTIVITY)
) return@withLock true
.isLastSyncStale(SYNC_TIME_GLOBAL_ACTIVITY, staleAfter = STALE_DURATION_GLOBAL_ACTIVITY)
) {
return@withLock true
}

analyticsApi.getGlobalActivity().takeIf { it.isSuccessful }?.body()?.let {
globalActivityRepository.updateGlobalActivity(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ internal class LanguagesSyncTasks @Inject constructor(
// short-circuit if we aren't forcing a sync and the data isn't stale
if (!isForced(args) &&
!lastSyncTimeRepository.isLastSyncStale(SYNC_TIME_LANGUAGES, staleAfter = STALE_DURATION_LANGUAGES)
) return@withContext true
) {
return@withContext true
}

// fetch languages from the API
val json = languagesApi.list(JsonApiParams()).takeIf { it.isSuccessful }?.body() ?: return@withContext false
Expand Down
Loading

0 comments on commit bf94791

Please sign in to comment.