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:
parent
16df2bfe87
commit
006f0de05c
7 changed files with 34 additions and 57 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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<TimelineStatusWithAccount>) {
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue