diff --git a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
index ebc5a226e5..7a2b31cc81 100644
--- a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
+++ b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
@@ -194,6 +194,34 @@ public class OpeningHoursParser {
return open24_7;
}
+ public String getOpenFromStr(Calendar cal) {
+ String openFrom = getOpenFromDayStr(cal);
+ if (Algorithms.isEmpty(openFrom)) {
+ openFrom = getOpenFromPreviousStr(cal);
+ }
+ return openFrom;
+ }
+
+ private String getOpenFromDayStr(Calendar cal) {
+ String openFrom = "";
+ for (OpeningHoursRule r : rules) {
+ if (r.containsDay(cal) && r.containsMonth(cal)) {
+ openFrom = r.getOpenedFromStr(cal, false);
+ }
+ }
+ return openFrom;
+ }
+
+ private String getOpenFromPreviousStr(Calendar cal) {
+ String openFrom = "";
+ for (OpeningHoursRule r : rules) {
+ if (r.containsPreviousDay(cal) && r.containsMonth(cal)) {
+ openFrom = r.getOpenedFromStr(cal, true);
+ }
+ }
+ return openFrom;
+ }
+
public String getCurrentRuleTime(Calendar cal) {
// make exception for overlapping times i.e.
// (1) Mo 14:00-16:00; Tu off
@@ -351,6 +379,8 @@ public class OpeningHoursParser {
public String toLocalRuleString();
boolean isOpen24_7();
+
+ String getOpenedFromStr(Calendar cal, boolean checkPrevious);
}
/**
@@ -607,14 +637,10 @@ public class OpeningHoursParser {
*/
@Override
public boolean isOpenedForTime(Calendar cal, boolean checkPrevious) {
- int i = cal.get(Calendar.DAY_OF_WEEK);
- int d = (i + 5) % 7;
- int p = d - 1;
- if (p < 0) {
- p += 7;
- }
- int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE); // Time in minutes
- for (i = 0; i < startTimes.size(); i++) {
+ int d = getCurrentDay(cal);
+ int p = getPreviousDay(d);
+ int time = getCurrentTimeInMinutes(cal); // Time in minutes
+ for (int i = 0; i < startTimes.size(); i++) {
int startTime = this.startTimes.get(i);
int endTime = this.endTimes.get(i);
if (startTime < endTime || endTime == -1) {
@@ -638,6 +664,23 @@ public class OpeningHoursParser {
return false;
}
+ private int getCurrentDay(Calendar cal) {
+ int i = cal.get(Calendar.DAY_OF_WEEK);
+ return (i + 5) % 7;
+ }
+
+ private int getPreviousDay(int currentDay) {
+ int p = currentDay - 1;
+ if (p < 0) {
+ p += 7;
+ }
+ return p;
+ }
+
+ private int getCurrentTimeInMinutes(Calendar cal) {
+ return cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
+ }
+
@Override
public String toRuleString() {
return toRuleString(daysStr, monthsStr);
@@ -749,6 +792,43 @@ public class OpeningHoursParser {
return false;
}
+ @Override
+ public String getOpenedFromStr(Calendar cal, boolean checkPrevious) {
+ StringBuilder sb = new StringBuilder();
+ int d = getCurrentDay(cal);
+ int p = getPreviousDay(d);
+ int time = getCurrentTimeInMinutes(cal);
+ for (int i = 0; i < startTimes.size(); i++) {
+ int startTime = startTimes.get(i);
+ int endTime = endTimes.get(i);
+ if (startTime < endTime || endTime == -1) {
+ if (days[d] && !checkPrevious) {
+ if (time - startTime <= 600 && (endTime == -1 || time <= endTime)) {
+ int stHour = startTime / 60;
+ int stTime = startTime - stHour * 60;
+ formatTime(stHour, stTime, sb);
+ break;
+ }
+ }
+ } else {
+ if (time >= startTime && days[d] && !checkPrevious) {
+ int stHour = startTime / 60;
+ int stTime = startTime - stHour * 60;
+ formatTime(stHour, stTime, sb);
+ break;
+ } else if (time < endTime && days[p] && checkPrevious) {
+ if (24 * 60 - endTime + time <= 600) {
+ int stHour = startTime / 60;
+ int stTime = startTime - stHour * 60;
+ formatTime(stHour, stTime, sb);
+ break;
+ }
+ }
+ }
+ }
+ return sb.toString();
+ }
+
@Override
public String toString() {
return toRuleString();
@@ -944,6 +1024,11 @@ public class OpeningHoursParser {
return false;
}
+ @Override
+ public String getOpenedFromStr(Calendar cal, boolean checkPrevious) {
+ return "";
+ }
+
@Override
public String toString() {
return toRuleString();
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 10df5c1d47..0f819d4c24 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
+ Opened
+ Opened from
Additional actions
\u2022 Detection of stop signs now considers driving direction\n\n
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
index 07339d4f0b..662da8c670 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
@@ -1106,8 +1106,14 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
View openingHoursView = view.findViewById(R.id.opening_hours_view);
TextView openingHoursTextView = (TextView) view.findViewById(R.id.opening_hours_text_view);
openingHoursTextView.setTextColor(ContextCompat.getColor(getContext(), menu.isOpened() ? R.color.ctx_menu_amenity_opened_text_color : R.color.ctx_menu_amenity_closed_text_color));
- if (menu.isOpen24_7()) {
- openingHoursTextView.setText(getString(R.string.shared_string_is_open_24_7));
+ String openingHoursStr = "";
+ if (menu.isOpened()) {
+ if (menu.isOpen24_7()) {
+ openingHoursStr = getString(R.string.shared_string_is_open_24_7);
+ } else if (!Algorithms.isEmpty(menu.getOpenFromStr())) {
+ openingHoursStr = getString(R.string.opened_from) + " " + menu.getOpenFromStr();
+ }
+ openingHoursTextView.setText(openingHoursStr);
openingHoursView.setVisibility(View.VISIBLE);
} else {
openingHoursView.setVisibility(View.GONE);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
index ccb3ab8975..24e2c3d922 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
@@ -428,6 +428,10 @@ public abstract class MenuController extends BaseMenuController {
return false;
}
+ public String getOpenFromStr() {
+ 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 7b195dcf6f..d12e2433ec 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
@@ -19,6 +19,7 @@ public abstract class MenuTitleController {
protected Drawable secondLineTypeIcon;
protected String streetStr = "";
protected boolean open24_7;
+ protected String openFromStr = "";
private AddressLookupRequest addressLookupRequest;
@@ -103,8 +104,12 @@ public abstract class MenuTitleController {
return open24_7;
}
+ public String getOpenFromStr() {
+ return openFromStr;
+ }
+
public boolean isOpened() {
- if (isOpen24_7()) {
+ if (isOpen24_7() || !Algorithms.isEmpty(getOpenFromStr())) {
return true;
} else {
return false;
@@ -205,6 +210,7 @@ public abstract class MenuTitleController {
MenuController menuController = getMenuController();
if (menuController != null) {
open24_7 = menuController.isOpen24_7();
+ openFromStr = menuController.getOpenFromStr();
}
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java
index d9aecf86ab..3cb5bdc9e8 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java
@@ -123,6 +123,11 @@ public class AmenityMenuController extends MenuController {
return isOpen24_7(amenity);
}
+ @Override
+ public String getOpenFromStr() {
+ return getOpenFromStr(amenity);
+ }
+
public static String getTypeStr(Amenity amenity) {
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
@@ -151,6 +156,16 @@ public class AmenityMenuController extends MenuController {
return isOpen24_7;
}
+ public static String getOpenFromStr(Amenity amenity) {
+ OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
+ if (openingHours == null) {
+ return "";
+ } else {
+ Calendar cal = Calendar.getInstance();
+ return openingHours.getOpenFromStr(cal);
+ }
+ }
+
@Override
public String getCommonTypeStr() {
PoiCategory pc = amenity.getType();