yarolegovich / MaterialPreferences

A highly flexible set of lovely looking views that provides functionality of preferences.
Apache License 2.0
485 stars 67 forks source link

CompositeClickListener doesn't function as expected #13

Open PeterAttardo opened 6 years ago

PeterAttardo commented 6 years ago

CompositeClickListener maintains a list of View.OnClickListeners and when it receives a click event it iterates through the list backward, delegating the click to each in turn. The problem with this approach is that in the case of AbsMaterialCheckablePreference the preference sets itself as a listener in its onViewCreated method, which is the listener responsible for switching the value. Because this is the first listener in the CompositeClickListener's list, it is the last to be executed, so all other click listeners will be executed using the old value of the preference should they call getValue().

This is particularly notable with MaterialPreferenceScreen#setVisibilityController as it sets a click listener on the controller MaterialPreference which is consistently invoked with the wrong boolean value. The sample app demonstrates this behavior (despite what appears to be an attempt to correct for it by setting showWhenChecked to false when it really wants to be true). When you enter the AppConfigActivity, the visibility of Location will be the opposite of what Automatic Location would indicate (because at this point it has the correct value and is respecting showWhenChecked = false. When you switch the value for the first time, the visibility will not change (as it is still using the old value).

Possible solutions include:

anggrayudi commented 6 years ago

It is been 3 months, and no fixes yet?