Refactor
This commit is contained in:
parent
1b35b82db0
commit
b29871e263
6 changed files with 116 additions and 145 deletions
|
@ -189,70 +189,70 @@ public class OpeningHoursParser {
|
|||
public boolean isOpen24_7() {
|
||||
boolean open24_7 = false;
|
||||
for (OpeningHoursRule r : rules) {
|
||||
open24_7 = r.isOpen24_7();
|
||||
open24_7 = r.isOpened24_7();
|
||||
}
|
||||
return open24_7;
|
||||
}
|
||||
|
||||
public String getOpenFromStr(Calendar cal) {
|
||||
String openFrom = getOpenFromDayStr(cal);
|
||||
public String getOpenedFromTime(Calendar cal) {
|
||||
String openFrom = getOpenFromTimeDay(cal);
|
||||
if (Algorithms.isEmpty(openFrom)) {
|
||||
openFrom = getOpenFromPreviousStr(cal);
|
||||
openFrom = getOpenFromTimePrevious(cal);
|
||||
}
|
||||
return openFrom;
|
||||
}
|
||||
|
||||
private String getOpenFromDayStr(Calendar cal) {
|
||||
private String getOpenFromTimeDay(Calendar cal) {
|
||||
String openFrom = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
||||
openFrom = r.getOpenedFromStr(cal, false);
|
||||
openFrom = r.getOpenedFromTime(cal, false);
|
||||
}
|
||||
}
|
||||
return openFrom;
|
||||
}
|
||||
|
||||
private String getOpenFromPreviousStr(Calendar cal) {
|
||||
private String getOpenFromTimePrevious(Calendar cal) {
|
||||
String openFrom = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
if (r.containsPreviousDay(cal) && r.containsMonth(cal)) {
|
||||
openFrom = r.getOpenedFromStr(cal, true);
|
||||
openFrom = r.getOpenedFromTime(cal, true);
|
||||
}
|
||||
}
|
||||
return openFrom;
|
||||
}
|
||||
|
||||
public String getClosedAtStr(Calendar cal) {
|
||||
return getClosedStr(cal, true);
|
||||
public String getClosedAtTime(Calendar cal) {
|
||||
return getClosedTime(cal, true);
|
||||
}
|
||||
|
||||
public String getOpenedTillStr(Calendar cal) {
|
||||
return getClosedStr(cal, false);
|
||||
public String getOpenedTillTime(Calendar cal) {
|
||||
return getClosedTime(cal, false);
|
||||
}
|
||||
|
||||
public String getClosedStr(Calendar cal, boolean nearToClosing) {
|
||||
String closedAt = getClosedAtDayStr(cal, nearToClosing);
|
||||
private String getClosedTime(Calendar cal, boolean nearToClosing) {
|
||||
String closedAt = getClosedAtTimeDay(cal, nearToClosing);
|
||||
if (Algorithms.isEmpty(closedAt)) {
|
||||
closedAt = getClosedAtNextDayStr(cal, nearToClosing);
|
||||
closedAt = getClosedAtTimeNextDay(cal, nearToClosing);
|
||||
}
|
||||
return closedAt;
|
||||
}
|
||||
|
||||
private String getClosedAtDayStr(Calendar cal, boolean nearToClosing) {
|
||||
private String getClosedAtTimeDay(Calendar cal, boolean nearToClosing) {
|
||||
String closedAt = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
if (r.containsDay(cal) && r.containsMonth(cal)) {
|
||||
closedAt = r.getClosedAtStr(cal, false, nearToClosing);
|
||||
closedAt = r.getClosedAtTime(cal, false, nearToClosing);
|
||||
}
|
||||
}
|
||||
return closedAt;
|
||||
}
|
||||
|
||||
private String getClosedAtNextDayStr(Calendar cal, boolean nearToClosing) {
|
||||
private String getClosedAtTimeNextDay(Calendar cal, boolean nearToClosing) {
|
||||
String closedAt = "";
|
||||
for (OpeningHoursRule r : rules) {
|
||||
if (r.containsNextDay(cal) && r.containsMonth(cal)) {
|
||||
closedAt = r.getClosedAtStr(cal, true, nearToClosing);
|
||||
closedAt = r.getClosedAtTime(cal, true, nearToClosing);
|
||||
}
|
||||
}
|
||||
return closedAt;
|
||||
|
@ -422,11 +422,11 @@ public class OpeningHoursParser {
|
|||
|
||||
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) {
|
||||
b.append("off");
|
||||
} else {
|
||||
if (isOpen24_7()) {
|
||||
if (isOpened24_7()) {
|
||||
return "24/7";
|
||||
}
|
||||
for (int i = 0; i < startTimes.size(); i++) {
|
||||
|
@ -835,16 +835,16 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen24_7() {
|
||||
boolean open24_7 = true;
|
||||
public boolean isOpened24_7() {
|
||||
boolean opened24_7 = true;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (!days[i]) {
|
||||
open24_7 = false;
|
||||
opened24_7 = false;
|
||||
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++) {
|
||||
int startTime = startTimes.get(i);
|
||||
int endTime = endTimes.get(i);
|
||||
|
@ -857,7 +857,7 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getOpenedFromStr(Calendar cal, boolean checkPrevious) {
|
||||
public String getOpenedFromTime(Calendar cal, boolean checkPrevious) {
|
||||
int limit = 300;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int d = getCurrentDay(cal);
|
||||
|
@ -889,7 +889,7 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) {
|
||||
public String getClosedAtTime(Calendar cal, boolean checkNext, boolean nearToClosing) {
|
||||
int nearToClosingLimit = 120;
|
||||
int freeLimit = 300;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -1118,17 +1118,17 @@ public class OpeningHoursParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen24_7() {
|
||||
public boolean isOpened24_7() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpenedFromStr(Calendar cal, boolean checkPrevious) {
|
||||
public String getOpenedFromTime(Calendar cal, boolean checkPrevious) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClosedAtStr(Calendar cal, boolean checkNext, boolean nearToClosing) {
|
||||
public String getClosedAtTime(Calendar cal, boolean checkNext, boolean nearToClosing) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
@ -1105,17 +1105,18 @@ 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));
|
||||
String openingHoursStr = "";
|
||||
if (menu.isOpened()) {
|
||||
if (menu.isOpen24_7()) {
|
||||
OpeningHoursInfo openingHoursInfo = menu.getOpeningHoursInfo();
|
||||
if (openingHoursInfo != null) {
|
||||
openingHoursTextView.setTextColor(ContextCompat.getColor(getContext(), openingHoursInfo.isOpened() ? R.color.ctx_menu_amenity_opened_text_color : R.color.ctx_menu_amenity_closed_text_color));
|
||||
String openingHoursStr = "";
|
||||
if (openingHoursInfo.isOpened24_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();
|
||||
} 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();
|
||||
} else if (!Algorithms.isEmpty(openingHoursInfo.getOpenedFromTime())) {
|
||||
openingHoursStr = getString(R.string.opened_from) + " " + openingHoursInfo.getOpenedFromTime();
|
||||
} else if (!Algorithms.isEmpty(openingHoursInfo.getClosedAtTime())) {
|
||||
openingHoursStr = getString(R.string.will_be_closed_at) + " " + openingHoursInfo.getClosedAtTime();
|
||||
} else if (!Algorithms.isEmpty(openingHoursInfo.getOpenedTillTime())) {
|
||||
openingHoursStr = getString(R.string.opened_till) + " " + openingHoursInfo.getOpenedTillTime();
|
||||
}
|
||||
openingHoursTextView.setText(openingHoursStr);
|
||||
openingHoursView.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -424,20 +424,8 @@ public abstract class MenuController extends BaseMenuController {
|
|||
return "";
|
||||
}
|
||||
|
||||
public boolean isOpen24_7() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getOpenFromStr() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getClosedAtStr() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getOpenedTillStr() {
|
||||
return "";
|
||||
public OpeningHoursInfo getOpeningHoursInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getCommonTypeStr() {
|
||||
|
|
|
@ -18,10 +18,7 @@ public abstract class MenuTitleController {
|
|||
protected String commonTypeStr = "";
|
||||
protected Drawable secondLineTypeIcon;
|
||||
protected String streetStr = "";
|
||||
protected boolean open24_7;
|
||||
protected String openFromStr = "";
|
||||
protected String closedAtStr = "";
|
||||
protected String openedTillStr = "";
|
||||
protected OpeningHoursInfo openingHoursInfo;
|
||||
|
||||
private AddressLookupRequest addressLookupRequest;
|
||||
|
||||
|
@ -102,28 +99,8 @@ public abstract class MenuTitleController {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isOpen24_7() {
|
||||
return open24_7;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
public OpeningHoursInfo getOpeningHoursInfo() {
|
||||
return openingHoursInfo;
|
||||
}
|
||||
|
||||
protected void initTitle() {
|
||||
|
@ -140,7 +117,7 @@ public abstract class MenuTitleController {
|
|||
acquireStreetName();
|
||||
}
|
||||
|
||||
acquireOpeningHoursData();
|
||||
acquireOpeningHoursInfo();
|
||||
}
|
||||
|
||||
protected boolean needStreetName() {
|
||||
|
@ -216,13 +193,10 @@ public abstract class MenuTitleController {
|
|||
getMapActivity().getMyApplication().getGeocodingLookupService().lookupAddress(addressLookupRequest);
|
||||
}
|
||||
|
||||
protected void acquireOpeningHoursData() {
|
||||
protected void acquireOpeningHoursInfo() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
open24_7 = menuController.isOpen24_7();
|
||||
openFromStr = menuController.getOpenFromStr();
|
||||
closedAtStr = menuController.getClosedAtStr();
|
||||
openedTillStr = menuController.getOpenedTillStr();
|
||||
openingHoursInfo = menuController.getOpeningHoursInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapcontextmenu.OpeningHoursInfo;
|
||||
import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
|
@ -119,23 +120,8 @@ public class AmenityMenuController extends MenuController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen24_7() {
|
||||
return isOpen24_7(amenity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpenFromStr() {
|
||||
return getOpenFromStr(amenity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClosedAtStr() {
|
||||
return getClosedAtStr(amenity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpenedTillStr() {
|
||||
return getOpenedTillStr(amenity);
|
||||
public OpeningHoursInfo getOpeningHoursInfo() {
|
||||
return getOpeningHoursInfo(amenity);
|
||||
}
|
||||
|
||||
public static String getTypeStr(Amenity amenity) {
|
||||
|
@ -150,50 +136,22 @@ public class AmenityMenuController extends MenuController {
|
|||
return typeStr;
|
||||
}
|
||||
|
||||
public static boolean isOpen24_7(Amenity amenity) {
|
||||
boolean isOpen24_7 = false;
|
||||
public static OpeningHoursInfo getOpeningHoursInfo(Amenity amenity) {
|
||||
OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
|
||||
if (openingHours == null) {
|
||||
isOpen24_7 = false;
|
||||
return null;
|
||||
} else {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if (openingHours.isOpenedForTime(calendar)) {
|
||||
if (openingHours.isOpen24_7()) {
|
||||
isOpen24_7 = true;
|
||||
}
|
||||
OpeningHoursInfo info = new OpeningHoursInfo();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
if (openingHours.isOpenedForTime(cal)) {
|
||||
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 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);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue