Allow overriding theme
This commit is contained in:
parent
72fb32fb52
commit
fd351f5088
7 changed files with 54 additions and 6 deletions
|
@ -13,12 +13,14 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Jellyfin"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity android:name=".PlayerActivity" />
|
||||
<activity
|
||||
android:name=".PlayerActivity"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.JellyfinSplashScreen"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:exported="true">
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
package dev.jdtech.jellyfin
|
||||
|
||||
import android.app.Application
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.PreferenceManager
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import timber.log.Timber
|
||||
|
||||
@HiltAndroidApp
|
||||
class BaseApplication : Application() {
|
||||
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()
|
||||
if (BuildConfig.DEBUG) {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
|
|
|
@ -22,9 +22,8 @@ class MainActivity : AppCompatActivity() {
|
|||
private val viewModel: MainViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
installSplashScreen()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
|
||||
|
@ -66,7 +65,9 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
viewModel.doneLoading.observe(this, {
|
||||
if (it) {
|
||||
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
|
||||
if (navController.currentDestination!!.id == R.id.initializingFragment) {
|
||||
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package dev.jdtech.jellyfin.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatDelegate.*
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import dev.jdtech.jellyfin.R
|
||||
|
@ -14,5 +16,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
findNavController().navigate(SettingsFragmentDirections.actionNavigationSettingsToServerSelectFragment2())
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,4 +47,6 @@
|
|||
<string name="initializing">Initializing…</string>
|
||||
<string name="settings_category_servers">Servers</string>
|
||||
<string name="switch_server">Switch server</string>
|
||||
<string name="settings_category_appearance">Appearance</string>
|
||||
<string name="theme">Theme</string>
|
||||
</resources>
|
|
@ -22,4 +22,16 @@
|
|||
<item name="windowSplashScreenBackground">@color/neutral_100</item>
|
||||
<item name="postSplashScreenTheme">@style/Theme.Jellyfin</item>
|
||||
</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>
|
|
@ -29,4 +29,14 @@
|
|||
|
||||
</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>
|
Loading…
Reference in a new issue