Skip to content

Commit

Permalink
fix strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Aug 17, 2024
1 parent 1c3f78e commit 2c9dd79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ inline fun <T, R> T.allowDiskWrite(block: T.() -> R): R {
}
}

inline fun <T, R> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +25,7 @@ class MainViewModel @Inject constructor(
val isNavBatAtTheBottom: LiveData<Boolean> by lazySuspend { loadIsNavBatAtTheBottom() }

private fun syncState() {
viewModelScope.launch {
allowDiskRead { viewModelScope }.launch {
notificationTypeInteractor.updateNotifications()
widgetInteractor.updateWidgets()
wearInteractor.update()
Expand Down

0 comments on commit 2c9dd79

Please sign in to comment.