Search in sources :

Example 1 with ExportSettingsType

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

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

the class SettingsHelper method getSettingsItems.

private Map<ExportSettingsType, List<?>> getSettingsItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> settingsItems = new LinkedHashMap<>();
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.PROFILE)) {
        List<ApplicationModeBean> appModeBeans = new ArrayList<>();
        for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
            appModeBeans.add(mode.toModeBean());
        }
        settingsItems.put(ExportSettingsType.PROFILE, appModeBeans);
    }
    List<GlobalSettingsItem> globalSettingsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.GLOBAL) ? Collections.singletonList(new GlobalSettingsItem(app.getSettings())) : Collections.emptyList();
    if (!globalSettingsList.isEmpty() || addEmptyItems) {
        settingsItems.put(ExportSettingsType.GLOBAL, globalSettingsList);
    }
    QuickActionRegistry registry = app.getQuickActionRegistry();
    List<QuickAction> actionsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.QUICK_ACTIONS) ? registry.getQuickActions() : Collections.emptyList();
    if (!actionsList.isEmpty() || addEmptyItems) {
        settingsItems.put(ExportSettingsType.QUICK_ACTIONS, actionsList);
    }
    List<PoiUIFilter> poiList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.POI_TYPES) ? app.getPoiFilters().getUserDefinedPoiFilters(false) : Collections.emptyList();
    if (!poiList.isEmpty() || addEmptyItems) {
        settingsItems.put(ExportSettingsType.POI_TYPES, poiList);
    }
    Map<LatLon, AvoidRoadInfo> impassableRoads = settingsTypes == null || settingsTypes.contains(ExportSettingsType.AVOID_ROADS) ? app.getAvoidSpecificRoads().getImpassableRoads() : Collections.emptyMap();
    if (!impassableRoads.isEmpty() || addEmptyItems) {
        settingsItems.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
    }
    return settingsItems;
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) ArrayList(java.util.ArrayList) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) LinkedHashMap(java.util.LinkedHashMap) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) List(java.util.List) ArrayList(java.util.ArrayList) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Example 3 with ExportSettingsType

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

the class SettingsHelper method getMyPlacesItems.

private Map<ExportSettingsType, List<?>> getMyPlacesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
    List<FavoriteGroup> favoriteGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.FAVORITES) ? app.getFavoritesHelper().getFavoriteGroups() : Collections.emptyList();
    if (!favoriteGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.FAVORITES, favoriteGroups);
    }
    List<GpxDataItem> gpxItems = settingsTypes == null || settingsTypes.contains(ExportSettingsType.TRACKS) ? app.getGpxDbHelper().getItems() : Collections.emptyList();
    if (!gpxItems.isEmpty() || addEmptyItems) {
        List<File> files = new ArrayList<>();
        for (GpxDataItem gpxItem : gpxItems) {
            File file = gpxItem.getFile();
            if (file.exists() && !file.isDirectory()) {
                files.add(file);
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.TRACKS, files);
        }
    }
    OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        List<OsmNotesPoint> notesPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_NOTES) ? osmEditingPlugin.getDBBug().getOsmbugsPoints() : Collections.emptyList();
        if (!notesPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_NOTES, notesPointList);
        }
        List<OpenstreetmapPoint> editsPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_EDITS) ? osmEditingPlugin.getDBPOI().getOpenstreetmapPoints() : Collections.emptyList();
        if (!editsPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_EDITS, editsPointList);
        }
    }
    AudioVideoNotesPlugin avNotesPlugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
    if (avNotesPlugin != null) {
        List<File> files = new ArrayList<>();
        if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MULTIMEDIA_NOTES)) {
            for (Recording rec : avNotesPlugin.getAllRecordings()) {
                File file = rec.getFile();
                if (file != null && file.exists()) {
                    files.add(file);
                }
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
        }
    }
    List<MapMarker> mapMarkers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ACTIVE_MARKERS) ? app.getMapMarkersHelper().getMapMarkers() : Collections.emptyList();
    if (!mapMarkers.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.map_markers);
        String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(mapMarkers);
        myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
    }
    List<MapMarker> markersHistory = settingsTypes == null || settingsTypes.contains(ExportSettingsType.HISTORY_MARKERS) ? app.getMapMarkersHelper().getMapMarkersHistory() : Collections.emptyList();
    if (!markersHistory.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.shared_string_history);
        String groupId = ExportSettingsType.HISTORY_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(markersHistory);
        myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
    }
    List<HistoryEntry> historyEntries = settingsTypes == null || settingsTypes.contains(ExportSettingsType.SEARCH_HISTORY) ? SearchHistoryHelper.getInstance(app).getHistoryEntries(false) : Collections.emptyList();
    if (!historyEntries.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
    }
    List<MapMarkersGroup> markersGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ITINERARY_GROUPS) ? app.getMapMarkersHelper().getVisibleMapMarkersGroups() : Collections.emptyList();
    if (!markersGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.ITINERARY_GROUPS, markersGroups);
    }
    return myPlacesItems;
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) MapMarker(net.osmand.plus.mapmarkers.MapMarker) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) List(java.util.List) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Recording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.Recording) File(java.io.File)

Example 4 with ExportSettingsType

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

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

ExportSettingsType (net.osmand.plus.settings.backend.ExportSettingsType)36 ArrayList (java.util.ArrayList)18 List (java.util.List)10 SettingsCategoryItems (net.osmand.plus.settings.fragments.SettingsCategoryItems)9 ExportSettingsCategory (net.osmand.plus.settings.backend.ExportSettingsCategory)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Nullable (androidx.annotation.Nullable)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)4 NonNull (androidx.annotation.NonNull)3 EnumMap (java.util.EnumMap)3 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)3 SuppressLint (android.annotation.SuppressLint)2 Typeface (android.graphics.Typeface)2 AsyncTask (android.os.AsyncTask)2