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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations