Added app theme toggle

This commit is contained in:
archroid 2022-03-17 23:18:43 +03:30
parent c0d3522bb8
commit b52bb3c6e9
4 changed files with 44 additions and 2 deletions

View File

@ -13,12 +13,14 @@ import android.util.Log
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.blankj.utilcode.util.UriUtils
import com.github.libretube.obj.Subscribe
import retrofit2.HttpException
@ -100,7 +102,6 @@ class Settings : PreferenceFragmentCompat() {
importFromYt?.setOnPreferenceClickListener {
//check StorageAccess
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Log.d("myz", "" + Build.VERSION.SDK_INT)
if (!Environment.isExternalStorageManager()) {
@ -137,6 +138,16 @@ class Settings : PreferenceFragmentCompat() {
true
}
val themeToggle = findPreference<ListPreference>("theme_togglee")
themeToggle?.setOnPreferenceChangeListener { _, newValue ->
when (newValue.toString()) {
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
true
}
}
private fun fetchInstance() {

View File

@ -404,4 +404,17 @@
<item>ZM</item>
<item>ZW</item>
</string-array>
<string-array name="themes">
<item>System Default</item>
<item>Light Theme</item>
<item>Dark Theme</item>
</string-array>
<string-array name="themesValue">
<item>A</item>
<item>L</item>
<item>D</item>
</string-array>
</resources>

View File

@ -30,6 +30,6 @@
<string name="vlc">Open in VLC</string>
<string name="vlcerror">Can\'t open in VLC. Maybe it\'s not installed yet?</string>
<string name="import_from_yt">Import subscriptions from youtube</string>
<string name="dark_theme">Dark theme</string>
<string name="app_theme">App theme</string>
</resources>

View File

@ -37,4 +37,22 @@
/>
<!-- <ListPreference-->
<!-- app:key="theme_toggleee"-->
<!-- app:title="@string/region"-->
<!-- app:entries="@array/regions"-->
<!-- app:entryValues="@array/regionsValue"-->
<!-- app:defaultValue="US"-->
<!-- app:useSimpleSummaryProvider="true"-->
<!-- />-->
<ListPreference
app:title="@string/app_theme"
app:key="theme_togglee"
app:entries="@array/themes"
app:entryValues="@array/themesValue"
app:defaultValue="A"
/>
</androidx.preference.PreferenceScreen>