diff --git a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java index d57cb60f51..50acefa3da 100644 --- a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java +++ b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java @@ -223,28 +223,36 @@ public class OpeningHoursParser { } public String getClosedAtStr(Calendar cal) { - String closedAt = getClosedAtDayStr(cal); + return getClosedStr(cal, true); + } + + public String getOpenedTillStr(Calendar cal) { + return getClosedStr(cal, false); + } + + public String getClosedStr(Calendar cal, boolean nearToClosing) { + String closedAt = getClosedAtDayStr(cal, nearToClosing); if (Algorithms.isEmpty(closedAt)) { - closedAt = getClosedAtNextDayStr(cal); + closedAt = getClosedAtNextDayStr(cal, nearToClosing); } return closedAt; } - private String getClosedAtDayStr(Calendar cal) { + private String getClosedAtDayStr(Calendar cal, boolean nearToClosing) { String closedAt = ""; for (OpeningHoursRule r : rules) { if (r.containsDay(cal) && r.containsMonth(cal)) { - closedAt = r.getClosedAtStr(cal, false); + closedAt = r.getClosedAtStr(cal, false, nearToClosing); } } return closedAt; } - private String getClosedAtNextDayStr(Calendar cal) { + private String getClosedAtNextDayStr(Calendar cal, boolean nearToClosing) { String closedAt = ""; for (OpeningHoursRule r : rules) { if (r.containsNextDay(cal) && r.containsMonth(cal)) { - closedAt = r.getClosedAtStr(cal, true); + closedAt = r.getClosedAtStr(cal, true, nearToClosing); } } return closedAt; @@ -418,7 +426,7 @@ public class OpeningHoursParser { String getOpenedFromStr(Calendar cal, boolean checkPrevious); - String getClosedAtStr(Calendar cal, boolean checkNext); + String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing); } /** @@ -881,8 +889,9 @@ public class OpeningHoursParser { } @Override - public String getClosedAtStr(Calendar cal, boolean checkNext) { - int limit = 120; + public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) { + int nearToClosingLimit = 120; + int freeLimit = 300; StringBuilder sb = new StringBuilder(); int d = getCurrentDay(cal); int n = getNextDay(d); @@ -890,9 +899,10 @@ public class OpeningHoursParser { for (int i = 0; i < startTimes.size(); i++) { int startTime = startTimes.get(i); int endTime = endTimes.get(i); + int diff = endTime - time; if (startTime < endTime && endTime != -1) { if (days[d] && !checkNext) { - if (time <= endTime && endTime - time <= limit ) { + if ((time <= endTime) && ((!nearToClosing && diff >= freeLimit) || (nearToClosing && diff <= nearToClosingLimit))) { formatTime(endTime, sb); break; } @@ -902,7 +912,7 @@ public class OpeningHoursParser { formatTime(endTime, sb); break; } else if (time < endTime && days[n] && checkNext) { - if (endTime - time <= limit) { + if ((!nearToClosing && diff >= freeLimit) || (nearToClosing && diff <= nearToClosingLimit)) { formatTime(endTime, sb); break; } @@ -1118,7 +1128,7 @@ public class OpeningHoursParser { } @Override - public String getClosedAtStr(Calendar cal, boolean checkNext) { + public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) { return ""; } diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 69e904c7c3..1a9914b292 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ --> Opened Opened from + Opened till Will be closed at Additional actions diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index c0c6c1643d..b314fb2915 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -1114,6 +1114,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo openingHoursStr = getString(R.string.opened_from) + " " + menu.getOpenFromStr(); } else if (!Algorithms.isEmpty(menu.getClosedAtStr())) { openingHoursStr = getString(R.string.will_be_closed_at) + " " + menu.getClosedAtStr(); + } else if (!Algorithms.isEmpty(menu.getOpenedTillStr())) { + openingHoursStr = getString(R.string.opened_till) + " " + menu.getOpenedTillStr(); } openingHoursTextView.setText(openingHoursStr); openingHoursView.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 6d1d6c0a0d..b0e0d44533 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -436,6 +436,10 @@ public abstract class MenuController extends BaseMenuController { return ""; } + public String getOpenedTillStr() { + return ""; + } + public String getCommonTypeStr() { return ""; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java index 78365380b3..6ed91cc0b4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java @@ -21,6 +21,7 @@ public abstract class MenuTitleController { protected boolean open24_7; protected String openFromStr = ""; protected String closedAtStr = ""; + protected String openedTillStr = ""; private AddressLookupRequest addressLookupRequest; @@ -113,8 +114,12 @@ public abstract class MenuTitleController { return closedAtStr; } + public String getOpenedTillStr() { + return openedTillStr; + } + public boolean isOpened() { - if (isOpen24_7() || !Algorithms.isEmpty(getOpenFromStr()) || !Algorithms.isEmpty(getClosedAtStr())) { + if (isOpen24_7() || !Algorithms.isEmpty(getOpenFromStr()) || !Algorithms.isEmpty(getClosedAtStr()) || !Algorithms.isEmpty(getOpenedTillStr())) { return true; } else { return false; @@ -217,6 +222,7 @@ public abstract class MenuTitleController { open24_7 = menuController.isOpen24_7(); openFromStr = menuController.getOpenFromStr(); closedAtStr = menuController.getClosedAtStr(); + openedTillStr = menuController.getOpenedTillStr(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 53b9bbbcde..325f9edb60 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -133,6 +133,11 @@ public class AmenityMenuController extends MenuController { return getClosedAtStr(amenity); } + @Override + public String getOpenedTillStr() { + return getOpenedTillStr(amenity); + } + public static String getTypeStr(Amenity amenity) { PoiCategory pc = amenity.getType(); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); @@ -181,6 +186,16 @@ public class AmenityMenuController extends MenuController { } } + public static String getOpenedTillStr(Amenity amenity) { + OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours()); + if (openingHours == null) { + return ""; + } else { + Calendar cal = Calendar.getInstance(); + return openingHours.getOpenedTillStr(cal); + } + } + @Override public String getCommonTypeStr() { PoiCategory pc = amenity.getType();