Add opening day str
This commit is contained in:
parent
53ee937be7
commit
d9b4a213c9
5 changed files with 65 additions and 27 deletions
|
@ -28,6 +28,9 @@ public class OpeningHoursParser {
|
||||||
private static final String[] monthsStr;
|
private static final String[] monthsStr;
|
||||||
private static final String[] localMothsStr;
|
private static final String[] localMothsStr;
|
||||||
|
|
||||||
|
private static final int LOW_TIME_LIMIT = 120;
|
||||||
|
private static final int HIGH_TIME_LIMIT = 300;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
|
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
|
||||||
monthsStr = dateFormatSymbols.getShortMonths();
|
monthsStr = dateFormatSymbols.getShortMonths();
|
||||||
|
@ -195,44 +198,63 @@ public class OpeningHoursParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNearToOpeningTime(Calendar cal) {
|
public String getNearToOpeningTime(Calendar cal) {
|
||||||
return getTime(cal, true, true);
|
return getTime(cal, LOW_TIME_LIMIT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOpeningTime(Calendar cal) {
|
public String getOpeningTime(Calendar cal) {
|
||||||
return getTime(cal, false, true);
|
return getTime(cal, HIGH_TIME_LIMIT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNearToClosingTime(Calendar cal) {
|
public String getNearToClosingTime(Calendar cal) {
|
||||||
return getTime(cal, true, false);
|
return getTime(cal, LOW_TIME_LIMIT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClosingTime(Calendar cal) {
|
public String getClosingTime(Calendar cal) {
|
||||||
return getTime(cal, false, false);
|
return getTime(cal, HIGH_TIME_LIMIT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTime(Calendar cal, boolean nearToEvent, boolean opening) {
|
public String getOpeningDay(Calendar calendar) {
|
||||||
String time = getTimeDay(cal, nearToEvent, opening);
|
Calendar cal = (Calendar) calendar.clone();
|
||||||
|
String openingTime = "";
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
for (OpeningHoursRule r : rules) {
|
||||||
|
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
||||||
|
openingTime = r.getTime(cal, false, -1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Algorithms.isEmpty(openingTime)) {
|
||||||
|
openingTime += " " + localDaysStr[cal.get(Calendar.DAY_OF_WEEK)];
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return openingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTime(Calendar cal, int limit, boolean opening) {
|
||||||
|
String time = getTimeDay(cal, limit, opening);
|
||||||
if (Algorithms.isEmpty(time)) {
|
if (Algorithms.isEmpty(time)) {
|
||||||
time = getTimeAnotherDay(cal, nearToEvent, opening);
|
time = getTimeAnotherDay(cal, limit, opening);
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeDay(Calendar cal, boolean nearToEvent, boolean opening) {
|
private String getTimeDay(Calendar cal, int limit, boolean opening) {
|
||||||
String atTime = "";
|
String atTime = "";
|
||||||
for (OpeningHoursRule r : rules) {
|
for (OpeningHoursRule r : rules) {
|
||||||
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
||||||
atTime = r.getTime(cal, false, nearToEvent, opening);
|
atTime = r.getTime(cal, false, limit, opening);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return atTime;
|
return atTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeAnotherDay(Calendar cal, boolean nearToEvent, boolean opening) {
|
private String getTimeAnotherDay(Calendar cal, int limit, boolean opening) {
|
||||||
String atTime = "";
|
String atTime = "";
|
||||||
for (OpeningHoursRule r : rules) {
|
for (OpeningHoursRule r : rules) {
|
||||||
if (((opening && r.containsPreviousDay(cal)) || (!opening && r.containsNextDay(cal))) && r.containsMonth(cal)) {
|
if (((opening && r.containsPreviousDay(cal)) || (!opening && r.containsNextDay(cal))) && r.containsMonth(cal)) {
|
||||||
atTime = r.getTime(cal, true, nearToEvent, opening);
|
atTime = r.getTime(cal, true, limit, opening);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return atTime;
|
return atTime;
|
||||||
|
@ -404,7 +426,7 @@ public class OpeningHoursParser {
|
||||||
|
|
||||||
boolean isOpened24_7();
|
boolean isOpened24_7();
|
||||||
|
|
||||||
String getTime(Calendar cal, boolean checkAnotherDay, boolean nearToEvent, boolean opening);
|
String getTime(Calendar cal, boolean checkAnotherDay, int limit, boolean opening);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -835,9 +857,7 @@ public class OpeningHoursParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTime(Calendar cal, boolean checkAnotherDay, boolean nearToEvent, boolean opening) {
|
public String getTime(Calendar cal, boolean checkAnotherDay, int limit, boolean opening) {
|
||||||
int nearToEventLimit = 120;
|
|
||||||
int freeLimit = 300;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int d = getCurrentDay(cal);
|
int d = getCurrentDay(cal);
|
||||||
int ad = opening ? getNextDay(d) : getPreviousDay(d);
|
int ad = opening ? getNextDay(d) : getPreviousDay(d);
|
||||||
|
@ -849,7 +869,7 @@ public class OpeningHoursParser {
|
||||||
if (startTime < endTime || endTime == -1) {
|
if (startTime < endTime || endTime == -1) {
|
||||||
if (days[d] && !checkAnotherDay) {
|
if (days[d] && !checkAnotherDay) {
|
||||||
int diff = startTime - time;
|
int diff = startTime - time;
|
||||||
if ((time <= startTime) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
if (limit == -1 || ((time <= startTime) && (diff <= limit))) {
|
||||||
formatTime(startTime, sb);
|
formatTime(startTime, sb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -861,7 +881,7 @@ public class OpeningHoursParser {
|
||||||
} else if (time > endTime && days[ad] && checkAnotherDay) {
|
} else if (time > endTime && days[ad] && checkAnotherDay) {
|
||||||
diff = 24 * 60 - endTime + time;
|
diff = 24 * 60 - endTime + time;
|
||||||
}
|
}
|
||||||
if ((diff != -1) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
if (limit == -1 || ((diff != -1) && (diff <= limit))) {
|
||||||
formatTime(startTime, sb);
|
formatTime(startTime, sb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -870,7 +890,7 @@ public class OpeningHoursParser {
|
||||||
if (startTime < endTime && endTime != -1) {
|
if (startTime < endTime && endTime != -1) {
|
||||||
if (days[d] && !checkAnotherDay) {
|
if (days[d] && !checkAnotherDay) {
|
||||||
int diff = endTime - time;
|
int diff = endTime - time;
|
||||||
if ((time <= endTime) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
if (limit == -1 || ((time <= endTime) && (diff <= limit))) {
|
||||||
formatTime(endTime, sb);
|
formatTime(endTime, sb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -882,7 +902,7 @@ public class OpeningHoursParser {
|
||||||
} else if (time < endTime && days[ad] && checkAnotherDay) {
|
} else if (time < endTime && days[ad] && checkAnotherDay) {
|
||||||
diff = startTime - time;
|
diff = startTime - time;
|
||||||
}
|
}
|
||||||
if ((diff != -1) && ((!nearToEvent && diff >= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
if (limit == -1 || ((diff != -1) && (diff <= limit))) {
|
||||||
formatTime(endTime, sb);
|
formatTime(endTime, sb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1093,7 +1113,7 @@ public class OpeningHoursParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTime(Calendar cal, boolean checkAnotherDay, boolean nearToEvent, boolean opening) {
|
public String getTime(Calendar cal, boolean checkAnotherDay, int limit, boolean opening) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<string name="opened_till">Opened till</string>
|
<string name="opened_till">Opened till</string>
|
||||||
<string name="will_be_closed_at">Will be closed at</string>
|
<string name="will_be_closed_at">Will be closed at</string>
|
||||||
<string name="will_be_opened_at">Will be opened at</string>
|
<string name="will_be_opened_at">Will be opened at</string>
|
||||||
|
<string name="will_be_opened_on">Will be opened on</string>
|
||||||
<string name="additional_actions">Additional actions</string>
|
<string name="additional_actions">Additional actions</string>
|
||||||
<string name="release_3_0">
|
<string name="release_3_0">
|
||||||
\u2022 Detection of stop signs now considers driving direction\n\n
|
\u2022 Detection of stop signs now considers driving direction\n\n
|
||||||
|
|
|
@ -1118,6 +1118,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
||||||
openingHoursStr = getString(R.string.opened_till) + " " + openingHoursInfo.getClosingTime();
|
openingHoursStr = getString(R.string.opened_till) + " " + openingHoursInfo.getClosingTime();
|
||||||
} else if (!Algorithms.isEmpty(openingHoursInfo.getNearToClosingTime())) {
|
} else if (!Algorithms.isEmpty(openingHoursInfo.getNearToClosingTime())) {
|
||||||
openingHoursStr = getString(R.string.will_be_closed_at) + " " + openingHoursInfo.getNearToClosingTime();
|
openingHoursStr = getString(R.string.will_be_closed_at) + " " + openingHoursInfo.getNearToClosingTime();
|
||||||
|
} else if (!Algorithms.isEmpty(openingHoursInfo.getOpeningDay())) {
|
||||||
|
openingHoursStr = getString(R.string.will_be_opened_on) + " " + openingHoursInfo.getOpeningDay() + ".";
|
||||||
}
|
}
|
||||||
openingHoursTextView.setText(openingHoursStr);
|
openingHoursTextView.setText(openingHoursStr);
|
||||||
openingHoursTextView.setVisibility(View.VISIBLE);
|
openingHoursTextView.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class OpeningHoursInfo {
|
||||||
private String nearToOpeningTime = "";
|
private String nearToOpeningTime = "";
|
||||||
private String closingTime = "";
|
private String closingTime = "";
|
||||||
private String nearToClosingTime = "";
|
private String nearToClosingTime = "";
|
||||||
|
private String openingDay = "";
|
||||||
|
|
||||||
public boolean isOpened() {
|
public boolean isOpened() {
|
||||||
return opened;
|
return opened;
|
||||||
|
@ -59,11 +60,20 @@ public class OpeningHoursInfo {
|
||||||
this.nearToClosingTime = nearToClosingTime;
|
this.nearToClosingTime = nearToClosingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOpeningDay() {
|
||||||
|
return openingDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpeningDay(String openingDay) {
|
||||||
|
this.openingDay = openingDay;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean containsInfo() {
|
public boolean containsInfo() {
|
||||||
return opened24_7
|
return opened24_7
|
||||||
|| !Algorithms.isEmpty(openingTime)
|
|| !Algorithms.isEmpty(openingTime)
|
||||||
|| !Algorithms.isEmpty(nearToOpeningTime)
|
|| !Algorithms.isEmpty(nearToOpeningTime)
|
||||||
|| !Algorithms.isEmpty(closingTime)
|
|| !Algorithms.isEmpty(closingTime)
|
||||||
|| !Algorithms.isEmpty(nearToClosingTime);
|
|| !Algorithms.isEmpty(nearToClosingTime)
|
||||||
|
|| !Algorithms.isEmpty(openingDay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,12 +143,17 @@ public class AmenityMenuController extends MenuController {
|
||||||
} else {
|
} else {
|
||||||
OpeningHoursInfo info = new OpeningHoursInfo();
|
OpeningHoursInfo info = new OpeningHoursInfo();
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
info.setOpened(openingHours.isOpenedForTime(cal));
|
boolean opened = openingHours.isOpenedForTime(cal);
|
||||||
info.setOpened24_7(openingHours.isOpened24_7());
|
info.setOpened(opened);
|
||||||
info.setOpeningTime(openingHours.getOpeningTime(cal));
|
if (opened) {
|
||||||
info.setNearToOpeningTime(openingHours.getNearToOpeningTime(cal));
|
info.setOpened24_7(openingHours.isOpened24_7());
|
||||||
info.setClosingTime(openingHours.getClosingTime(cal));
|
info.setClosingTime(openingHours.getClosingTime(cal));
|
||||||
info.setNearToClosingTime(openingHours.getNearToClosingTime(cal));
|
info.setNearToClosingTime(openingHours.getNearToClosingTime(cal));
|
||||||
|
} else {
|
||||||
|
info.setOpeningTime(openingHours.getOpeningTime(cal));
|
||||||
|
info.setNearToOpeningTime(openingHours.getNearToOpeningTime(cal));
|
||||||
|
info.setOpeningDay(openingHours.getOpeningDay(cal));
|
||||||
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue