Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require app restart when changing the use_median setting #476

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/src/main/java/hu/vmiklos/plees_tracker/DataModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.util.Log
import android.widget.Toast
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData
import androidx.lifecycle.switchMap
import androidx.room.Room
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
Expand Down Expand Up @@ -167,7 +168,14 @@ object DataModel {
}

fun getSleepsAfterLive(after: Date): LiveData<List<Sleep>> {
return database.sleepDao().getAfterLive(after.time)
// Callable, so we update if any of the below LiveDatas change.
val afterSleep = {
database.sleepDao().getAfterLive(after.time)
}
val useMedian = preferences.liveDataBoolean("use_median", false).switchMap { _ ->
afterSleep()
}
return useMedian
}

suspend fun importData(context: Context, cr: ContentResolver, uri: Uri) {
Expand Down