From 2c9dd79622353cc3cebd445c29cd622ca22f9366 Mon Sep 17 00:00:00 2001 From: razeeman Date: Sat, 17 Aug 2024 08:38:42 +0300 Subject: [PATCH] fix strict mode --- .../simpletimetracker/core/extension/OtherExtensions.kt | 9 +++++++++ .../feature_main/viewModel/MainViewModel.kt | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/extension/OtherExtensions.kt b/core/src/main/java/com/example/util/simpletimetracker/core/extension/OtherExtensions.kt index b3ff56e31..a9d948f9a 100644 --- a/core/src/main/java/com/example/util/simpletimetracker/core/extension/OtherExtensions.kt +++ b/core/src/main/java/com/example/util/simpletimetracker/core/extension/OtherExtensions.kt @@ -23,6 +23,15 @@ inline fun T.allowDiskWrite(block: T.() -> R): R { } } +inline fun T.allowDiskRead(block: T.() -> R): R { + val oldPolicy = StrictMode.allowThreadDiskReads() + try { + return block() + } finally { + StrictMode.setThreadPolicy(oldPolicy) + } +} + fun Calendar.setWeekToFirstDay() { val another = Calendar.getInstance() another.timeInMillis = timeInMillis diff --git a/features/feature_main/src/main/java/com/example/util/simpletimetracker/feature_main/viewModel/MainViewModel.kt b/features/feature_main/src/main/java/com/example/util/simpletimetracker/feature_main/viewModel/MainViewModel.kt index a806fcd4c..fcdc7fc42 100644 --- a/features/feature_main/src/main/java/com/example/util/simpletimetracker/feature_main/viewModel/MainViewModel.kt +++ b/features/feature_main/src/main/java/com/example/util/simpletimetracker/feature_main/viewModel/MainViewModel.kt @@ -3,6 +3,7 @@ package com.example.util.simpletimetracker.feature_main.viewModel import androidx.lifecycle.LiveData import androidx.lifecycle.viewModelScope import com.example.util.simpletimetracker.core.base.BaseViewModel +import com.example.util.simpletimetracker.core.extension.allowDiskRead import com.example.util.simpletimetracker.core.extension.lazySuspend import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor @@ -24,7 +25,7 @@ class MainViewModel @Inject constructor( val isNavBatAtTheBottom: LiveData by lazySuspend { loadIsNavBatAtTheBottom() } private fun syncState() { - viewModelScope.launch { + allowDiskRead { viewModelScope }.launch { notificationTypeInteractor.updateNotifications() widgetInteractor.updateWidgets() wearInteractor.update()