Skip to content

Commit

Permalink
Support night mode on Android 29+
Browse files Browse the repository at this point in the history
  • Loading branch information
ninovanhooff committed Oct 20, 2021
1 parent 0f2ff00 commit 35d4862
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,14 +12,13 @@ internal object PreferencesCollector {
fun collect(context: Context) = mutableMapOf<String, Serializable>().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)
}
}

0 comments on commit 35d4862

Please sign in to comment.