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
This commit is contained in:
Konrad Pozniak 2023-02-04 20:22:29 +01:00 committed by GitHub
parent 16df2bfe87
commit 006f0de05c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 57 deletions

View file

@ -153,7 +153,7 @@ fun Status.toEntity(
} }
fun TimelineStatusWithAccount.toViewData(gson: Gson, isDetailed: Boolean = false): StatusViewData { 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})") Log.d(TAG, "Constructing Placeholder(${this.status.serverId}, ${this.status.expanded})")
return StatusViewData.Placeholder(this.status.serverId, this.status.expanded) return StatusViewData.Placeholder(this.status.serverId, this.status.expanded)
} }

View file

@ -16,41 +16,18 @@
package com.keylesspalace.tusky.db package com.keylesspalace.tusky.db
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.RewriteQueriesToDropUnusedColumns import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.Transaction import androidx.room.Upsert
import androidx.room.Update
@Dao @Dao
interface InstanceDao { interface InstanceDao {
@Insert(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) @Upsert(entity = InstanceEntity::class)
suspend fun insertOrIgnore(instance: InstanceInfoEntity): Long suspend fun upsert(instance: InstanceInfoEntity)
@Update(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class) @Upsert(entity = InstanceEntity::class)
suspend fun updateOrIgnore(instance: InstanceInfoEntity) suspend fun upsert(emojis: EmojisEntity)
@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)
}
}
@RewriteQueriesToDropUnusedColumns @RewriteQueriesToDropUnusedColumns
@Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1") @Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1")

View file

@ -18,7 +18,7 @@ package com.keylesspalace.tusky.db
import androidx.paging.PagingSource import androidx.paging.PagingSource
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy.REPLACE import androidx.room.OnConflictStrategy.Companion.REPLACE
import androidx.room.Query import androidx.room.Query
@Dao @Dao

View file

@ -104,11 +104,11 @@ data class TimelineAccountEntity(
val bot: Boolean val bot: Boolean
) )
class TimelineStatusWithAccount { data class TimelineStatusWithAccount(
@Embedded @Embedded
lateinit var status: TimelineStatusEntity val status: TimelineStatusEntity,
@Embedded(prefix = "a_") @Embedded(prefix = "a_")
lateinit var account: TimelineAccountEntity val account: TimelineAccountEntity? = null, // null when placeholder
@Embedded(prefix = "rb_") @Embedded(prefix = "rb_")
var reblogAccount: TimelineAccountEntity? = null val reblogAccount: TimelineAccountEntity? = null // null when no reblog
} )

View file

@ -193,9 +193,9 @@ class CachedTimelineRemoteMediatorTest {
listOf( listOf(
mockStatusEntityWithAccount("8"), mockStatusEntityWithAccount("8"),
mockStatusEntityWithAccount("7"), mockStatusEntityWithAccount("7"),
TimelineStatusWithAccount().apply { TimelineStatusWithAccount(
status = Placeholder("5", loading = false).toEntity(1) status = Placeholder("5", loading = false).toEntity(1)
}, ),
mockStatusEntityWithAccount("3"), mockStatusEntityWithAccount("3"),
mockStatusEntityWithAccount("2"), mockStatusEntityWithAccount("2"),
mockStatusEntityWithAccount("1"), mockStatusEntityWithAccount("1"),
@ -547,8 +547,8 @@ class CachedTimelineRemoteMediatorTest {
private fun AppDatabase.insert(statuses: List<TimelineStatusWithAccount>) { private fun AppDatabase.insert(statuses: List<TimelineStatusWithAccount>) {
runBlocking { runBlocking {
statuses.forEach { statusWithAccount -> statuses.forEach { statusWithAccount ->
if (!statusWithAccount.status.isPlaceholder) { statusWithAccount.account?.let { account ->
timelineDao().insertAccount(statusWithAccount.account) timelineDao().insertAccount(account)
} }
statusWithAccount.reblogAccount?.let { account -> statusWithAccount.reblogAccount?.let { account ->
timelineDao().insertAccount(account) timelineDao().insertAccount(account)

View file

@ -92,26 +92,26 @@ fun mockStatusEntityWithAccount(
val mockedStatus = mockStatus(id) val mockedStatus = mockStatus(id)
val gson = Gson() val gson = Gson()
return TimelineStatusWithAccount().apply { return TimelineStatusWithAccount(
status = mockedStatus.toEntity( status = mockedStatus.toEntity(
timelineUserId = userId, timelineUserId = userId,
gson = gson, gson = gson,
expanded = expanded, expanded = expanded,
contentShowing = false, contentShowing = false,
contentCollapsed = true contentCollapsed = true
) ),
account = mockedStatus.account.toEntity( account = mockedStatus.account.toEntity(
accountId = userId, accountId = userId,
gson = gson gson = gson
) )
} )
} }
fun mockPlaceholderEntityWithAccount( fun mockPlaceholderEntityWithAccount(
id: String, id: String,
userId: Long = 1, userId: Long = 1,
): TimelineStatusWithAccount { ): TimelineStatusWithAccount {
return TimelineStatusWithAccount().apply { return TimelineStatusWithAccount(
status = Placeholder(id, false).toEntity(userId) status = Placeholder(id, false).toEntity(userId)
} )
} }

View file

@ -1,30 +1,31 @@
[versions] [versions]
agp = "7.4.0" agp = "7.4.1"
androidx-activity = "1.6.0" androidx-activity = "1.6.1"
androidx-appcompat = "1.6.0-rc01" androidx-appcompat = "1.6.0"
androidx-browser = "1.4.0" androidx-browser = "1.4.0"
androidx-cardview = "1.0.0" androidx-cardview = "1.0.0"
androidx-constraintlayout = "2.1.4" androidx-constraintlayout = "2.1.4"
androidx-core = "1.9.0" androidx-core = "1.9.0"
androidx-exifinterface = "1.3.4" androidx-exifinterface = "1.3.5"
androidx-fragment = "1.5.3" androidx-fragment = "1.5.5"
androidx-junit = "1.1.3" androidx-junit = "1.1.5"
androidx-paging = "3.1.1" androidx-paging = "3.1.1"
androidx-preference = "1.2.0" androidx-preference = "1.2.0"
androidx-recyclerview = "1.1.0" androidx-recyclerview = "1.2.1"
androidx-sharetarget = "1.2.0" androidx-sharetarget = "1.2.0"
androidx-splashscreen = "1.0.0" androidx-splashscreen = "1.0.0"
androidx-swiperefresh-layout = "1.1.0" androidx-swiperefresh-layout = "1.1.0"
androidx-testing = "2.1.0" androidx-testing = "2.1.0"
androidx-viewpager2 = "1.0.0" androidx-viewpager2 = "1.0.0"
androidx-work = "2.7.1" androidx-work = "2.7.1"
androidx-room = "2.5.0"
autodispose = "2.1.1" autodispose = "2.1.1"
bouncycastle = "1.70" bouncycastle = "1.70"
conscrypt = "2.5.2" conscrypt = "2.5.2"
coroutines = "1.6.4" coroutines = "1.6.4"
dagger = "2.43.2" dagger = "2.43.2"
emoji2 = "1.1.0" emoji2 = "1.1.0"
espresso = "3.4.0" espresso = "3.5.1"
filemoji-compat = "3.2.7" filemoji-compat = "3.2.7"
glide = "4.13.2" glide = "4.13.2"
glide-animation-plugin = "2.23.0" glide-animation-plugin = "2.23.0"
@ -41,7 +42,6 @@ networkresult-calladapter = "1.0.0"
okhttp = "4.10.0" okhttp = "4.10.0"
retrofit = "2.9.0" retrofit = "2.9.0"
robolectric = "4.8.1" robolectric = "4.8.1"
room = "2.4.3"
rxandroid3 = "3.0.0" rxandroid3 = "3.0.0"
rxjava3 = "3.1.3" rxjava3 = "3.1.3"
rxkotlin3 = "3.0.1" 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-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-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-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "androidx-preference" }
androidx-room-compiler = { module = "androidx.room:room-compiler", 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 = "room" } androidx-room-paging = { module = "androidx.room:room-paging", version.ref = "androidx-room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" } androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidx-room" }
androidx-room-testing = { module = "androidx.room:room-testing", version.ref = "room" } androidx-room-testing = { module = "androidx.room:room-testing", version.ref = "androidx-room" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" } androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" }
androidx-sharetarget = { module = "androidx.sharetarget:sharetarget", version.ref = "androidx-sharetarget" } androidx-sharetarget = { module = "androidx.sharetarget:sharetarget", version.ref = "androidx-sharetarget" }
androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefresh-layout" } androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefresh-layout" }