Merge pull request #9359 from osmandapp/opening_hours_in_search
Opening hours in search
This commit is contained in:
commit
408c3673a2
2 changed files with 37 additions and 30 deletions
|
@ -559,27 +559,9 @@ public abstract class MenuController extends BaseMenuController implements Colla
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
if (openingHoursInfo != null) {
|
if (openingHoursInfo != null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
int colorOpen = mapActivity.getResources().getColor(R.color.ctx_menu_amenity_opened_text_color);
|
int colorOpen = mapActivity.getResources().getColor(R.color.ctx_menu_amenity_opened_text_color);
|
||||||
int colorClosed = mapActivity.getResources().getColor(R.color.ctx_menu_amenity_closed_text_color);
|
int colorClosed = mapActivity.getResources().getColor(R.color.ctx_menu_amenity_closed_text_color);
|
||||||
int[] pos = new int[openingHoursInfo.size()];
|
return getSpannableOpeningHours(openingHoursInfo, colorOpen, colorClosed);
|
||||||
for (int i = 0; i < openingHoursInfo.size(); i++) {
|
|
||||||
OpeningHours.Info info = openingHoursInfo.get(i);
|
|
||||||
if (sb.length() > 0) {
|
|
||||||
sb.append("\n");
|
|
||||||
}
|
|
||||||
sb.append(info.getInfo());
|
|
||||||
pos[i] = sb.length();
|
|
||||||
}
|
|
||||||
SpannableString infoStr = new SpannableString(sb.toString());
|
|
||||||
int k = 0;
|
|
||||||
for (int i = 0; i < openingHoursInfo.size(); i++) {
|
|
||||||
OpeningHours.Info info = openingHoursInfo.get(i);
|
|
||||||
infoStr.setSpan(new ForegroundColorSpan(info.isOpened() ? colorOpen : colorClosed), k, pos[i], 0);
|
|
||||||
k = pos[i];
|
|
||||||
}
|
|
||||||
return infoStr;
|
|
||||||
|
|
||||||
} else if (shouldShowMapSize()) {
|
} else if (shouldShowMapSize()) {
|
||||||
return mapActivity.getString(R.string.file_size_in_mb, indexItem.getArchiveSizeMB());
|
return mapActivity.getString(R.string.file_size_in_mb, indexItem.getArchiveSizeMB());
|
||||||
}
|
}
|
||||||
|
@ -597,6 +579,29 @@ public abstract class MenuController extends BaseMenuController implements Colla
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SpannableString getSpannableOpeningHours(List<OpeningHours.Info> openingHoursInfo,
|
||||||
|
int colorOpen,
|
||||||
|
int colorClosed) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int[] pos = new int[openingHoursInfo.size()];
|
||||||
|
for (int i = 0; i < openingHoursInfo.size(); i++) {
|
||||||
|
OpeningHours.Info info = openingHoursInfo.get(i);
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
sb.append(info.getInfo());
|
||||||
|
pos[i] = sb.length();
|
||||||
|
}
|
||||||
|
SpannableString infoStr = new SpannableString(sb.toString());
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 0; i < openingHoursInfo.size(); i++) {
|
||||||
|
OpeningHours.Info info = openingHoursInfo.get(i);
|
||||||
|
infoStr.setSpan(new ForegroundColorSpan(info.isOpened() ? colorOpen : colorClosed), k, pos[i], 0);
|
||||||
|
k = pos[i];
|
||||||
|
}
|
||||||
|
return infoStr;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldShowMapSize() {
|
private boolean shouldShowMapSize() {
|
||||||
return indexItem != null && !downloaded;
|
return indexItem != null && !downloaded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.search;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.SpannableString;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -13,7 +14,9 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.appcompat.view.ContextThemeWrapper;
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -26,6 +29,7 @@ import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
||||||
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
import net.osmand.plus.search.listitems.QuickSearchHeaderListItem;
|
import net.osmand.plus.search.listitems.QuickSearchHeaderListItem;
|
||||||
import net.osmand.plus.search.listitems.QuickSearchListItem;
|
import net.osmand.plus.search.listitems.QuickSearchListItem;
|
||||||
import net.osmand.plus.search.listitems.QuickSearchListItemType;
|
import net.osmand.plus.search.listitems.QuickSearchListItemType;
|
||||||
|
@ -402,19 +406,17 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
|
||||||
&& ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
|
&& ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
|
||||||
Amenity amenity = (Amenity) listItem.getSearchResult().object;
|
Amenity amenity = (Amenity) listItem.getSearchResult().object;
|
||||||
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
|
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
|
||||||
if (rs != null) {
|
if (rs != null && rs.getInfo() != null) {
|
||||||
Calendar inst = Calendar.getInstance();
|
int colorOpen = R.color.ctx_menu_amenity_opened_text_color;
|
||||||
inst.setTimeInMillis(System.currentTimeMillis());
|
int colorClosed = R.color.ctx_menu_amenity_closed_text_color;
|
||||||
boolean worksNow = !amenity.isClosed() && rs.isOpenedForTime(inst);
|
SpannableString openHours = MenuController.getSpannableOpeningHours(
|
||||||
inst.setTimeInMillis(System.currentTimeMillis() + 30 * 60 * 1000); // 30 minutes later
|
rs.getInfo(),
|
||||||
boolean worksLater = rs.isOpenedForTime(inst);
|
ContextCompat.getColor(app, colorOpen),
|
||||||
int colorId = worksNow ? worksLater ? R.color.color_ok : R.color.color_intermediate : R.color.color_warning;
|
ContextCompat.getColor(app, colorClosed));
|
||||||
|
int colorId = rs.isOpenedForTime(Calendar.getInstance()) ? colorOpen : colorClosed;
|
||||||
timeLayout.setVisibility(View.VISIBLE);
|
timeLayout.setVisibility(View.VISIBLE);
|
||||||
timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_time_16, colorId));
|
timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_time_16, colorId));
|
||||||
timeText.setTextColor(app.getResources().getColor(colorId));
|
timeText.setText(openHours);
|
||||||
String rt = amenity.isClosed() ? app.getResources().getString(R.string.poi_operational_status_closed) : rs.getCurrentRuleTime(inst);
|
|
||||||
timeText.setText(rt == null ? "" : rt);
|
|
||||||
} else {
|
} else {
|
||||||
timeLayout.setVisibility(View.GONE);
|
timeLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue