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[] localMothsStr;
|
||||
|
||||
private static final int LOW_TIME_LIMIT = 120;
|
||||
private static final int HIGH_TIME_LIMIT = 300;
|
||||
|
||||
static {
|
||||
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
|
||||
monthsStr = dateFormatSymbols.getShortMonths();
|
||||
|
@ -195,44 +198,63 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
public String getNearToOpeningTime(Calendar cal) {
|
||||
return getTime(cal, true, true);
|
||||
return getTime(cal, LOW_TIME_LIMIT, true);
|
||||
}
|
||||
|
||||
public String getOpeningTime(Calendar cal) {
|
||||
return getTime(cal, false, true);
|
||||
return getTime(cal, HIGH_TIME_LIMIT, true);
|
||||
}
|
||||
|
||||
public String getNearToClosingTime(Calendar cal) {
|
||||
return getTime(cal, true, false);
|
||||
return getTime(cal, LOW_TIME_LIMIT, false);
|
||||
}
|
||||
|
||||
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) {
|
||||
String time = getTimeDay(cal, nearToEvent, opening);
|
||||
public String getOpeningDay(Calendar calendar) {
|
||||
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)) {
|
||||
time = getTimeAnotherDay(cal, nearToEvent, opening);
|
||||
time = getTimeAnotherDay(cal, limit, opening);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
private String getTimeDay(Calendar cal, boolean nearToEvent, boolean opening) {
|
||||
private String getTimeDay(Calendar cal, int limit, boolean opening) {
|
||||
String atTime = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
||||
atTime = r.getTime(cal, false, nearToEvent, opening);
|
||||
atTime = r.getTime(cal, false, limit, opening);
|
||||
}
|
||||
}
|
||||
return atTime;
|
||||
}
|
||||
|
||||
private String getTimeAnotherDay(Calendar cal, boolean nearToEvent, boolean opening) {
|
||||
private String getTimeAnotherDay(Calendar cal, int limit, boolean opening) {
|
||||
String atTime = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
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;
|
||||
|
@ -404,7 +426,7 @@ public class OpeningHoursParser {
|
|||
|
||||
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
|
||||
public String getTime(Calendar cal, boolean checkAnotherDay, boolean nearToEvent, boolean opening) {
|
||||
int nearToEventLimit = 120;
|
||||
int freeLimit = 300;
|
||||
public String getTime(Calendar cal, boolean checkAnotherDay, int limit, boolean opening) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int d = getCurrentDay(cal);
|
||||
int ad = opening ? getNextDay(d) : getPreviousDay(d);
|
||||
|
@ -849,7 +869,7 @@ public class OpeningHoursParser {
|
|||
if (startTime < endTime || endTime == -1) {
|
||||
if (days[d] && !checkAnotherDay) {
|
||||
int diff = startTime - time;
|
||||
if ((time <= startTime) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
||||
if (limit == -1 || ((time <= startTime) && (diff <= limit))) {
|
||||
formatTime(startTime, sb);
|
||||
break;
|
||||
}
|
||||
|
@ -861,7 +881,7 @@ public class OpeningHoursParser {
|
|||
} else if (time > endTime && days[ad] && checkAnotherDay) {
|
||||
diff = 24 * 60 - endTime + time;
|
||||
}
|
||||
if ((diff != -1) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
||||
if (limit == -1 || ((diff != -1) && (diff <= limit))) {
|
||||
formatTime(startTime, sb);
|
||||
break;
|
||||
}
|
||||
|
@ -870,7 +890,7 @@ public class OpeningHoursParser {
|
|||
if (startTime < endTime && endTime != -1) {
|
||||
if (days[d] && !checkAnotherDay) {
|
||||
int diff = endTime - time;
|
||||
if ((time <= endTime) && ((!nearToEvent && diff <= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
||||
if (limit == -1 || ((time <= endTime) && (diff <= limit))) {
|
||||
formatTime(endTime, sb);
|
||||
break;
|
||||
}
|
||||
|
@ -882,7 +902,7 @@ public class OpeningHoursParser {
|
|||
} else if (time < endTime && days[ad] && checkAnotherDay) {
|
||||
diff = startTime - time;
|
||||
}
|
||||
if ((diff != -1) && ((!nearToEvent && diff >= freeLimit) || (nearToEvent && diff <= nearToEventLimit))) {
|
||||
if (limit == -1 || ((diff != -1) && (diff <= limit))) {
|
||||
formatTime(endTime, sb);
|
||||
break;
|
||||
}
|
||||
|
@ -1093,7 +1113,7 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getTime(Calendar cal, boolean checkAnotherDay, boolean nearToEvent, boolean opening) {
|
||||
public String getTime(Calendar cal, boolean checkAnotherDay, int limit, boolean opening) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="opened_till">Opened till</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_on">Will be opened on</string>
|
||||
<string name="additional_actions">Additional actions</string>
|
||||
<string name="release_3_0">
|
||||
\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();
|
||||
} else if (!Algorithms.isEmpty(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.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -10,6 +10,7 @@ public class OpeningHoursInfo {
|
|||
private String nearToOpeningTime = "";
|
||||
private String closingTime = "";
|
||||
private String nearToClosingTime = "";
|
||||
private String openingDay = "";
|
||||
|
||||
public boolean isOpened() {
|
||||
return opened;
|
||||
|
@ -59,11 +60,20 @@ public class OpeningHoursInfo {
|
|||
this.nearToClosingTime = nearToClosingTime;
|
||||
}
|
||||
|
||||
public String getOpeningDay() {
|
||||
return openingDay;
|
||||
}
|
||||
|
||||
public void setOpeningDay(String openingDay) {
|
||||
this.openingDay = openingDay;
|
||||
}
|
||||
|
||||
public boolean containsInfo() {
|
||||
return opened24_7
|
||||
|| !Algorithms.isEmpty(openingTime)
|
||||
|| !Algorithms.isEmpty(nearToOpeningTime)
|
||||
|| !Algorithms.isEmpty(closingTime)
|
||||
|| !Algorithms.isEmpty(nearToClosingTime);
|
||||
|| !Algorithms.isEmpty(nearToClosingTime)
|
||||
|| !Algorithms.isEmpty(openingDay);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,12 +143,17 @@ public class AmenityMenuController extends MenuController {
|
|||
} else {
|
||||
OpeningHoursInfo info = new OpeningHoursInfo();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
info.setOpened(openingHours.isOpenedForTime(cal));
|
||||
boolean opened = openingHours.isOpenedForTime(cal);
|
||||
info.setOpened(opened);
|
||||
if (opened) {
|
||||
info.setOpened24_7(openingHours.isOpened24_7());
|
||||
info.setOpeningTime(openingHours.getOpeningTime(cal));
|
||||
info.setNearToOpeningTime(openingHours.getNearToOpeningTime(cal));
|
||||
info.setClosingTime(openingHours.getClosingTime(cal));
|
||||
info.setNearToClosingTime(openingHours.getNearToClosingTime(cal));
|
||||
} else {
|
||||
info.setOpeningTime(openingHours.getOpeningTime(cal));
|
||||
info.setNearToOpeningTime(openingHours.getNearToOpeningTime(cal));
|
||||
info.setOpeningDay(openingHours.getOpeningDay(cal));
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue