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: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" />
|
||||||
|
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -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,8 +65,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
viewModel.doneLoading.observe(this, {
|
viewModel.doneLoading.observe(this, {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
if (navController.currentDestination!!.id == R.id.initializingFragment) {
|
||||||
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
|
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in a new issue