mflisar / materialpreferences Goto Github PK
View Code? Open in Web Editor NEWPreference via delegates (Flow, Coroutines) + JetPack DataStore Storage + DSL for RecyclerView based preference screens
License: Apache License 2.0
Preference via delegates (Flow, Coroutines) + JetPack DataStore Storage + DSL for RecyclerView based preference screens
License: Apache License 2.0
when the switch is disabled by default or dependency it seems that the switch is not drawn.
see this image: https://ibb.co/KjtWzV7
opened settings screen and boom runtime crash at my face
java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
at android.text.StaticLayout.<init>(StaticLayout.java:455)
at androidx.appcompat.widget.SwitchCompat.makeLayout(SwitchCompat.java:995)
at androidx.appcompat.widget.SwitchCompat.onMeasure(SwitchCompat.java:916)
at android.view.View.measure(View.java:25833)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1204)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:723)
at android.view.View.measure(View.java:25833)
.......
log of catched exception
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f040107 a=-1}
at android.content.res.TypedArray.getColor(TypedArray.java:529)
at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:262)
at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:236)
at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:558)
at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
at androidx.appcompat.widget.TintTypedArray.getColorStateList(TintTypedArray.java:179)
at com.google.android.material.materialswitch.MaterialSwitch.<init>(MaterialSwitch.java:101)
at com.google.android.material.materialswitch.MaterialSwitch.<init>(MaterialSwitch.java:72)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at com.michaelflisar.materialpreferences.preferencescreen.bool.databinding.WidgetSwitchBinding.inflate(WidgetSwitchBinding.java:42)
at com.michaelflisar.materialpreferences.preferencescreen.bool.switches.SwitchViewHolder.createSubBinding(SwitchViewHolder.kt:23)
at com.michaelflisar.materialpreferences.preferencescreen.bool.switches.SwitchViewHolder.createSubBinding(SwitchViewHolder.kt:12)
at com.michaelflisar.materialpreferences.preferencescreen.recyclerview.viewholders.base.BaseViewHolderWithWidget$subBinding$2.invoke(BaseViewHolderWithWidget.kt:31)
at com.michaelflisar.materialpreferences.preferencescreen.recyclerview.viewholders.base.BaseViewHolderWithWidget$subBinding$2.invoke(BaseViewHolderWithWidget.kt:31)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.michaelflisar.materialpreferences.preferencescreen.recyclerview.viewholders.base.BaseViewHolderWithWidget.getSubBinding(BaseViewHolderWithWidget.kt:31)
at com.michaelflisar.materialpreferences.preferencescreen.bool.switches.SwitchViewHolder.bindWidget(SwitchViewHolder.kt:26)
at com.michaelflisar.materialpreferences.preferencescreen.bool.switches.SwitchViewHolder.bindWidget(SwitchViewHolder.kt:12)
at com.michaelflisar.materialpreferences.preferencescreen.recyclerview.viewholders.base.BaseViewHolderWithWidget.rebind(BaseViewHolderWithWidget.kt:92)
at com.michaelflisar.materialpreferences.preferencescreen.recyclerview.viewholders.base.BaseViewHolderWithWidget$bind$1$1.invokeSuspend(BaseViewHolderWithWidget.kt:70)
I am following the example with the built-in settings activity to build a quick prototype, but I am surely missing something pretty basic.
Here I get these errors on Android Studio, Unresolved reference: IScreenCreator and No 'Parcelable' supertype for ScreenCreator itself.
object UserSettingsModel : SettingsModel(DataStoreStorage(name = "user")) {
// main data types
val baseVideoUri by stringPref("rtsp://10.0.0.10:8554")
}
@Parcelize
object ScreenCreator : SettingsActivity.IScreenCreator {
override fun createScreen(
activity: AppCompatActivity,
savedInstanceState: Bundle?,
updateTitle: (title: String) -> Unit
): PreferenceScreen {
return screen {
state = savedInstanceState
input(UserSettingsModel.baseVideoUri) {
title = "Video URL".asText()
}
}
}
}
class MainActivity : AppCompatActivity() {
(rest of the activity)
I think I am just using it wrong, I've been looking at the example app but I didn't find anything.
In any case, thanks a lot for the library, it seems to save a lot of time when dealing with prefs. The automagic settings activity would just be the icing on the cake.
I investigated it and found the source of the problem, fixed it myself until I found this good-looking comment, uncomment it and bug was fixed.
updateCurrentFilteredItems(true)
that updated the adapter list, also I found out that the object is leaking when in fragment, so I hope you investigate and fix it.
Keep up the good work!
when switching between fragment no leak as before but got 3 leaks if I switched app theme in the settings fragment
as the parent activity is recreated and the pervious instance is not cleared as settingsview is holding a reference to its context.
and i really suggest that you setup a settings fragment in the test app so you catch errors and leaks that will only show in fragment as
it has some differences than activity.
SharedPreferences data is not safe from apk extraction/reverse engineering. Would be great if this had encrypted data.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.