Merge branch 'master' into remove_waypoint

This commit is contained in:
Dmitriy Ruban 2020-07-02 18:08:31 +03:00 committed by GitHub
commit 806a7cf4f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 32 deletions

View file

@ -12,6 +12,7 @@
-->
<string name="quick_action_remove_next_destination_descr">The current destination point on the route will be deleted. If it will be the Destination, navigation will stop.</string>
<string name="please_provide_point_name_error">Please provide a name for the point</string>
<string name="use_volume_buttons_as_zoom">Volume buttons as zoom</string>
<string name="use_volume_buttons_as_zoom_descr">Enable to control the map zoom level with device volume buttons.</string>
<string name="quick_action_remove_next_destination">Delete next destination point</string>

View file

@ -559,27 +559,9 @@ public abstract class MenuController extends BaseMenuController implements Colla
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (openingHoursInfo != null) {
StringBuilder sb = new StringBuilder();
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[] 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;
return getSpannableOpeningHours(openingHoursInfo, colorOpen, colorClosed);
} else if (shouldShowMapSize()) {
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;
}
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() {
return indexItem != null && !downloaded;
}

View file

@ -11,6 +11,8 @@ import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -163,7 +165,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
});
view.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View saveButton = view.findViewById(R.id.right_bottom_button);
final View saveButton = view.findViewById(R.id.right_bottom_button);
saveButton.setVisibility(View.VISIBLE);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -183,11 +185,32 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(nightMode, saveButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_save);
TextInputLayout nameCaption = (TextInputLayout) view.findViewById(R.id.name_caption);
final TextInputLayout nameCaption = (TextInputLayout) view.findViewById(R.id.name_caption);
nameCaption.setHint(getString(R.string.shared_string_name));
nameEdit = (EditText) view.findViewById(R.id.name_edit);
nameEdit.setText(getNameInitValue());
nameEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.toString().trim().isEmpty()) {
nameCaption.setError(app.getString(R.string.please_provide_point_name_error));
saveButton.setEnabled(false);
} else {
nameCaption.setError(null);
saveButton.setEnabled(true);
}
}
});
nameIcon = (ImageView) view.findViewById(R.id.name_icon);
TextView categoryEdit = view.findViewById(R.id.groupName);
if (categoryEdit != null) {

View file

@ -3,6 +3,7 @@ package net.osmand.plus.search;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,7 +14,9 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import net.osmand.AndroidUtils;
@ -26,6 +29,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
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.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchListItemType;
@ -402,19 +406,17 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
&& ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
Amenity amenity = (Amenity) listItem.getSearchResult().object;
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (rs != null) {
Calendar inst = Calendar.getInstance();
inst.setTimeInMillis(System.currentTimeMillis());
boolean worksNow = !amenity.isClosed() && rs.isOpenedForTime(inst);
inst.setTimeInMillis(System.currentTimeMillis() + 30 * 60 * 1000); // 30 minutes later
boolean worksLater = rs.isOpenedForTime(inst);
int colorId = worksNow ? worksLater ? R.color.color_ok : R.color.color_intermediate : R.color.color_warning;
if (rs != null && rs.getInfo() != null) {
int colorOpen = R.color.ctx_menu_amenity_opened_text_color;
int colorClosed = R.color.ctx_menu_amenity_closed_text_color;
SpannableString openHours = MenuController.getSpannableOpeningHours(
rs.getInfo(),
ContextCompat.getColor(app, colorOpen),
ContextCompat.getColor(app, colorClosed));
int colorId = rs.isOpenedForTime(Calendar.getInstance()) ? colorOpen : colorClosed;
timeLayout.setVisibility(View.VISIBLE);
timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_time_16, colorId));
timeText.setTextColor(app.getResources().getColor(colorId));
String rt = amenity.isClosed() ? app.getResources().getString(R.string.poi_operational_status_closed) : rs.getCurrentRuleTime(inst);
timeText.setText(rt == null ? "" : rt);
timeText.setText(openHours);
} else {
timeLayout.setVisibility(View.GONE);
}