package cgeo.geocaching.settings;

import cgeo.geocaching.R;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import org.apache.commons.lang3.StringUtils;

/**
 * Preference for displaying the supported capabilities of an {@link IConnector} implementation.
 */
public class CapabilitiesPreference extends AbstractAttributeBasedPreference {

    private String connectorCode;

    public CapabilitiesPreference(final Context context) {
        super(context);
    }

    public CapabilitiesPreference(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    public CapabilitiesPreference(final Context context, final AttributeSet attrs, final int defStyle) {
        super(context, attrs, defStyle);
    }

    private String createCapabilitiesMessage() {
        // TODO: this needs a better key for the connectors
        final IConnector connector = ConnectorFactory.getConnector(connectorCode + "1234");

        return StringUtils.join(connector.getCapabilities(), "\n");
    }

    @Override
    protected void processAttributeValues(final TypedArray values) {
        connectorCode = values.getString(0);
        setSummary(StringUtils.EMPTY);
    }

    @Override
    protected int[] getAttributeNames() {
        return new int[]{R.attr.connector};
    }

    @Override
    public void setSummary(final CharSequence summary) {
        super.setSummary(createCapabilitiesMessage());
    }
}

@@ -255,16 +255,98 @@
 buteSet;
+%0Aimport android.widget.TextView;%0A%0Aimport androidx.preference.PreferenceViewHolder;
 %0A%0Aimport
@@ -1660,11 +1660,422 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void onBindViewHolder(final PreferenceViewHolder holder) %7B%0A        super.onBindViewHolder(holder);%0A%0A        // there is a UI bug in the material preference implementation, see #12338%0A        final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);%0A        if (summaryView != null) %7B%0A            summaryView.setVerticalScrollBarEnabled(false);%0A        %7D%0A    %7D
 %0A%7D%0A

disable vertical scroll bar (fix #12338) (#13162)