Search in sources :

Example 1 with ThreeStateCheckbox

use of net.osmand.view.ThreeStateCheckbox in project Osmand by osmandapp.

the class ExportSettingsAdapter method getGroupView.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    View group = convertView;
    if (group == null) {
        group = themedInflater.inflate(R.layout.profile_data_list_item_group, parent, false);
        group.findViewById(R.id.item_container).setMinimumHeight(groupViewHeight);
    }
    final ExportSettingsCategory category = itemsTypes.get(groupPosition);
    final SettingsCategoryItems items = itemsMap.get(category);
    String title = app.getString(category.getTitleId());
    TextView titleTv = group.findViewById(R.id.title_tv);
    titleTv.setText(UiUtilities.createCustomFontSpannable(FontCache.getRobotoMedium(app), title, title));
    TextView subTextTv = group.findViewById(R.id.sub_text_tv);
    subTextTv.setText(getCategoryDescr(category, exportMode));
    int selectedTypes = 0;
    for (ExportSettingsType type : items.getTypes()) {
        if (!Algorithms.isEmpty(selectedItemsMap.get(type))) {
            selectedTypes++;
        }
    }
    final ThreeStateCheckbox checkBox = group.findViewById(R.id.check_box);
    if (selectedTypes == 0) {
        checkBox.setState(UNCHECKED);
    } else {
        checkBox.setState(selectedTypes == items.getNotEmptyTypes().size() ? CHECKED : MISC);
    }
    int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes;
    CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
    group.findViewById(R.id.check_box_container).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!Algorithms.isEmpty(items.getNotEmptyTypes())) {
                checkBox.performClick();
                boolean selected = checkBox.getState() == CHECKED;
                if (listener != null) {
                    listener.onCategorySelected(category, selected);
                }
                notifyDataSetChanged();
            } else {
                showNoItemsMessage();
            }
        }
    });
    adjustIndicator(app, groupPosition, isExpanded, group, !nightMode);
    AndroidUiHelper.updateVisibility(group.findViewById(R.id.divider), isExpanded);
    AndroidUiHelper.updateVisibility(group.findViewById(R.id.card_top_divider), true);
    AndroidUiHelper.updateVisibility(group.findViewById(R.id.vertical_divider), false);
    AndroidUiHelper.updateVisibility(group.findViewById(R.id.card_bottom_divider), !isExpanded);
    return group;
}
Also used : ThreeStateCheckbox(net.osmand.view.ThreeStateCheckbox) ExportSettingsCategory(net.osmand.plus.settings.backend.ExportSettingsCategory) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Example 2 with ThreeStateCheckbox

use of net.osmand.view.ThreeStateCheckbox in project Osmand by osmandapp.

the class ExportSettingsAdapter method getChildView.

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    View child = convertView;
    if (child == null) {
        child = themedInflater.inflate(R.layout.profile_data_list_item_group, parent, false);
        child.findViewById(R.id.item_container).setMinimumHeight(childViewHeight);
    }
    final ExportSettingsCategory category = itemsTypes.get(groupPosition);
    final SettingsCategoryItems categoryItems = itemsMap.get(category);
    final ExportSettingsType type = categoryItems.getTypes().get(childPosition);
    final List<?> items = categoryItems.getItemsForType(type);
    List<?> selectedItems = selectedItemsMap.get(type);
    TextView titleTv = child.findViewById(R.id.title_tv);
    titleTv.setText(type.getTitleId());
    TextView subTextTv = child.findViewById(R.id.sub_text_tv);
    subTextTv.setText(getSelectedTypeDescr(type, items));
    ImageView icon = child.findViewById(R.id.explicit_indicator);
    setupIcon(icon, type.getIconRes(), !Algorithms.isEmpty(selectedItems));
    final ThreeStateCheckbox checkBox = child.findViewById(R.id.check_box);
    if (selectedItems == null) {
        checkBox.setState(UNCHECKED);
    } else if (selectedItems.containsAll(items)) {
        checkBox.setState(CHECKED);
    } else {
        boolean contains = false;
        for (Object object : items) {
            if (selectedItems.contains(object)) {
                contains = true;
                break;
            }
        }
        checkBox.setState(contains ? MISC : UNCHECKED);
    }
    child.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!Algorithms.isEmpty(items)) {
                if (listener != null) {
                    listener.onTypeClicked(type);
                }
            } else {
                showNoItemsMessage();
            }
        }
    });
    int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes;
    CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
    child.findViewById(R.id.check_box_container).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!Algorithms.isEmpty(items)) {
                checkBox.performClick();
                boolean selected = checkBox.getState() == CHECKED;
                if (listener != null) {
                    listener.onItemsSelected(type, selected ? items : new ArrayList<>());
                }
                notifyDataSetChanged();
            } else {
                showNoItemsMessage();
            }
        }
    });
    AndroidUiHelper.updateVisibility(child.findViewById(R.id.card_bottom_divider), isLastChild);
    return child;
}
Also used : ExportSettingsCategory(net.osmand.plus.settings.backend.ExportSettingsCategory) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ThreeStateCheckbox(net.osmand.view.ThreeStateCheckbox) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Aggregations

View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ExportSettingsCategory (net.osmand.plus.settings.backend.ExportSettingsCategory)2 ExportSettingsType (net.osmand.plus.settings.backend.ExportSettingsType)2 ThreeStateCheckbox (net.osmand.view.ThreeStateCheckbox)2