Search in sources :

Example 1 with ExportSettingsCategory

use of net.osmand.plus.settings.backend.ExportSettingsCategory in project Osmand by osmandapp.

the class SettingsHelper method getSettingsByCategory.

public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean addEmptyItems) {
    Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
    Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(null, addEmptyItems);
    Map<ExportSettingsType, List<?>> myPlacesItems = getMyPlacesItems(null, addEmptyItems);
    Map<ExportSettingsType, List<?>> resourcesItems = getResourcesItems(null, addEmptyItems);
    if (!settingsItems.isEmpty() || addEmptyItems) {
        dataList.put(ExportSettingsCategory.SETTINGS, new SettingsCategoryItems(settingsItems));
    }
    if (!myPlacesItems.isEmpty() || addEmptyItems) {
        dataList.put(ExportSettingsCategory.MY_PLACES, new SettingsCategoryItems(myPlacesItems));
    }
    if (!resourcesItems.isEmpty() || addEmptyItems) {
        dataList.put(ExportSettingsCategory.RESOURCES, new SettingsCategoryItems(resourcesItems));
    }
    return dataList;
}
Also used : SettingsCategoryItems(net.osmand.plus.settings.fragments.SettingsCategoryItems) ExportSettingsCategory(net.osmand.plus.settings.backend.ExportSettingsCategory) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Example 2 with ExportSettingsCategory

use of net.osmand.plus.settings.backend.ExportSettingsCategory 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 3 with ExportSettingsCategory

use of net.osmand.plus.settings.backend.ExportSettingsCategory 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)

Example 4 with ExportSettingsCategory

use of net.osmand.plus.settings.backend.ExportSettingsCategory in project Osmand by osmandapp.

the class SettingsHelper method getSettingsToOperateByCategory.

public static Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsToOperateByCategory(Map<ExportSettingsType, List<?>> settingsToOperate, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> settingsItems = new LinkedHashMap<>();
    Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
    Map<ExportSettingsType, List<?>> resourcesItems = new LinkedHashMap<>();
    for (Map.Entry<ExportSettingsType, List<?>> entry : settingsToOperate.entrySet()) {
        ExportSettingsType type = entry.getKey();
        if (type.isSettingsCategory()) {
            settingsItems.put(type, entry.getValue());
        } else if (type.isMyPlacesCategory()) {
            myPlacesItems.put(type, entry.getValue());
        } else if (type.isResourcesCategory()) {
            resourcesItems.put(type, entry.getValue());
        }
    }
    Map<ExportSettingsCategory, SettingsCategoryItems> exportMap = new LinkedHashMap<>();
    if (!settingsItems.isEmpty() || addEmptyItems) {
        exportMap.put(ExportSettingsCategory.SETTINGS, new SettingsCategoryItems(settingsItems));
    }
    if (!myPlacesItems.isEmpty() || addEmptyItems) {
        exportMap.put(ExportSettingsCategory.MY_PLACES, new SettingsCategoryItems(myPlacesItems));
    }
    if (!resourcesItems.isEmpty() || addEmptyItems) {
        exportMap.put(ExportSettingsCategory.RESOURCES, new SettingsCategoryItems(resourcesItems));
    }
    return exportMap;
}
Also used : SettingsCategoryItems(net.osmand.plus.settings.fragments.SettingsCategoryItems) List(java.util.List) ArrayList(java.util.ArrayList) ExportSettingsCategory(net.osmand.plus.settings.backend.ExportSettingsCategory) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with ExportSettingsCategory

use of net.osmand.plus.settings.backend.ExportSettingsCategory in project Osmand by osmandapp.

the class BackupTypesAdapter method getGroupView.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        view = themedInflater.inflate(R.layout.backup_type_item, parent, false);
    }
    ExportSettingsCategory category = itemsTypes.get(groupPosition);
    SettingsCategoryItems items = itemsMap.get(category);
    String name = app.getString(category.getTitleId());
    Typeface typeface = FontCache.getRobotoMedium(app);
    TextView titleTv = view.findViewById(R.id.title);
    titleTv.setText(UiUtilities.createCustomFontSpannable(typeface, name, name));
    TextView description = view.findViewById(R.id.description);
    description.setText(getCategoryDescr(category));
    int selectedTypes = 0;
    for (ExportSettingsType type : items.getTypes()) {
        if (selectedItemsMap.get(type) != null) {
            selectedTypes++;
        }
    }
    CompoundButton compoundButton = view.findViewById(R.id.switch_widget);
    compoundButton.setChecked(selectedTypes == items.getTypes().size());
    UiUtilities.setupCompoundButton(compoundButton, nightMode, CompoundButtonType.GLOBAL);
    view.findViewById(R.id.switch_container).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            compoundButton.performClick();
            if (listener != null) {
                listener.onCategorySelected(category, compoundButton.isChecked());
            }
            notifyDataSetChanged();
        }
    });
    setupSelectableBackground(view);
    adjustIndicator(app, groupPosition, isExpanded, view, !nightMode);
    AndroidUiHelper.updateVisibility(view.findViewById(R.id.divider), isExpanded);
    AndroidUiHelper.updateVisibility(view.findViewById(R.id.card_top_divider), true);
    AndroidUiHelper.updateVisibility(view.findViewById(R.id.card_bottom_divider), !isExpanded);
    return view;
}
Also used : SettingsCategoryItems(net.osmand.plus.settings.fragments.SettingsCategoryItems) Typeface(android.graphics.Typeface) ExportSettingsCategory(net.osmand.plus.settings.backend.ExportSettingsCategory) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Aggregations

ExportSettingsCategory (net.osmand.plus.settings.backend.ExportSettingsCategory)6 ExportSettingsType (net.osmand.plus.settings.backend.ExportSettingsType)6 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 SettingsCategoryItems (net.osmand.plus.settings.fragments.SettingsCategoryItems)4 CompoundButton (android.widget.CompoundButton)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ThreeStateCheckbox (net.osmand.view.ThreeStateCheckbox)2 Typeface (android.graphics.Typeface)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1