This commit is contained in:
PavelRatushny 2017-12-08 11:31:25 +02:00
parent 1b35b82db0
commit b29871e263
6 changed files with 116 additions and 145 deletions

View file

@ -189,70 +189,70 @@ public class OpeningHoursParser {
public boolean isOpen24_7() { public boolean isOpen24_7() {
boolean open24_7 = false; boolean open24_7 = false;
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
open24_7 = r.isOpen24_7(); open24_7 = r.isOpened24_7();
} }
return open24_7; return open24_7;
} }
public String getOpenFromStr(Calendar cal) { public String getOpenedFromTime(Calendar cal) {
String openFrom = getOpenFromDayStr(cal); String openFrom = getOpenFromTimeDay(cal);
if (Algorithms.isEmpty(openFrom)) { if (Algorithms.isEmpty(openFrom)) {
openFrom = getOpenFromPreviousStr(cal); openFrom = getOpenFromTimePrevious(cal);
} }
return openFrom; return openFrom;
} }
private String getOpenFromDayStr(Calendar cal) { private String getOpenFromTimeDay(Calendar cal) {
String openFrom = ""; String openFrom = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsDay(cal) && r.containsMonth(cal)) { if (r.containsDay(cal) && r.containsMonth(cal)) {
openFrom = r.getOpenedFromStr(cal, false); openFrom = r.getOpenedFromTime(cal, false);
} }
} }
return openFrom; return openFrom;
} }
private String getOpenFromPreviousStr(Calendar cal) { private String getOpenFromTimePrevious(Calendar cal) {
String openFrom = ""; String openFrom = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsPreviousDay(cal) && r.containsMonth(cal)) { if (r.containsPreviousDay(cal) && r.containsMonth(cal)) {
openFrom = r.getOpenedFromStr(cal, true); openFrom = r.getOpenedFromTime(cal, true);
} }
} }
return openFrom; return openFrom;
} }
public String getClosedAtStr(Calendar cal) { public String getClosedAtTime(Calendar cal) {
return getClosedStr(cal, true); return getClosedTime(cal, true);
} }
public String getOpenedTillStr(Calendar cal) { public String getOpenedTillTime(Calendar cal) {
return getClosedStr(cal, false); return getClosedTime(cal, false);
} }
public String getClosedStr(Calendar cal, boolean nearToClosing) { private String getClosedTime(Calendar cal, boolean nearToClosing) {
String closedAt = getClosedAtDayStr(cal, nearToClosing); String closedAt = getClosedAtTimeDay(cal, nearToClosing);
if (Algorithms.isEmpty(closedAt)) { if (Algorithms.isEmpty(closedAt)) {
closedAt = getClosedAtNextDayStr(cal, nearToClosing); closedAt = getClosedAtTimeNextDay(cal, nearToClosing);
} }
return closedAt; return closedAt;
} }
private String getClosedAtDayStr(Calendar cal, boolean nearToClosing) { private String getClosedAtTimeDay(Calendar cal, boolean nearToClosing) {
String closedAt = ""; String closedAt = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsDay(cal) && r.containsMonth(cal)) { if (r.containsDay(cal) && r.containsMonth(cal)) {
closedAt = r.getClosedAtStr(cal, false, nearToClosing); closedAt = r.getClosedAtTime(cal, false, nearToClosing);
} }
} }
return closedAt; return closedAt;
} }
private String getClosedAtNextDayStr(Calendar cal, boolean nearToClosing) { private String getClosedAtTimeNextDay(Calendar cal, boolean nearToClosing) {
String closedAt = ""; String closedAt = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsNextDay(cal) && r.containsMonth(cal)) { if (r.containsNextDay(cal) && r.containsMonth(cal)) {
closedAt = r.getClosedAtStr(cal, true, nearToClosing); closedAt = r.getClosedAtTime(cal, true, nearToClosing);
} }
} }
return closedAt; return closedAt;
@ -422,11 +422,11 @@ public class OpeningHoursParser {
public String toLocalRuleString(); public String toLocalRuleString();
boolean isOpen24_7(); boolean isOpened24_7();
String getOpenedFromStr(Calendar cal, boolean checkPrevious); String getOpenedFromTime(Calendar cal, boolean checkPrevious);
String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing); String getClosedAtTime(Calendar cal, boolean checkNext, boolean nearToClosing);
} }
/** /**
@ -779,7 +779,7 @@ public class OpeningHoursParser {
if (startTimes == null || startTimes.size() == 0) { if (startTimes == null || startTimes.size() == 0) {
b.append("off"); b.append("off");
} else { } else {
if (isOpen24_7()) { if (isOpened24_7()) {
return "24/7"; return "24/7";
} }
for (int i = 0; i < startTimes.size(); i++) { for (int i = 0; i < startTimes.size(); i++) {
@ -835,16 +835,16 @@ public class OpeningHoursParser {
} }
@Override @Override
public boolean isOpen24_7() { public boolean isOpened24_7() {
boolean open24_7 = true; boolean opened24_7 = true;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
if (!days[i]) { if (!days[i]) {
open24_7 = false; opened24_7 = false;
break; break;
} }
} }
if (open24_7 && startTimes != null && startTimes.size() > 0) { if (opened24_7 && startTimes != null && startTimes.size() > 0) {
for (int i = 0; i < startTimes.size(); i++) { for (int i = 0; i < startTimes.size(); i++) {
int startTime = startTimes.get(i); int startTime = startTimes.get(i);
int endTime = endTimes.get(i); int endTime = endTimes.get(i);
@ -857,7 +857,7 @@ public class OpeningHoursParser {
} }
@Override @Override
public String getOpenedFromStr(Calendar cal, boolean checkPrevious) { public String getOpenedFromTime(Calendar cal, boolean checkPrevious) {
int limit = 300; int limit = 300;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int d = getCurrentDay(cal); int d = getCurrentDay(cal);
@ -889,7 +889,7 @@ public class OpeningHoursParser {
} }
@Override @Override
public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) { public String getClosedAtTime(Calendar cal, boolean checkNext, boolean nearToClosing) {
int nearToClosingLimit = 120; int nearToClosingLimit = 120;
int freeLimit = 300; int freeLimit = 300;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -1118,17 +1118,17 @@ public class OpeningHoursParser {
} }
@Override @Override
public boolean isOpen24_7() { public boolean isOpened24_7() {
return false; return false;
} }
@Override @Override
public String getOpenedFromStr(Calendar cal, boolean checkPrevious) { public String getOpenedFromTime(Calendar cal, boolean checkPrevious) {
return ""; return "";
} }
@Override @Override
public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) { public String getClosedAtTime(Calendar cal, boolean checkNext, boolean nearToClosing) {
return ""; return "";
} }

View file

@ -1105,17 +1105,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
View openingHoursView = view.findViewById(R.id.opening_hours_view); View openingHoursView = view.findViewById(R.id.opening_hours_view);
TextView openingHoursTextView = (TextView) view.findViewById(R.id.opening_hours_text_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)); OpeningHoursInfo openingHoursInfo = menu.getOpeningHoursInfo();
String openingHoursStr = ""; if (openingHoursInfo != null) {
if (menu.isOpened()) { openingHoursTextView.setTextColor(ContextCompat.getColor(getContext(), openingHoursInfo.isOpened() ? R.color.ctx_menu_amenity_opened_text_color : R.color.ctx_menu_amenity_closed_text_color));
if (menu.isOpen24_7()) { String openingHoursStr = "";
if (openingHoursInfo.isOpened24_7()) {
openingHoursStr = getString(R.string.shared_string_is_open_24_7); openingHoursStr = getString(R.string.shared_string_is_open_24_7);
} else if (!Algorithms.isEmpty(menu.getOpenFromStr())) { } else if (!Algorithms.isEmpty(openingHoursInfo.getOpenedFromTime())) {
openingHoursStr = getString(R.string.opened_from) + " " + menu.getOpenFromStr(); openingHoursStr = getString(R.string.opened_from) + " " + openingHoursInfo.getOpenedFromTime();
} else if (!Algorithms.isEmpty(menu.getClosedAtStr())) { } else if (!Algorithms.isEmpty(openingHoursInfo.getClosedAtTime())) {
openingHoursStr = getString(R.string.will_be_closed_at) + " " + menu.getClosedAtStr(); openingHoursStr = getString(R.string.will_be_closed_at) + " " + openingHoursInfo.getClosedAtTime();
} else if (!Algorithms.isEmpty(menu.getOpenedTillStr())) { } else if (!Algorithms.isEmpty(openingHoursInfo.getOpenedTillTime())) {
openingHoursStr = getString(R.string.opened_till) + " " + menu.getOpenedTillStr(); openingHoursStr = getString(R.string.opened_till) + " " + openingHoursInfo.getOpenedTillTime();
} }
openingHoursTextView.setText(openingHoursStr); openingHoursTextView.setText(openingHoursStr);
openingHoursView.setVisibility(View.VISIBLE); openingHoursView.setVisibility(View.VISIBLE);

View file

@ -424,20 +424,8 @@ public abstract class MenuController extends BaseMenuController {
return ""; return "";
} }
public boolean isOpen24_7() { public OpeningHoursInfo getOpeningHoursInfo() {
return false; return null;
}
public String getOpenFromStr() {
return "";
}
public String getClosedAtStr() {
return "";
}
public String getOpenedTillStr() {
return "";
} }
public String getCommonTypeStr() { public String getCommonTypeStr() {

View file

@ -18,10 +18,7 @@ public abstract class MenuTitleController {
protected String commonTypeStr = ""; protected String commonTypeStr = "";
protected Drawable secondLineTypeIcon; protected Drawable secondLineTypeIcon;
protected String streetStr = ""; protected String streetStr = "";
protected boolean open24_7; protected OpeningHoursInfo openingHoursInfo;
protected String openFromStr = "";
protected String closedAtStr = "";
protected String openedTillStr = "";
private AddressLookupRequest addressLookupRequest; private AddressLookupRequest addressLookupRequest;
@ -102,28 +99,8 @@ public abstract class MenuTitleController {
} }
} }
public boolean isOpen24_7() { public OpeningHoursInfo getOpeningHoursInfo() {
return open24_7; return openingHoursInfo;
}
public String getOpenFromStr() {
return openFromStr;
}
public String getClosedAtStr() {
return closedAtStr;
}
public String getOpenedTillStr() {
return openedTillStr;
}
public boolean isOpened() {
if (isOpen24_7() || !Algorithms.isEmpty(getOpenFromStr()) || !Algorithms.isEmpty(getClosedAtStr()) || !Algorithms.isEmpty(getOpenedTillStr())) {
return true;
} else {
return false;
}
} }
protected void initTitle() { protected void initTitle() {
@ -140,7 +117,7 @@ public abstract class MenuTitleController {
acquireStreetName(); acquireStreetName();
} }
acquireOpeningHoursData(); acquireOpeningHoursInfo();
} }
protected boolean needStreetName() { protected boolean needStreetName() {
@ -216,13 +193,10 @@ public abstract class MenuTitleController {
getMapActivity().getMyApplication().getGeocodingLookupService().lookupAddress(addressLookupRequest); getMapActivity().getMyApplication().getGeocodingLookupService().lookupAddress(addressLookupRequest);
} }
protected void acquireOpeningHoursData() { protected void acquireOpeningHoursInfo() {
MenuController menuController = getMenuController(); MenuController menuController = getMenuController();
if (menuController != null) { if (menuController != null) {
open24_7 = menuController.isOpen24_7(); openingHoursInfo = menuController.getOpeningHoursInfo();
openFromStr = menuController.getOpenFromStr();
closedAtStr = menuController.getClosedAtStr();
openedTillStr = menuController.getOpenedTillStr();
} }
} }

View file

@ -0,0 +1,50 @@
package net.osmand.plus.mapcontextmenu;
public class OpeningHoursInfo {
private boolean opened;
private boolean opened24_7;
private String openedFromTime = "";
private String closedAtTime = "";
private String openedTillTime = "";
public boolean isOpened() {
return opened;
}
public void setOpened(boolean opened) {
this.opened = opened;
}
public boolean isOpened24_7() {
return opened24_7;
}
public void setOpened24_7(boolean opened24_7) {
this.opened24_7 = opened24_7;
}
public String getOpenedFromTime() {
return openedFromTime;
}
public void setOpenedFromTime(String openFromTime) {
this.openedFromTime = openFromTime;
}
public String getClosedAtTime() {
return closedAtTime;
}
public void setClosedAtTime(String closedAtTime) {
this.closedAtTime = closedAtTime;
}
public String getOpenedTillTime() {
return openedTillTime;
}
public void setOpenedTillTime(String openedTillTime) {
this.openedTillTime = openedTillTime;
}
}

View file

@ -16,6 +16,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.OpeningHoursInfo;
import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder; import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
@ -119,23 +120,8 @@ public class AmenityMenuController extends MenuController {
} }
@Override @Override
public boolean isOpen24_7() { public OpeningHoursInfo getOpeningHoursInfo() {
return isOpen24_7(amenity); return getOpeningHoursInfo(amenity);
}
@Override
public String getOpenFromStr() {
return getOpenFromStr(amenity);
}
@Override
public String getClosedAtStr() {
return getClosedAtStr(amenity);
}
@Override
public String getOpenedTillStr() {
return getOpenedTillStr(amenity);
} }
public static String getTypeStr(Amenity amenity) { public static String getTypeStr(Amenity amenity) {
@ -150,50 +136,22 @@ public class AmenityMenuController extends MenuController {
return typeStr; return typeStr;
} }
public static boolean isOpen24_7(Amenity amenity) { public static OpeningHoursInfo getOpeningHoursInfo(Amenity amenity) {
boolean isOpen24_7 = false;
OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours()); OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (openingHours == null) { if (openingHours == null) {
isOpen24_7 = false; return null;
} else { } else {
Calendar calendar = Calendar.getInstance(); OpeningHoursInfo info = new OpeningHoursInfo();
if (openingHours.isOpenedForTime(calendar)) { Calendar cal = Calendar.getInstance();
if (openingHours.isOpen24_7()) { if (openingHours.isOpenedForTime(cal)) {
isOpen24_7 = true; info.setOpened(true);
} info.setOpened24_7(openingHours.isOpen24_7());
// info.setOpenedFromTime(openingHours.getOpenedFromTime(cal));
info.setOpenedFromTime("");
info.setClosedAtTime(openingHours.getClosedAtTime(cal));
info.setOpenedTillTime(openingHours.getOpenedTillTime(cal));
} }
} return info;
return isOpen24_7;
}
public static String getOpenFromStr(Amenity amenity) {
return "";
// OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
// if (openingHours == null) {
// return "";
// } else {
// Calendar cal = Calendar.getInstance();
// return openingHours.getOpenFromStr(cal);
// }
}
public static String getClosedAtStr(Amenity amenity) {
OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (openingHours == null) {
return "";
} else {
Calendar cal = Calendar.getInstance();
return openingHours.getClosedAtStr(cal);
}
}
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);
} }
} }