From 1ababc8c7fc821b6c7641a37fdf02e2b19e45933 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 2 Aug 2019 01:20:16 -0700 Subject: [PATCH] RepoDB does not need to run on main thread --- .../java/com/topjohnwu/magisk/di/DatabaseModule.kt | 1 - .../topjohnwu/magisk/ui/settings/SettingsFragment.kt | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt index 0ccaef70b..5a5cbeb47 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt @@ -20,5 +20,4 @@ val databaseModule = module { fun createRepoDatabase(context: Context) = Room.databaseBuilder(context, RepoDatabase::class.java, "repo.db") .fallbackToDestructiveMigration() - .allowMainThreadQueries() .build() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt index 78a87b5aa..8fc2496fc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt @@ -33,6 +33,7 @@ import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog import com.topjohnwu.net.Networking import com.topjohnwu.superuser.Shell +import io.reactivex.Completable import org.koin.android.ext.android.inject import java.io.File @@ -83,13 +84,15 @@ class SettingsFragment : BasePreferenceFragment() { true } findPreference("clear").setOnPreferenceClickListener { - repoDB.clear() - Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT) + Completable.fromAction { repoDB.clear() }.subscribeK { + Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT) + } true } findPreference("hosts").setOnPreferenceClickListener { - Shell.su("add_hosts_module").exec() - Utils.toast(R.string.settings_hosts_toast, Toast.LENGTH_SHORT) + Shell.su("add_hosts_module").submit { + Utils.toast(R.string.settings_hosts_toast, Toast.LENGTH_SHORT) + } true }