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