From 9094a6d438c5b022ad644b08f7b43934354deb69 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Mon, 17 Jun 2019 13:43:11 +0200 Subject: [PATCH] update Room to 2.1.0 (#1323) --- app/build.gradle | 6 +++--- .../conversation/ConversationsViewModel.kt | 19 ++++++------------- .../tusky/db/ConversationsDao.kt | 5 +++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e93db150..9e2347b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsViewModel.kt index 924c5c74..212e92cc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsViewModel.kt @@ -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,9 +54,8 @@ class ConversationsViewModel @Inject constructor( val newConversation = conversation.copy( lastStatus = conversation.lastStatus.copy(favourited = favourite) ) - Single.fromCallable { - database.conversationDao().insert(newConversation) - } + + database.conversationDao().insert(newConversation) } .subscribeOn(Schedulers.io()) .doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) } @@ -74,9 +72,8 @@ class ConversationsViewModel @Inject constructor( val newConversation = conversation.copy( lastStatus = conversation.lastStatus.copy(poll = poll) ) - Single.fromCallable { - database.conversationDao().insert(newConversation) - } + + database.conversationDao().insert(newConversation) } .subscribeOn(Schedulers.io()) .doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) } @@ -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) - } + database.conversationDao().delete(conversation) .subscribeOn(Schedulers.io()) .subscribe() } } private fun saveConversationToDb(conversation: ConversationEntity) { - Single.fromCallable { - database.conversationDao().insert(conversation) - } + database.conversationDao().insert(conversation) .subscribeOn(Schedulers.io()) .subscribe() } diff --git a/app/src/main/java/com/keylesspalace/tusky/db/ConversationsDao.kt b/app/src/main/java/com/keylesspalace/tusky/db/ConversationsDao.kt index 9a4896df..00f32f53 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/ConversationsDao.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/ConversationsDao.kt @@ -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) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(conversation: ConversationEntity) + fun insert(conversation: ConversationEntity): Single @Delete - fun delete(conversation: ConversationEntity) + fun delete(conversation: ConversationEntity): Single @Query("SELECT * FROM ConversationEntity WHERE accountId = :accountId ORDER BY s_createdAt DESC") fun conversationsForAccount(accountId: Long) : DataSource.Factory