3
3
Fork 1
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:
EdgarPi 2024-07-22 18:11:52 +02:00
parent 0c418fdf9b
commit 8861fb5e95
9 changed files with 54 additions and 12 deletions
app/src/main
AndroidManifest.xml
java/com/lagradost/cloudstream3
res
values-es
values-pl
values-tr
values-vi
values

View file

@ -97,7 +97,7 @@
-->
<activity
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:launchMode="singleTask"
android:resizeableActivity="true"

View file

@ -5,6 +5,7 @@ import android.app.Activity
import android.app.PictureInPictureParams
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Build
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?) {
if (act == null) return
val settingsManager = PreferenceManager.getDefaultSharedPreferences(act)
val currentTheme =
when (settingsManager.getString(act.getString(R.string.app_theme_key), "AmoledLight")) {
"System" -> mapSystemTheme(act)
"Black" -> R.style.AppTheme
"Light" -> R.style.LightMode
"Amoled" -> R.style.AmoledMode
@ -352,8 +376,8 @@ object CommonActivity {
currentLook = currentLook.parent as? View ?: break
}*/
private fun View.hasContent() : Boolean {
return isShown && when(this) {
private fun View.hasContent(): Boolean {
return isShown && when (this) {
//is RecyclerView -> this.childCount > 0
is ViewGroup -> this.childCount > 0
else -> true

View file

@ -68,6 +68,7 @@ import com.lagradost.cloudstream3.CommonActivity.screenHeight
import com.lagradost.cloudstream3.CommonActivity.setActivityInstance
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.CommonActivity.updateLocale
import com.lagradost.cloudstream3.CommonActivity.updateTheme
import com.lagradost.cloudstream3.databinding.ActivityMainBinding
import com.lagradost.cloudstream3.databinding.ActivityMainTvBinding
import com.lagradost.cloudstream3.databinding.BottomResultviewPreviewBinding
@ -484,6 +485,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
updateLocale() // android fucks me by chaining lang when rotating the phone
updateTheme(this) // Update if system theme
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment

View file

@ -88,10 +88,9 @@ class SettingsUI : PreferenceFragmentCompat() {
getPref(R.string.app_theme_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.themes_names).toMutableList()
val prefValues = resources.getStringArray(R.array.themes_names_values).toMutableList()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // remove monet on android 11 and less
val removeFunction = { text: String ->
val toRemove = prefValues
.mapIndexed { idx, s -> if (s.startsWith("Monet")) idx else null }
.mapIndexed { idx, s -> if (s.startsWith(text)) idx else null }
.filterNotNull()
var offset = 0
toRemove.forEach { idx ->
@ -100,6 +99,12 @@ class SettingsUI : PreferenceFragmentCompat() {
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 =
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
@ -123,7 +128,8 @@ class SettingsUI : PreferenceFragmentCompat() {
}
getPref(R.string.primary_color_key)?.setOnPreferenceClickListener {
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
val toRemove = prefValues

View file

@ -243,13 +243,15 @@
<string-array name="themes_names">
<item>Sistema</item>
<item>Oscuro</item>
<item>Gris</item>
<item>Amoled</item>
<item>Destello</item>
<item>Material You</item>
<item>Material You (Android 12+)</item>
</string-array>
<string-array name="themes_names_values">
<item>System</item>
<item>AmoledLight</item>
<item>Black</item>
<item>Amoled</item>

View file

@ -252,13 +252,15 @@
<string-array name="themes_names">
<item>System</item>
<item>Ciemny</item>
<item>Szary</item>
<item>Amoled</item>
<item>Flashbang</item>
<item>Material You</item>
<item>Material You (Android 12+)</item>
</string-array>
<string-array name="themes_names_values">
<item>System</item>
<item>AmoledLight</item>
<item>Black</item>
<item>Amoled</item>

View file

@ -277,13 +277,15 @@
</string-array>
<string-array name="themes_names">
<item>Sistem</item>
<item>Koyu</item>
<item>Gri</item>
<item>Amoled</item>
<item>Flaş Bombası</item>
<item>Material You</item>
<item>Material You (Android 12+)</item>
</string-array>
<string-array name="themes_names_values">
<item>System</item>
<item>AmoledLight</item>
<item>Black</item>
<item>Amoled</item>

View file

@ -244,13 +244,15 @@
<string-array name="themes_names">
<item>Hệ thống</item>
<item>Tối</item>
<item>Xám</item>
<item>Amoled</item>
<item>Sáng</item>
<item>Material You</item>
<item>Material You (Android 12+)</item>
</string-array>
<string-array name="themes_names_values">
<item>System</item>
<item>AmoledLight</item>
<item>Black</item>
<item>Amoled</item>

View file

@ -314,13 +314,15 @@
</string-array>
<string-array name="themes_names">
<item>System</item>
<item>Dark</item>
<item>Gray</item>
<item>Amoled</item>
<item>Flashbang</item>
<item>Material You</item>
<item>Material You (Android 12+)</item>
</string-array>
<string-array name="themes_names_values">
<item>System</item>
<item>AmoledLight</item>
<item>Black</item>
<item>Amoled</item>