From 35d48624c627ffcbee2159b5abd55990dc4fcfd2 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Wed, 20 Oct 2021 17:34:49 +0200 Subject: [PATCH] Support night mode on Android 29+ --- .../library/collector/PreferencesCollector.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/q42stats/src/main/java/com/q42/q42stats/library/collector/PreferencesCollector.kt b/q42stats/src/main/java/com/q42/q42stats/library/collector/PreferencesCollector.kt index 7dff7c7..195b46d 100644 --- a/q42stats/src/main/java/com/q42/q42stats/library/collector/PreferencesCollector.kt +++ b/q42stats/src/main/java/com/q42/q42stats/library/collector/PreferencesCollector.kt @@ -1,6 +1,7 @@ package com.q42.q42stats.library.collector import android.content.Context +import android.content.res.Configuration import android.os.Build import com.q42.q42stats.library.util.DayTimeUtil import java.io.Serializable @@ -11,14 +12,13 @@ internal object PreferencesCollector { fun collect(context: Context) = mutableMapOf().apply { val configuration = context.resources.configuration - put( - "isNightModeEnabled", - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - configuration.isNightModeActive - } else { - false - } - ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + put( + "isNightModeEnabled", + configuration.uiMode + .and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES + ) + } put("daytime", DayTimeUtil.dayNight().serverValue) } } \ No newline at end of file