Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 155aad00 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Catalyst] Handle binding for unavailable screen" into main

parents 68cb0d5f 155e8567
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -60,14 +60,17 @@ interface PreferenceIconProvider {
    fun getIcon(context: Context): Int
}

/** Interface to provide the state of preference availability. */
interface PreferenceAvailabilityProvider {

    /**
 * Interface to provide the state of preference availability.
     * Returns if the preference is available.
     *
 * UI framework normally does not show the preference widget if it is unavailable.
     * When unavailable (i.e. `false` returned),
     * - UI framework normally does not show the preference widget.
     * - If it is a preference screen, all children may be disabled (depends on UI framework
     *   implementation).
     */
interface PreferenceAvailabilityProvider {

    /** Returns if the preference is available. */
    fun isAvailable(context: Context): Boolean
}

+7 −1
Original line number Diff line number Diff line
@@ -97,9 +97,15 @@ interface PreferenceBinding {
            if (!isPreferenceScreen) {
                preference.summary = getPreferenceSummary(context)
            }
            preference.isEnabled = isEnabled(context)
            preference.isVisible =
                (this as? PreferenceAvailabilityProvider)?.isAvailable(context) != false
            // PreferenceScreen.isVisible=false has no effect on UI, while isEnable=false will
            // apply recursively. As a workaround, disable all children when screen is unavailable.
            preference.isEnabled =
                when {
                    isPreferenceScreen && !preference.isVisible -> false
                    else -> isEnabled(context)
                }
            preference.isPersistent = isPersistent(context)
            // PreferenceScreenBindingHelper will notify dependency change, so we do not need to set
            // dependency here. This simplifies dependency management and avoid the