Allow overriding theme

This commit is contained in:
jarnedemeulemeester 2021-08-04 12:29:51 +02:00
parent 72fb32fb52
commit fd351f5088
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
7 changed files with 54 additions and 6 deletions

View file

@ -13,12 +13,14 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Jellyfin" android:theme="@style/Theme.Jellyfin"
android:usesCleartextTraffic="true"> android:usesCleartextTraffic="true">
<activity android:name=".PlayerActivity" /> <activity
android:name=".PlayerActivity"
android:screenOrientation="landscape" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.JellyfinSplashScreen" android:theme="@style/Theme.JellyfinSplashScreen"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan">
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View file

@ -1,12 +1,22 @@
package dev.jdtech.jellyfin package dev.jdtech.jellyfin
import android.app.Application import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
import dagger.hilt.android.HiltAndroidApp import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber import timber.log.Timber
@HiltAndroidApp @HiltAndroidApp
class BaseApplication : Application() { class BaseApplication : Application() {
override fun onCreate() { override fun onCreate() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
when (sharedPreferences.getString("theme", null)) {
"system" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
"light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
"dark" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
super.onCreate() super.onCreate()
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree()) Timber.plant(Timber.DebugTree())

View file

@ -22,9 +22,8 @@ class MainActivity : AppCompatActivity() {
private val viewModel: MainViewModel by viewModels() private val viewModel: MainViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen() installSplashScreen()
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
@ -66,7 +65,9 @@ class MainActivity : AppCompatActivity() {
viewModel.doneLoading.observe(this, { viewModel.doneLoading.observe(this, {
if (it) { if (it) {
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome()) if (navController.currentDestination!!.id == R.id.initializingFragment) {
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
}
} }
}) })
} }

View file

@ -1,7 +1,9 @@
package dev.jdtech.jellyfin.fragments package dev.jdtech.jellyfin.fragments
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatDelegate.*
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import dev.jdtech.jellyfin.R import dev.jdtech.jellyfin.R
@ -14,5 +16,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
findNavController().navigate(SettingsFragmentDirections.actionNavigationSettingsToServerSelectFragment2()) findNavController().navigate(SettingsFragmentDirections.actionNavigationSettingsToServerSelectFragment2())
true true
} }
findPreference<ListPreference>("theme")?.setOnPreferenceChangeListener { _, newValue ->
when (newValue) {
"system" -> setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM)
"light" -> setDefaultNightMode(MODE_NIGHT_NO)
"dark" -> setDefaultNightMode(MODE_NIGHT_YES)
}
true
}
} }
} }

View file

@ -47,4 +47,6 @@
<string name="initializing">Initializing…</string> <string name="initializing">Initializing…</string>
<string name="settings_category_servers">Servers</string> <string name="settings_category_servers">Servers</string>
<string name="switch_server">Switch server</string> <string name="switch_server">Switch server</string>
<string name="settings_category_appearance">Appearance</string>
<string name="theme">Theme</string>
</resources> </resources>

View file

@ -22,4 +22,16 @@
<item name="windowSplashScreenBackground">@color/neutral_100</item> <item name="windowSplashScreenBackground">@color/neutral_100</item>
<item name="postSplashScreenTheme">@style/Theme.Jellyfin</item> <item name="postSplashScreenTheme">@style/Theme.Jellyfin</item>
</style> </style>
<string-array name="themes">
<item>Follow system</item>
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="themes_value">
<item>system</item>
<item>light</item>
<item>dark</item>
</string-array>
</resources> </resources>

View file

@ -29,4 +29,14 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/settings_category_appearance">
<ListPreference
app:defaultValue="system"
app:entries="@array/themes"
app:entryValues="@array/themes_value"
app:key="theme"
app:title="@string/theme"
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>