Theme color reset

This commit is contained in:
Hardcore Sushi 2020-08-07 22:40:13 +02:00
parent d3bcd29806
commit 62e04027d2
8 changed files with 68 additions and 16 deletions

View File

@ -18,15 +18,19 @@ open class BaseActivity: CyaneaAppCompatActivity() {
} }
val themeColor = ThemeColor.getThemeColor(this) val themeColor = ThemeColor.getThemeColor(this)
if (cyanea.accent != themeColor){ if (cyanea.accent != themeColor){
val backgroundColor = ContextCompat.getColor(this, R.color.backgroundColor) changeThemeColor(themeColor)
cyanea.edit{
accent(themeColor)
//accentDark(themeColor)
//accentLight(themeColor)
background(backgroundColor)
//backgroundDark(backgroundColor)
//backgroundLight(backgroundColor)
}
} }
} }
fun changeThemeColor(themeColor: Int? = null){
val accentColor = themeColor ?: ThemeColor.getThemeColor(this)
val backgroundColor = ContextCompat.getColor(this, R.color.backgroundColor)
cyanea.edit{
accent(accentColor)
//accentDark(themeColor)
//accentLight(themeColor)
background(backgroundColor)
//backgroundDark(backgroundColor)
//backgroundLight(backgroundColor)
}.recreate(this)
}
} }

View File

@ -1,10 +1,14 @@
package sushi.hardcore.droidfs package sushi.hardcore.droidfs
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.jaredrummler.android.colorpicker.ColorPreferenceCompat
import kotlinx.android.synthetic.main.toolbar.* import kotlinx.android.synthetic.main.toolbar.*
import sushi.hardcore.droidfs.widgets.SimpleActionPreference
import sushi.hardcore.droidfs.widgets.ThemeColor import sushi.hardcore.droidfs.widgets.ThemeColor
@ -32,6 +36,26 @@ class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceSt
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey) setPreferencesFromResource(R.xml.root_preferences, rootKey)
ThemeColor.tintPreferenceIcons(preferenceScreen, ThemeColor.getThemeColor(requireContext())) ThemeColor.tintPreferenceIcons(preferenceScreen, ThemeColor.getThemeColor(requireContext()))
var originalThemeColor: Int? = null
context?.let {
originalThemeColor = ContextCompat.getColor(it, R.color.themeColor)
}
findPreference<ColorPreferenceCompat>("themeColor")?.let { colorPicker ->
colorPicker.onPreferenceChangeListener = Preference.OnPreferenceChangeListener{ _, _ ->
(activity as SettingsActivity).changeThemeColor()
true
}
findPreference<SimpleActionPreference>("resetThemeColor")?.onClick = {
originalThemeColor?.let {
colorPicker.saveValue(it)
val settingsActivity = (activity as SettingsActivity)
Thread {
settingsActivity.sharedPrefs.edit().commit()
settingsActivity.runOnUiThread { settingsActivity.changeThemeColor() }
}.start()
}
}
}
} }
} }

View File

@ -0,0 +1,16 @@
package sushi.hardcore.droidfs.widgets
import android.content.Context
import android.util.AttributeSet
import androidx.preference.Preference
class SimpleActionPreference: Preference {
constructor(context: Context): super(context)
constructor(context: Context, attrs: AttributeSet): super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int): super(context, attrs, defStyleAttr)
var onClick: ((SimpleActionPreference) -> Unit)? = null
override fun onClick() {
onClick?.let { it(this) }
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z"/>
</vector>

View File

@ -6,7 +6,6 @@
<color name="cyanea_primary_reference">@color/colorPrimaryDark</color> <color name="cyanea_primary_reference">@color/colorPrimaryDark</color>
<color name="cyanea_primary_dark_reference">@color/colorPrimaryDark</color> <color name="cyanea_primary_dark_reference">@color/colorPrimaryDark</color>
<color name="themeColor">@color/colorAccent</color> <color name="themeColor">@color/colorAccent</color>
<color name="cyanea_accent">@color/themeColor</color>
<color name="backgroundColor">#333333</color> <color name="backgroundColor">#333333</color>
<color name="fullScreenBackgroundColor">#000000</color> <color name="fullScreenBackgroundColor">#000000</color>
<color name="textColor">#FFFFFF</color> <color name="textColor">#FFFFFF</color>

View File

@ -103,6 +103,7 @@
<string name="manage_unsafe_features_summary">Enable/Disable unsafe features</string> <string name="manage_unsafe_features_summary">Enable/Disable unsafe features</string>
<string name="ui">UI</string> <string name="ui">UI</string>
<string name="preference_theme_color_title">Theme color</string> <string name="preference_theme_color_title">Theme color</string>
<string name="preference_theme_color_summary">Set a custom theme color</string>
<string name="usf_home_warning_msg">DroidFS try to be as secure as possible. However, security often involves lack of comfort. This is why DroidFS offer you additional unsafe features that you can enable/disable according to your needs.\n\nWarning: this features can be UNSAFE. Do not use them unless you know exactly what you are doing. It is highly recommended to read the documentation before enabling them.</string> <string name="usf_home_warning_msg">DroidFS try to be as secure as possible. However, security often involves lack of comfort. This is why DroidFS offer you additional unsafe features that you can enable/disable according to your needs.\n\nWarning: this features can be UNSAFE. Do not use them unless you know exactly what you are doing. It is highly recommended to read the documentation before enabling them.</string>
<string name="see_unsafe_features">See unsafe features</string> <string name="see_unsafe_features">See unsafe features</string>
<string name="open_as">Open as:</string> <string name="open_as">Open as:</string>
@ -146,4 +147,6 @@
<string name="default_total_size">N//A</string> <string name="default_total_size">N//A</string>
<string name="file_overwrite_question">%s already exists, do you want to overwrite it ?</string> <string name="file_overwrite_question">%s already exists, do you want to overwrite it ?</string>
<string name="enter_new_filename">Enter new filename</string> <string name="enter_new_filename">Enter new filename</string>
<string name="reset_theme_color">Reset theme color</string>
<string name="reset_theme_color_summary">Reset theme color to the default one</string>
</resources> </resources>

View File

@ -1,10 +1,7 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.Cyanea.Dark.NoActionBar"> <style name="AppTheme" parent="Theme.Cyanea.Dark.NoActionBar">
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorBackground">@color/backgroundColor</item>
<item name="android:textColor">@color/textColor</item> <item name="android:textColor">@color/textColor</item>
<!--<item name="checkboxStyle">@style/checkbox</item>-->
<!--<item name="actionOverflowMenuStyle">@style/menu_overflow</item>--> <!--<item name="actionOverflowMenuStyle">@style/menu_overflow</item>-->
</style> </style>
<style name="button" parent="Widget.AppCompat.Button"> <style name="button" parent="Widget.AppCompat.Button">
@ -14,9 +11,6 @@
<item name="android:divider">#000000</item> <item name="android:divider">#000000</item>
<item name="android:dividerHeight">0dp</item> <item name="android:dividerHeight">0dp</item>
</style> </style>
<style name="checkbox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:textColor">@color/textColor</item>
</style>
<!--<style name="menu_overflow" parent="Widget.AppCompat.PopupMenu.Overflow"> <!--<style name="menu_overflow" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">@drawable/popupmenu_overflow</item> <item name="android:popupBackground">@drawable/popupmenu_overflow</item>
</style>--> </style>-->

View File

@ -7,8 +7,15 @@
android:defaultValue="@color/themeColor" android:defaultValue="@color/themeColor"
android:key="themeColor" android:key="themeColor"
android:title="@string/preference_theme_color_title" android:title="@string/preference_theme_color_title"
android:summary="@string/preference_theme_color_summary"
android:icon="@drawable/icon_palette"/> android:icon="@drawable/icon_palette"/>
<sushi.hardcore.droidfs.widgets.SimpleActionPreference
android:title="@string/reset_theme_color"
android:summary="@string/reset_theme_color_summary"
android:key="resetThemeColor"
android:icon="@drawable/icon_restore"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/explorer"> <PreferenceCategory android:title="@string/explorer">