update Room to 2.1.0 (#1323)

This commit is contained in:
Konrad Pozniak 2019-06-17 13:43:11 +02:00 committed by GitHub
parent 4b96c1e3f4
commit 22bd0462b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 18 deletions

View file

@ -124,10 +124,10 @@ dependencies {
// architecture components
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
//room
implementation 'androidx.room:room-runtime:2.0.0'
implementation 'androidx.room:room-runtime:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
implementation 'androidx.room:room-rxjava2:2.0.0'
kapt 'androidx.room:room-compiler:2.1.0'
implementation 'androidx.room:room-rxjava2:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"

View file

@ -11,7 +11,6 @@ import com.keylesspalace.tusky.db.AppDatabase
import com.keylesspalace.tusky.network.TimelineCases
import com.keylesspalace.tusky.util.Listing
import com.keylesspalace.tusky.util.NetworkState
import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
@ -55,10 +54,9 @@ class ConversationsViewModel @Inject constructor(
val newConversation = conversation.copy(
lastStatus = conversation.lastStatus.copy(favourited = favourite)
)
Single.fromCallable {
database.conversationDao().insert(newConversation)
}
}
.subscribeOn(Schedulers.io())
.doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) }
.subscribe()
@ -74,10 +72,9 @@ class ConversationsViewModel @Inject constructor(
val newConversation = conversation.copy(
lastStatus = conversation.lastStatus.copy(poll = poll)
)
Single.fromCallable {
database.conversationDao().insert(newConversation)
}
}
.subscribeOn(Schedulers.io())
.doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) }
.subscribe()
@ -118,18 +115,14 @@ class ConversationsViewModel @Inject constructor(
/* this is not ideal since deleting last toot from an conversation
should not delete the conversation but show another toot of the conversation */
timelineCases.delete(conversation.lastStatus.id)
Single.fromCallable {
database.conversationDao().delete(conversation)
}
.subscribeOn(Schedulers.io())
.subscribe()
}
}
private fun saveConversationToDb(conversation: ConversationEntity) {
Single.fromCallable {
database.conversationDao().insert(conversation)
}
.subscribeOn(Schedulers.io())
.subscribe()
}

View file

@ -18,6 +18,7 @@ package com.keylesspalace.tusky.db
import androidx.paging.DataSource
import androidx.room.*
import com.keylesspalace.tusky.components.conversation.ConversationEntity
import io.reactivex.Single
@Dao
interface ConversationsDao {
@ -25,10 +26,10 @@ interface ConversationsDao {
fun insert(conversations: List<ConversationEntity>)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(conversation: ConversationEntity)
fun insert(conversation: ConversationEntity): Single<Long>
@Delete
fun delete(conversation: ConversationEntity)
fun delete(conversation: ConversationEntity): Single<Int>
@Query("SELECT * FROM ConversationEntity WHERE accountId = :accountId ORDER BY s_createdAt DESC")
fun conversationsForAccount(accountId: Long) : DataSource.Factory<Int, ConversationEntity>