Add opened till str
This commit is contained in:
parent
0c4dfe4736
commit
4b491fb938
6 changed files with 51 additions and 13 deletions
|
@ -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 "";
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
-->
|
||||
<string name="shared_string_opened">Opened</string>
|
||||
<string name="opened_from">Opened from</string>
|
||||
<string name="opened_till">Opened till</string>
|
||||
<string name="will_be_closed_at">Will be closed at</string>
|
||||
<string name="additional_actions">Additional actions</string>
|
||||
<string name="release_3_0">
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -436,6 +436,10 @@ public abstract class MenuController extends BaseMenuController {
|
|||
return "";
|
||||
}
|
||||
|
||||
public String getOpenedTillStr() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getCommonTypeStr() {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue