Add opened from string

This commit is contained in:
PavelRatushny 2017-12-07 17:09:04 +02:00
parent 94a5074dbd
commit 587aaff2c6
6 changed files with 129 additions and 11 deletions

View file

@ -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();

View file

@ -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
-->
<string name="shared_string_opened">Opened</string>
<string name="opened_from">Opened from</string>
<string name="additional_actions">Additional actions</string>
<string name="release_3_0">
\u2022 Detection of stop signs now considers driving direction\n\n

View file

@ -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);

View file

@ -428,6 +428,10 @@ public abstract class MenuController extends BaseMenuController {
return false;
}
public String getOpenFromStr() {
return "";
}
public String getCommonTypeStr() {
return "";
}

View file

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

View file

@ -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();