update preferences dependency

This commit is contained in:
Phillip Thelen 2021-06-08 08:59:17 +02:00
parent a381458a28
commit eb2333667b
9 changed files with 33 additions and 40 deletions

View file

@ -61,6 +61,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0' implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation "androidx.preference:preference-ktx:1.1.1"
// Markdown // Markdown
implementation "io.noties.markwon:core:4.6.2" implementation "io.noties.markwon:core:4.6.2"
implementation "io.noties.markwon:ext-strikethrough:4.6.2" implementation "io.noties.markwon:ext-strikethrough:4.6.2"
@ -143,7 +146,7 @@ android {
buildConfigField "String", "TESTING_LEVEL", "\"production\"" buildConfigField "String", "TESTING_LEVEL", "\"production\""
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW" resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
versionCode 2962 versionCode 2964
versionName "3.3" versionName "3.3"
} }

View file

@ -41,7 +41,6 @@
<item name="popupMenuStyle">@style/PopupTheme</item> <item name="popupMenuStyle">@style/PopupTheme</item>
<item name="actionOverflowMenuStyle">@style/PopupTheme</item> <item name="actionOverflowMenuStyle">@style/PopupTheme</item>
<item name="android:popupMenuStyle">@style/PopupTheme</item> <item name="android:popupMenuStyle">@style/PopupTheme</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="android:textColorLink">@color/brand_400</item> <item name="android:textColorLink">@color/brand_400</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item> <item name="alertDialogTheme">@style/AlertDialogTheme</item>
<item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentStatus">false</item>
@ -815,10 +814,6 @@
<item name="searchHintIcon">@null</item> <item name="searchHintIcon">@null</item>
</style> </style>
<style name="PreferenceThemeOverlay.v14" tools:override="true">
<item name="android:background">@color/content_background</item>
</style>
<style name="FlatCardView"> <style name="FlatCardView">
<item name="android:background">@drawable/layout_rounded_bg_window</item> <item name="android:background">@drawable/layout_rounded_bg_window</item>
<item name="android:layout_margin">@dimen/spacing_medium</item> <item name="android:layout_margin">@dimen/spacing_medium</item>

View file

@ -36,8 +36,6 @@ object GSonFactoryCreator {
val ownedMountListType = object : TypeToken<RealmList<OwnedMount?>?>() {}.type val ownedMountListType = object : TypeToken<RealmList<OwnedMount?>?>() {}.type
val achievementsListType = object : TypeToken<List<Achievement?>?>() {}.type val achievementsListType = object : TypeToken<List<Achievement?>?>() {}.type
//Exclusion strategy needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
val gson = GsonBuilder() val gson = GsonBuilder()
.registerTypeAdapter(taskTagClassListType, TaskTagDeserializer()) .registerTypeAdapter(taskTagClassListType, TaskTagDeserializer())
.registerTypeAdapter(Boolean::class.java, BooleanAsIntAdapter()) .registerTypeAdapter(Boolean::class.java, BooleanAsIntAdapter())

View file

@ -38,7 +38,7 @@ class APIPreferenceFragment: BasePreferencesFragment() {
override fun setupPreferences() { override fun setupPreferences() {
for ((key, value) in preferenceScreen.sharedPreferences.all) { for ((key, value) in preferenceScreen.sharedPreferences.all) {
if (apiPreferences.contains(key) && value != null) { if (apiPreferences.contains(key) && value != null) {
findPreference(key).summary = value.toString() findPreference<Preference>(key)?.summary = value.toString()
} }
} }
} }

View file

@ -9,6 +9,7 @@ import android.widget.EditText
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Toast import android.widget.Toast
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.habitrpg.android.habitica.HabiticaBaseApplication import com.habitrpg.android.habitica.HabiticaBaseApplication
@ -46,17 +47,17 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
HabiticaBaseApplication.userComponent?.inject(this) HabiticaBaseApplication.userComponent?.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
findPreference("login_name").title = context?.getString(R.string.username) findPreference<Preference>("login_name")?.title = context?.getString(R.string.username)
findPreference("confirm_username").isVisible = user?.flags?.verifiedUsername != true findPreference<Preference>("confirm_username")?.isVisible = user?.flags?.verifiedUsername != true
} }
private fun updateUserFields() { private fun updateUserFields() {
configurePreference(findPreference("login_name"), user?.authentication?.localAuthentication?.username, false) configurePreference(findPreference("login_name"), user?.authentication?.localAuthentication?.username, false)
configurePreference(findPreference("email"), user?.authentication?.localAuthentication?.email, true) configurePreference(findPreference("email"), user?.authentication?.localAuthentication?.email, true)
findPreference("change_password").isVisible = user?.authentication?.localAuthentication?.email?.isNotEmpty() == true findPreference<Preference>("change_password")?.isVisible = user?.authentication?.localAuthentication?.email?.isNotEmpty() == true
findPreference("add_local_auth").isVisible = user?.authentication?.localAuthentication?.email?.isNotEmpty() != true findPreference<Preference>("add_local_auth")?.isVisible = user?.authentication?.localAuthentication?.email?.isNotEmpty() != true
findPreference("confirm_username").isVisible = user?.flags?.verifiedUsername != true findPreference<Preference>("confirm_username")?.isVisible = user?.flags?.verifiedUsername != true
val preference = findPreference("authentication_methods") val preference = findPreference<Preference>("authentication_methods")
val methods = mutableListOf<String>() val methods = mutableListOf<String>()
if (user?.authentication?.localAuthentication?.email != null) { if (user?.authentication?.localAuthentication?.email != null) {
context?.getString(R.string.local)?.let { methods.add(it) } context?.getString(R.string.local)?.let { methods.add(it) }
@ -64,7 +65,7 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
if (user?.authentication?.hasFacebookAuth == true) { context?.getString(R.string.facebook)?.let { methods.add(it) } } if (user?.authentication?.hasFacebookAuth == true) { context?.getString(R.string.facebook)?.let { methods.add(it) } }
if (user?.authentication?.hasGoogleAuth == true) { context?.getString(R.string.google)?.let { methods.add(it) } } if (user?.authentication?.hasGoogleAuth == true) { context?.getString(R.string.google)?.let { methods.add(it) } }
if (user?.authentication?.hasAppleAuth == true) { context?.getString(R.string.apple_sign_in)?.let { methods.add(it) } } if (user?.authentication?.hasAppleAuth == true) { context?.getString(R.string.apple_sign_in)?.let { methods.add(it) } }
preference.summary = methods.joinToString(", ") preference?.summary = methods.joinToString(", ")
} }
private fun configurePreference(preference: Preference?, value: String?, hideIfEmpty: Boolean) { private fun configurePreference(preference: Preference?, value: String?, hideIfEmpty: Boolean) {

View file

@ -24,11 +24,7 @@ abstract class BasePreferencesFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
compositeSubscription.add(userRepository.getUser().subscribe({ this.setUser(it) }, RxErrorHandler.handleEmptyError()))
val userID = preferenceManager.sharedPreferences.getString(context?.getString(R.string.SP_userID), null)
if (userID != null) {
compositeSubscription.add(userRepository.getUser(userID).subscribe({ this.setUser(it) }, RxErrorHandler.handleEmptyError()))
}
} }
override fun onDestroy() { override fun onDestroy() {

View file

@ -236,15 +236,15 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
.subscribe({ }, RxErrorHandler.handleEmptyError()) .subscribe({ }, RxErrorHandler.handleEmptyError())
"server_url" -> { "server_url" -> {
apiClient.updateServerUrl(sharedPreferences.getString(key, "")) apiClient.updateServerUrl(sharedPreferences.getString(key, ""))
findPreference(key).summary = sharedPreferences.getString(key, "") findPreference<Preference>(key)?.summary = sharedPreferences.getString(key, "")
} }
"task_display" -> { "task_display" -> {
val preference = findPreference(key) as ListPreference val preference = findPreference<ListPreference>(key)
preference.summary = preference.entry preference?.summary = preference?.entry
} }
"FirstDayOfTheWeek" -> { "FirstDayOfTheWeek" -> {
val preference = findPreference(key) as ListPreference val preference = findPreference<ListPreference>(key)
preference.summary = preference.entry preference?.summary = preference?.entry
} }
"disablePMs" -> { "disablePMs" -> {
val isDisabled = sharedPreferences.getBoolean("disablePMs", false) val isDisabled = sharedPreferences.getBoolean("disablePMs", false)
@ -254,8 +254,8 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
} }
} }
"launch_screen" -> { "launch_screen" -> {
val preference = findPreference(key) as ListPreference val preference = findPreference<ListPreference>(key)
preference.summary = preference.entry ?: "Habits" preference?.summary = preference?.entry ?: "Habits"
} }
} }
} }
@ -297,7 +297,7 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
} }
val cdsTimePreference = findPreference("cds_time") as? TimePreference val cdsTimePreference = findPreference("cds_time") as? TimePreference
cdsTimePreference?.text = user?.preferences?.dayStart.toString() + ":00" cdsTimePreference?.text = user?.preferences?.dayStart.toString() + ":00"
findPreference("dailyDueDefaultView").setDefaultValue(user?.preferences?.dailyDueDefaultView) findPreference<Preference>("dailyDueDefaultView")?.setDefaultValue(user?.preferences?.dailyDueDefaultView)
val languagePreference = findPreference("language") as? ListPreference val languagePreference = findPreference("language") as? ListPreference
languagePreference?.value = user?.preferences?.language languagePreference?.value = user?.preferences?.language
languagePreference?.summary = languagePreference?.entry languagePreference?.summary = languagePreference?.entry
@ -305,19 +305,19 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
audioThemePreference?.value = user?.preferences?.sound audioThemePreference?.value = user?.preferences?.sound
audioThemePreference?.summary = audioThemePreference?.entry audioThemePreference?.summary = audioThemePreference?.entry
val preference = findPreference("authentication") val preference = findPreference<Preference>("authentication")
if (user?.flags?.verifiedUsername == true) { if (user?.flags?.verifiedUsername == true) {
preference.layoutResource = R.layout.preference_child_summary preference?.layoutResource = R.layout.preference_child_summary
preference.summary = context?.getString(R.string.authentication_summary) preference?.summary = context?.getString(R.string.authentication_summary)
} else { } else {
preference.layoutResource = R.layout.preference_child_summary_error preference?.layoutResource = R.layout.preference_child_summary_error
preference.summary = context?.getString(R.string.username_not_confirmed) preference?.summary = context?.getString(R.string.username_not_confirmed)
} }
if (user?.party?.id?.isNotBlank() != true) { if (user?.party?.id?.isNotBlank() != true) {
val launchScreenPreference = findPreference("launch_screen") as ListPreference val launchScreenPreference = findPreference<ListPreference>("launch_screen")
launchScreenPreference.entries = resources.getStringArray(R.array.launch_screen_types).dropLast(1).toTypedArray() launchScreenPreference?.entries = resources.getStringArray(R.array.launch_screen_types).dropLast(1).toTypedArray()
launchScreenPreference.entryValues = resources.getStringArray(R.array.launch_screen_values).dropLast(1).toTypedArray() launchScreenPreference?.entryValues = resources.getStringArray(R.array.launch_screen_values).dropLast(1).toTypedArray()
} }
val disablePMsPreference = findPreference("disablePMs") as? CheckBoxPreference val disablePMsPreference = findPreference("disablePMs") as? CheckBoxPreference

View file

@ -50,7 +50,7 @@ class ProfilePreferencesFragment: BasePreferencesFragment(), SharedPreferences.O
updateUserFields() updateUserFields()
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String) {
val profileCategory = findPreference("profile") as? PreferenceCategory val profileCategory = findPreference("profile") as? PreferenceCategory
configurePreference(profileCategory?.findPreference(key), sharedPreferences?.getString(key, "")) configurePreference(profileCategory?.findPreference(key), sharedPreferences?.getString(key, ""))
if (sharedPreferences != null) { if (sharedPreferences != null) {

View file

@ -7,9 +7,9 @@ import com.habitrpg.android.habitica.extensions.getAsString
import com.habitrpg.android.habitica.models.Achievement import com.habitrpg.android.habitica.models.Achievement
import java.lang.reflect.Type import java.lang.reflect.Type
class AchievementListDeserializer: JsonDeserializer<List<Achievement>> { class AchievementListDeserializer: JsonDeserializer<List<Achievement?>> {
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): List<Achievement> { override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): List<Achievement?> {
val achievements = mutableListOf<Achievement>() val achievements = mutableListOf<Achievement>()
for (categoryEntry in json?.asJsonObject?.entrySet() ?: emptySet()) { for (categoryEntry in json?.asJsonObject?.entrySet() ?: emptySet()) {
val categoryIdentifier = categoryEntry.key val categoryIdentifier = categoryEntry.key