From d03751e59cf8e51faf23fbfeab53920ef1553ab7 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Wed, 13 Feb 2019 19:20:43 +0100 Subject: [PATCH] call db operation on background thread in TabPreferenceActivity (#1036) --- .../keylesspalace/tusky/TabPreferenceActivity.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt index ffdbf8b7..6f975ec7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt @@ -17,6 +17,7 @@ package com.keylesspalace.tusky import android.os.Bundle import android.view.MenuItem +import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -27,10 +28,15 @@ import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.MainTabsChangedEvent import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.util.visible +import io.reactivex.Single +import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_tab_preference.* import kotlinx.android.synthetic.main.toolbar_basic.* import javax.inject.Inject +import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from +import com.uber.autodispose.autoDisposable + class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListener { @Inject @@ -171,8 +177,14 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene private fun saveTabs() { accountManager.activeAccount?.let { - it.tabPreferences = currentTabs - accountManager.saveAccount(it) + Single.fromCallable { + it.tabPreferences = currentTabs + accountManager.saveAccount(it) + } + .subscribeOn(Schedulers.io()) + .autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)) + .subscribe() + } }