mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add system dark theme
This commit is contained in:
parent
0c418fdf9b
commit
8861fb5e95
9 changed files with 54 additions and 12 deletions
|
@ -97,7 +97,7 @@
|
||||||
-->
|
-->
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"
|
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation|uiMode"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.app.Activity
|
||||||
import android.app.PictureInPictureParams
|
import android.app.PictureInPictureParams
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
|
@ -276,12 +277,35 @@ object CommonActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateTheme(act: Activity) {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(act)
|
||||||
|
if (settingsManager
|
||||||
|
.getString(act.getString(R.string.app_theme_key), "AmoledLight") == "System"
|
||||||
|
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
loadThemes(act)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mapSystemTheme(act: Activity): Int {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
val currentNightMode =
|
||||||
|
act.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||||
|
return when (currentNightMode) {
|
||||||
|
Configuration.UI_MODE_NIGHT_NO -> R.style.LightMode // Night mode is not active, we're using the light theme
|
||||||
|
else -> R.style.AppTheme // Night mode is active, we're using dark theme
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return R.style.AppTheme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun loadThemes(act: Activity?) {
|
fun loadThemes(act: Activity?) {
|
||||||
if (act == null) return
|
if (act == null) return
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(act)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(act)
|
||||||
|
|
||||||
val currentTheme =
|
val currentTheme =
|
||||||
when (settingsManager.getString(act.getString(R.string.app_theme_key), "AmoledLight")) {
|
when (settingsManager.getString(act.getString(R.string.app_theme_key), "AmoledLight")) {
|
||||||
|
"System" -> mapSystemTheme(act)
|
||||||
"Black" -> R.style.AppTheme
|
"Black" -> R.style.AppTheme
|
||||||
"Light" -> R.style.LightMode
|
"Light" -> R.style.LightMode
|
||||||
"Amoled" -> R.style.AmoledMode
|
"Amoled" -> R.style.AmoledMode
|
||||||
|
|
|
@ -68,6 +68,7 @@ import com.lagradost.cloudstream3.CommonActivity.screenHeight
|
||||||
import com.lagradost.cloudstream3.CommonActivity.setActivityInstance
|
import com.lagradost.cloudstream3.CommonActivity.setActivityInstance
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
||||||
|
import com.lagradost.cloudstream3.CommonActivity.updateTheme
|
||||||
import com.lagradost.cloudstream3.databinding.ActivityMainBinding
|
import com.lagradost.cloudstream3.databinding.ActivityMainBinding
|
||||||
import com.lagradost.cloudstream3.databinding.ActivityMainTvBinding
|
import com.lagradost.cloudstream3.databinding.ActivityMainTvBinding
|
||||||
import com.lagradost.cloudstream3.databinding.BottomResultviewPreviewBinding
|
import com.lagradost.cloudstream3.databinding.BottomResultviewPreviewBinding
|
||||||
|
@ -484,6 +485,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
updateLocale() // android fucks me by chaining lang when rotating the phone
|
updateLocale() // android fucks me by chaining lang when rotating the phone
|
||||||
|
updateTheme(this) // Update if system theme
|
||||||
|
|
||||||
val navHostFragment =
|
val navHostFragment =
|
||||||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
||||||
|
|
|
@ -88,10 +88,9 @@ class SettingsUI : PreferenceFragmentCompat() {
|
||||||
getPref(R.string.app_theme_key)?.setOnPreferenceClickListener {
|
getPref(R.string.app_theme_key)?.setOnPreferenceClickListener {
|
||||||
val prefNames = resources.getStringArray(R.array.themes_names).toMutableList()
|
val prefNames = resources.getStringArray(R.array.themes_names).toMutableList()
|
||||||
val prefValues = resources.getStringArray(R.array.themes_names_values).toMutableList()
|
val prefValues = resources.getStringArray(R.array.themes_names_values).toMutableList()
|
||||||
|
val removeFunction = { text: String ->
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // remove monet on android 11 and less
|
|
||||||
val toRemove = prefValues
|
val toRemove = prefValues
|
||||||
.mapIndexed { idx, s -> if (s.startsWith("Monet")) idx else null }
|
.mapIndexed { idx, s -> if (s.startsWith(text)) idx else null }
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
var offset = 0
|
var offset = 0
|
||||||
toRemove.forEach { idx ->
|
toRemove.forEach { idx ->
|
||||||
|
@ -100,6 +99,12 @@ class SettingsUI : PreferenceFragmentCompat() {
|
||||||
offset += 1
|
offset += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // remove monet on android 11 and less
|
||||||
|
removeFunction("Monet")
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { // Remove system on android 9 and less
|
||||||
|
removeFunction("System")
|
||||||
|
}
|
||||||
|
|
||||||
val currentLayout =
|
val currentLayout =
|
||||||
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
|
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
|
||||||
|
@ -123,7 +128,8 @@ class SettingsUI : PreferenceFragmentCompat() {
|
||||||
}
|
}
|
||||||
getPref(R.string.primary_color_key)?.setOnPreferenceClickListener {
|
getPref(R.string.primary_color_key)?.setOnPreferenceClickListener {
|
||||||
val prefNames = resources.getStringArray(R.array.themes_overlay_names).toMutableList()
|
val prefNames = resources.getStringArray(R.array.themes_overlay_names).toMutableList()
|
||||||
val prefValues = resources.getStringArray(R.array.themes_overlay_names_values).toMutableList()
|
val prefValues =
|
||||||
|
resources.getStringArray(R.array.themes_overlay_names_values).toMutableList()
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // remove monet on android 11 and less
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // remove monet on android 11 and less
|
||||||
val toRemove = prefValues
|
val toRemove = prefValues
|
||||||
|
|
|
@ -243,13 +243,15 @@
|
||||||
|
|
||||||
|
|
||||||
<string-array name="themes_names">
|
<string-array name="themes_names">
|
||||||
|
<item>Sistema</item>
|
||||||
<item>Oscuro</item>
|
<item>Oscuro</item>
|
||||||
<item>Gris</item>
|
<item>Gris</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
<item>Destello</item>
|
<item>Destello</item>
|
||||||
<item>Material You</item>
|
<item>Material You (Android 12+)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="themes_names_values">
|
<string-array name="themes_names_values">
|
||||||
|
<item>System</item>
|
||||||
<item>AmoledLight</item>
|
<item>AmoledLight</item>
|
||||||
<item>Black</item>
|
<item>Black</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
|
|
|
@ -252,13 +252,15 @@
|
||||||
|
|
||||||
|
|
||||||
<string-array name="themes_names">
|
<string-array name="themes_names">
|
||||||
|
<item>System</item>
|
||||||
<item>Ciemny</item>
|
<item>Ciemny</item>
|
||||||
<item>Szary</item>
|
<item>Szary</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
<item>Flashbang</item>
|
<item>Flashbang</item>
|
||||||
<item>Material You</item>
|
<item>Material You (Android 12+)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="themes_names_values">
|
<string-array name="themes_names_values">
|
||||||
|
<item>System</item>
|
||||||
<item>AmoledLight</item>
|
<item>AmoledLight</item>
|
||||||
<item>Black</item>
|
<item>Black</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
|
|
|
@ -277,13 +277,15 @@
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="themes_names">
|
<string-array name="themes_names">
|
||||||
|
<item>Sistem</item>
|
||||||
<item>Koyu</item>
|
<item>Koyu</item>
|
||||||
<item>Gri</item>
|
<item>Gri</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
<item>Flaş Bombası</item>
|
<item>Flaş Bombası</item>
|
||||||
<item>Material You</item>
|
<item>Material You (Android 12+)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="themes_names_values">
|
<string-array name="themes_names_values">
|
||||||
|
<item>System</item>
|
||||||
<item>AmoledLight</item>
|
<item>AmoledLight</item>
|
||||||
<item>Black</item>
|
<item>Black</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
|
|
|
@ -244,13 +244,15 @@
|
||||||
|
|
||||||
|
|
||||||
<string-array name="themes_names">
|
<string-array name="themes_names">
|
||||||
|
<item>Hệ thống</item>
|
||||||
<item>Tối</item>
|
<item>Tối</item>
|
||||||
<item>Xám</item>
|
<item>Xám</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
<item>Sáng</item>
|
<item>Sáng</item>
|
||||||
<item>Material You</item>
|
<item>Material You (Android 12+)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="themes_names_values">
|
<string-array name="themes_names_values">
|
||||||
|
<item>System</item>
|
||||||
<item>AmoledLight</item>
|
<item>AmoledLight</item>
|
||||||
<item>Black</item>
|
<item>Black</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
|
|
|
@ -314,13 +314,15 @@
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="themes_names">
|
<string-array name="themes_names">
|
||||||
|
<item>System</item>
|
||||||
<item>Dark</item>
|
<item>Dark</item>
|
||||||
<item>Gray</item>
|
<item>Gray</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
<item>Flashbang</item>
|
<item>Flashbang</item>
|
||||||
<item>Material You</item>
|
<item>Material You (Android 12+)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="themes_names_values">
|
<string-array name="themes_names_values">
|
||||||
|
<item>System</item>
|
||||||
<item>AmoledLight</item>
|
<item>AmoledLight</item>
|
||||||
<item>Black</item>
|
<item>Black</item>
|
||||||
<item>Amoled</item>
|
<item>Amoled</item>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue