diff --git a/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt b/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt
index beaa6307a..edac165d4 100644
--- a/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt
+++ b/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt
@@ -26,7 +26,8 @@ class Debug : InjectingPreferenceFragment() {
R.string.p_leakcanary,
R.string.p_flipper,
R.string.p_strict_mode_vm,
- R.string.p_strict_mode_thread
+ R.string.p_strict_mode_thread,
+ R.string.p_debug_main_queries
)) {
findPreference(pref)
.setOnPreferenceChangeListener { _: Preference?, _: Any? ->
diff --git a/app/src/debug/res/values/keys.xml b/app/src/debug/res/values/keys.xml
index 51aa9039c..746472754 100644
--- a/app/src/debug/res/values/keys.xml
+++ b/app/src/debug/res/values/keys.xml
@@ -13,4 +13,7 @@
debug_themes
debug_tasker
Reset SSL certificates
+ Allow queries on main thread
+
+ debug_main_queries
\ No newline at end of file
diff --git a/app/src/debug/res/xml/preferences_debug.xml b/app/src/debug/res/xml/preferences_debug.xml
index 4676536f2..fd997c92f 100644
--- a/app/src/debug/res/xml/preferences_debug.xml
+++ b/app/src/debug/res/xml/preferences_debug.xml
@@ -17,6 +17,11 @@
android:key="@string/p_strict_mode_vm"
android:title="@string/debug_strict_mode_vm"/>
+
+
diff --git a/app/src/main/java/org/tasks/injection/ProductionModule.kt b/app/src/main/java/org/tasks/injection/ProductionModule.kt
index 7b3e6e09b..abc088131 100644
--- a/app/src/main/java/org/tasks/injection/ProductionModule.kt
+++ b/app/src/main/java/org/tasks/injection/ProductionModule.kt
@@ -8,6 +8,8 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent
import dagger.hilt.android.qualifiers.ApplicationContext
+import org.tasks.BuildConfig
+import org.tasks.R
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskListDao
import org.tasks.db.Migrations
@@ -21,11 +23,13 @@ import javax.inject.Singleton
internal class ProductionModule {
@Provides
@Singleton
- fun getAppDatabase(@ApplicationContext context: Context): Database {
- return Room.databaseBuilder(context, Database::class.java, Database.NAME)
- .allowMainThreadQueries() // TODO: remove me
+ fun getAppDatabase(@ApplicationContext context: Context, preferences: Preferences): Database {
+ val builder = Room.databaseBuilder(context, Database::class.java, Database.NAME)
.addMigrations(*Migrations.MIGRATIONS)
- .build()
+ if (!BuildConfig.DEBUG || preferences.getBoolean(R.string.p_debug_main_queries, true)) {
+ builder.allowMainThreadQueries()
+ }
+ return builder.build()
}
@Provides