Search in sources :

Example 1 with MapMarkersGroup

use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method createDisplayGroups.

private void createDisplayGroups() {
    items = new ArrayList<>();
    MapMarkersHelper helper = app.getMapMarkersHelper();
    helper.updateGroups();
    List<MapMarkersGroup> groups = new ArrayList<>(helper.getVisibleMapMarkersGroups());
    groups.addAll(helper.getGroupsForDisplayedGpx());
    groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
    // evaluate time constants
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    long currentTimeMillis = System.currentTimeMillis();
    Calendar currentDateCalendar = Calendar.getInstance();
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    // evaluate today, yesterday, last 7 days
    String today = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -1);
    String yesterday = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
    currentDateCalendar.set(Calendar.MINUTE, 0);
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -6);
    long last7Days = currentDateCalendar.getTimeInMillis();
    // evaluate this year & last 3 months
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    String thisYear = dateFormat.format(currentDateCalendar.getTime()).substring(0, 5);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus1 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus2 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus3 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    Calendar markerCalendar = Calendar.getInstance();
    for (int i = 0; i < groups.size(); i++) {
        MapMarkersGroup group = groups.get(i);
        String markerGroupName = group.getName();
        if (markerGroupName == null) {
            int previousGroupDateId = 0;
            List<MapMarker> groupMarkers = group.getActiveMarkers();
            for (int j = 0; j < groupMarkers.size(); j++) {
                MapMarker marker = groupMarkers.get(j);
                String markerDate = dateFormat.format(new Date(marker.creationDate));
                int currentGroupDateId;
                MarkerGroupItem currentGroupItem = null;
                if (marker.creationDate >= currentTimeMillis || (today.equals(markerDate))) {
                    currentGroupDateId = -1;
                    currentGroupItem = MarkerGroupItem.TODAY_HEADER;
                } else if (yesterday.equals(markerDate)) {
                    currentGroupDateId = -2;
                    currentGroupItem = MarkerGroupItem.YESTERDAY_HEADER;
                } else if (marker.creationDate >= last7Days) {
                    currentGroupDateId = -3;
                    currentGroupItem = MarkerGroupItem.LAST_SEVEN_DAYS_HEADER;
                } else if (markerDate.startsWith(monthMinus1)) {
                    currentGroupDateId = -5;
                } else if (markerDate.startsWith(monthMinus2)) {
                    currentGroupDateId = -6;
                } else if (markerDate.startsWith(monthMinus3)) {
                    currentGroupDateId = -7;
                } else if (markerDate.startsWith(thisYear)) {
                    currentGroupItem = MarkerGroupItem.THIS_YEAR_HEADER;
                    currentGroupDateId = -4;
                } else {
                    markerCalendar.setTimeInMillis(marker.creationDate);
                    currentGroupDateId = markerCalendar.get(Calendar.YEAR);
                }
                if (previousGroupDateId != currentGroupDateId) {
                    if (currentGroupItem != null) {
                        items.add(currentGroupItem);
                    } else if (currentGroupDateId < 0) {
                        SimpleDateFormat monthdateFormat = new SimpleDateFormat("LLLL", Locale.getDefault());
                        String monthStr = monthdateFormat.format(new Date(marker.creationDate));
                        if (monthStr.length() > 1) {
                            monthStr = Algorithms.capitalizeFirstLetter(monthStr);
                        }
                        items.add(new MarkerGroupItem(monthStr));
                    } else {
                        items.add(new MarkerGroupItem(currentGroupDateId + ""));
                    }
                    previousGroupDateId = currentGroupDateId;
                }
                items.add(marker);
            }
        } else {
            items.add(new GroupHeader(group));
            if (!group.isDisabled()) {
                if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
                    CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(group);
                    items.add(categoriesSubHeader);
                }
                TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper();
                if (travelHelper.isAnyTravelBookPresent()) {
                    List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
                    for (TravelArticle art : savedArticles) {
                        String gpxName = travelHelper.getGPXName(art);
                        File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
                        if (path.getAbsolutePath().equals(group.getGpxPath(app))) {
                            group.setWikivoyageArticle(art);
                        }
                    }
                }
            }
            if (Algorithms.isEmpty(group.getWptCategories())) {
                helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath(app)).getPointsByCategories().keySet());
            }
            populateAdapterWithGroupMarkers(group, getItemCount());
        }
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) Calendar(java.util.Calendar) GroupHeader(net.osmand.plus.mapmarkers.GroupHeader) ArrayList(java.util.ArrayList) Date(java.util.Date) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) SimpleDateFormat(java.text.SimpleDateFormat) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Example 2 with MapMarkersGroup

use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.

the class ItinerarySettingsItem method apply.

@Override
public void apply() {
    List<MapMarkersGroup> newItems = getNewItems();
    if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
        appliedItems = new ArrayList<>(newItems);
        for (MapMarkersGroup duplicate : duplicateItems) {
            if (shouldReplace) {
                MapMarkersGroup existingGroup = markersHelper.getMapMarkerGroupById(duplicate.getId(), duplicate.getType());
                markersHelper.removeMarkersGroup(existingGroup);
            }
            appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
        }
        for (MapMarkersGroup markersGroup : appliedItems) {
            markersHelper.enableGroup(markersGroup);
        }
        markersHelper.syncAllGroups();
    }
}
Also used : MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup)

Example 3 with MapMarkersGroup

use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.

the class ItinerarySettingsItem method getReader.

@Nullable
@Override
public SettingsItemReader<ItinerarySettingsItem> getReader() {
    return new SettingsItemReader<ItinerarySettingsItem>(this) {

        @Override
        public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IllegalArgumentException {
            List<ItineraryGroupInfo> groupInfos = new ArrayList<>();
            GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream, dataHelper.getGPXExtensionsReader(groupInfos));
            if (gpxFile.error != null) {
                warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
                SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
            } else {
                Map<String, MapMarker> markers = new LinkedHashMap<>();
                Map<String, MapMarkersGroup> groups = new LinkedHashMap<>();
                dataHelper.collectMarkersGroups(gpxFile, groups, groupInfos, markers);
                items.addAll(groups.values());
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ItineraryGroupInfo(net.osmand.plus.mapmarkers.ItineraryDataHelper.ItineraryGroupInfo) LinkedHashMap(java.util.LinkedHashMap) SettingsItemReader(net.osmand.plus.settings.backend.backup.SettingsItemReader) NonNull(androidx.annotation.NonNull) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) GPXFile(net.osmand.GPXUtilities.GPXFile) Nullable(androidx.annotation.Nullable)

Example 4 with MapMarkersGroup

use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.

the class HistoryMarkersSettingsItem method getMarkersGroup.

public MapMarkersGroup getMarkersGroup() {
    String name = app.getString(R.string.markers_history);
    String groupId = ExportSettingsType.HISTORY_MARKERS.name();
    MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
    markersGroup.setMarkers(items);
    return markersGroup;
}
Also used : MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup)

Example 5 with MapMarkersGroup

use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.

the class EditTrackGroupDialogFragment method createCopyToMarkersItem.

private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) {
    MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile);
    final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories()) || markersGroup.getWptCategories().contains(group.getName()));
    return new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy)).setTitle(getString(synced ? R.string.remove_group_from_markers : R.string.add_group_to_markers)).setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            updateGroupWptCategory(gpxFile, synced);
            dismiss();
        }
    }).create();
}
Also used : SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ImageView(android.widget.ImageView) View(android.view.View) BooleanPreferenceBottomSheet.updateCustomButtonView(net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.updateCustomButtonView) AdapterView(android.widget.AdapterView) BooleanPreferenceBottomSheet.getCustomButtonView(net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.getCustomButtonView)

Aggregations

MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)23 File (java.io.File)9 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)9 MapMarker (net.osmand.plus.mapmarkers.MapMarker)8 ArrayList (java.util.ArrayList)7 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)7 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)6 ITileSource (net.osmand.map.ITileSource)5 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)4 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)4 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)4 Bundle (android.os.Bundle)2