From 006f0de05c80111745c8231a0191d97960635026 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 4 Feb 2023 20:22:29 +0100 Subject: [PATCH] Upgrade AndroidX dependencies (#3169) * upgrade AndroidX dependencies * use new @Upsert in InstanceDao * fix crash because of new Room nullchecks * make TimelineStatusEntity.reblogAccount a val as well --- .../timeline/TimelineTypeMappers.kt | 2 +- .../com/keylesspalace/tusky/db/InstanceDao.kt | 33 +++---------------- .../com/keylesspalace/tusky/db/TimelineDao.kt | 2 +- .../tusky/db/TimelineStatusEntity.kt | 10 +++--- .../CachedTimelineRemoteMediatorTest.kt | 8 ++--- .../tusky/components/timeline/StatusMocker.kt | 10 +++--- gradle/libs.versions.toml | 26 +++++++-------- 7 files changed, 34 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt index dc220b3f7..24bc544d8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt @@ -153,7 +153,7 @@ fun Status.toEntity( } fun TimelineStatusWithAccount.toViewData(gson: Gson, isDetailed: Boolean = false): StatusViewData { - if (this.status.isPlaceholder) { + if (this.account == null) { Log.d(TAG, "Constructing Placeholder(${this.status.serverId}, ${this.status.expanded})") return StatusViewData.Placeholder(this.status.serverId, this.status.expanded) } diff --git a/app/src/main/java/com/keylesspalace/tusky/db/InstanceDao.kt b/app/src/main/java/com/keylesspalace/tusky/db/InstanceDao.kt index 0bf1dc32c..317c577ec 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/InstanceDao.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/InstanceDao.kt @@ -16,41 +16,18 @@ package com.keylesspalace.tusky.db import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.RewriteQueriesToDropUnusedColumns -import androidx.room.Transaction -import androidx.room.Update +import androidx.room.Upsert @Dao interface InstanceDao { - @Insert(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) - suspend fun insertOrIgnore(instance: InstanceInfoEntity): Long + @Upsert(entity = InstanceEntity::class) + suspend fun upsert(instance: InstanceInfoEntity) - @Update(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) - suspend fun updateOrIgnore(instance: InstanceInfoEntity) - - @Transaction - suspend fun upsert(instance: InstanceInfoEntity) { - if (insertOrIgnore(instance) == -1L) { - updateOrIgnore(instance) - } - } - - @Insert(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) - suspend fun insertOrIgnore(emojis: EmojisEntity): Long - - @Update(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) - suspend fun updateOrIgnore(emojis: EmojisEntity) - - @Transaction - suspend fun upsert(emojis: EmojisEntity) { - if (insertOrIgnore(emojis) == -1L) { - updateOrIgnore(emojis) - } - } + @Upsert(entity = InstanceEntity::class) + suspend fun upsert(emojis: EmojisEntity) @RewriteQueriesToDropUnusedColumns @Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1") diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt index ddf0c9559..d8423600a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt @@ -18,7 +18,7 @@ package com.keylesspalace.tusky.db import androidx.paging.PagingSource import androidx.room.Dao import androidx.room.Insert -import androidx.room.OnConflictStrategy.REPLACE +import androidx.room.OnConflictStrategy.Companion.REPLACE import androidx.room.Query @Dao diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt b/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt index 3bc4bc7df..ff63faf81 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt @@ -104,11 +104,11 @@ data class TimelineAccountEntity( val bot: Boolean ) -class TimelineStatusWithAccount { +data class TimelineStatusWithAccount( @Embedded - lateinit var status: TimelineStatusEntity + val status: TimelineStatusEntity, @Embedded(prefix = "a_") - lateinit var account: TimelineAccountEntity + val account: TimelineAccountEntity? = null, // null when placeholder @Embedded(prefix = "rb_") - var reblogAccount: TimelineAccountEntity? = null -} + val reblogAccount: TimelineAccountEntity? = null // null when no reblog +) diff --git a/app/src/test/java/com/keylesspalace/tusky/components/timeline/CachedTimelineRemoteMediatorTest.kt b/app/src/test/java/com/keylesspalace/tusky/components/timeline/CachedTimelineRemoteMediatorTest.kt index a055eeee4..00802caba 100644 --- a/app/src/test/java/com/keylesspalace/tusky/components/timeline/CachedTimelineRemoteMediatorTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/components/timeline/CachedTimelineRemoteMediatorTest.kt @@ -193,9 +193,9 @@ class CachedTimelineRemoteMediatorTest { listOf( mockStatusEntityWithAccount("8"), mockStatusEntityWithAccount("7"), - TimelineStatusWithAccount().apply { + TimelineStatusWithAccount( status = Placeholder("5", loading = false).toEntity(1) - }, + ), mockStatusEntityWithAccount("3"), mockStatusEntityWithAccount("2"), mockStatusEntityWithAccount("1"), @@ -547,8 +547,8 @@ class CachedTimelineRemoteMediatorTest { private fun AppDatabase.insert(statuses: List) { runBlocking { statuses.forEach { statusWithAccount -> - if (!statusWithAccount.status.isPlaceholder) { - timelineDao().insertAccount(statusWithAccount.account) + statusWithAccount.account?.let { account -> + timelineDao().insertAccount(account) } statusWithAccount.reblogAccount?.let { account -> timelineDao().insertAccount(account) diff --git a/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt b/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt index e9c242386..eef02d936 100644 --- a/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt +++ b/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt @@ -92,26 +92,26 @@ fun mockStatusEntityWithAccount( val mockedStatus = mockStatus(id) val gson = Gson() - return TimelineStatusWithAccount().apply { + return TimelineStatusWithAccount( status = mockedStatus.toEntity( timelineUserId = userId, gson = gson, expanded = expanded, contentShowing = false, contentCollapsed = true - ) + ), account = mockedStatus.account.toEntity( accountId = userId, gson = gson ) - } + ) } fun mockPlaceholderEntityWithAccount( id: String, userId: Long = 1, ): TimelineStatusWithAccount { - return TimelineStatusWithAccount().apply { + return TimelineStatusWithAccount( status = Placeholder(id, false).toEntity(userId) - } + ) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e9f2f0834..5921f8e6b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,30 +1,31 @@ [versions] -agp = "7.4.0" -androidx-activity = "1.6.0" -androidx-appcompat = "1.6.0-rc01" +agp = "7.4.1" +androidx-activity = "1.6.1" +androidx-appcompat = "1.6.0" androidx-browser = "1.4.0" androidx-cardview = "1.0.0" androidx-constraintlayout = "2.1.4" androidx-core = "1.9.0" -androidx-exifinterface = "1.3.4" -androidx-fragment = "1.5.3" -androidx-junit = "1.1.3" +androidx-exifinterface = "1.3.5" +androidx-fragment = "1.5.5" +androidx-junit = "1.1.5" androidx-paging = "3.1.1" androidx-preference = "1.2.0" -androidx-recyclerview = "1.1.0" +androidx-recyclerview = "1.2.1" androidx-sharetarget = "1.2.0" androidx-splashscreen = "1.0.0" androidx-swiperefresh-layout = "1.1.0" androidx-testing = "2.1.0" androidx-viewpager2 = "1.0.0" androidx-work = "2.7.1" +androidx-room = "2.5.0" autodispose = "2.1.1" bouncycastle = "1.70" conscrypt = "2.5.2" coroutines = "1.6.4" dagger = "2.43.2" emoji2 = "1.1.0" -espresso = "3.4.0" +espresso = "3.5.1" filemoji-compat = "3.2.7" glide = "4.13.2" glide-animation-plugin = "2.23.0" @@ -41,7 +42,6 @@ networkresult-calladapter = "1.0.0" okhttp = "4.10.0" retrofit = "2.9.0" robolectric = "4.8.1" -room = "2.4.3" rxandroid3 = "3.0.0" rxjava3 = "3.1.3" rxkotlin3 = "3.0.1" @@ -77,10 +77,10 @@ androidx-lifecycle-reactivestreams-ktx = { module = "androidx.lifecycle:lifecycl androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" } androidx-paging-runtime-ktx = { module = "androidx.paging:paging-runtime-ktx", version.ref = "androidx-paging" } androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "androidx-preference" } -androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" } -androidx-room-paging = { module = "androidx.room:room-paging", version.ref = "room" } -androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" } -androidx-room-testing = { module = "androidx.room:room-testing", version.ref = "room" } +androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidx-room" } +androidx-room-paging = { module = "androidx.room:room-paging", version.ref = "androidx-room" } +androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidx-room" } +androidx-room-testing = { module = "androidx.room:room-testing", version.ref = "androidx-room" } androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" } androidx-sharetarget = { module = "androidx.sharetarget:sharetarget", version.ref = "androidx-sharetarget" } androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefresh-layout" }