Skip to content

Commit

Permalink
Merge pull request #1622 from instructure/release/teacher-1.18.2-50
Browse files Browse the repository at this point in the history
Release Teacher 1.18.2 (50)
  • Loading branch information
hermannakos authored Jun 24, 2022
2 parents 2341a51 + adfd4d5 commit 679761c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/teacher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
defaultConfig {
minSdkVersion Versions.MIN_SDK
targetSdkVersion Versions.TARGET_SDK
versionCode = 49
versionName = '1.18.1'
versionCode = 50
versionName = '1.18.2'
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner 'com.instructure.teacher.ui.espresso.TeacherHiltTestRunner'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.instructure.pandautils.utils
import android.content.Context
import android.content.res.Configuration
import android.webkit.JavascriptInterface
import android.webkit.WebSettings
import android.webkit.WebView
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
Expand Down Expand Up @@ -158,17 +159,23 @@ fun WebView.setDarkModeSupport(webThemeDarkeningOnly: Boolean = false) {
val nightModeFlags: Int = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON)
if (webThemeDarkeningOnly) {
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY)
} else {
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING)
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
setForceDarkStrategy(webThemeDarkeningOnly, settings)
}
} else {
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF)
}
}
}

private fun setForceDarkStrategy(webThemeDarkeningOnly: Boolean, settings: WebSettings) {
if (webThemeDarkeningOnly) {
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY)
} else {
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING)
}
}

fun WebView.addDarkThemeToHtmlDocument() {
val css = """
@media (prefers-color-scheme: dark) {
Expand Down

0 comments on commit 679761c

Please sign in to comment.