Merge branch 'r3.9'

This commit is contained in:
Vitaliy 2021-02-03 12:44:33 +02:00
commit b770a61c31
5 changed files with 55 additions and 32 deletions

View file

@ -344,8 +344,8 @@ public class OsmAndFormatter {
if (minperkm >= 10) { if (minperkm >= 10) {
return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx); return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx);
} else { } else {
int mph10 = (int) Math.round(minperkm * 10f); int seconds = Math.round(minperkm * 60);
return (mph10 / 10f) + " " + mc.toShortString(ctx); return Algorithms.formatDuration(seconds, false) + " " + mc.toShortString(ctx);
} }
} else if (mc == SpeedConstants.MINUTES_PER_MILE) { } else if (mc == SpeedConstants.MINUTES_PER_MILE) {
if (metersperseconds < 0.111111111) { if (metersperseconds < 0.111111111) {

View file

@ -10,6 +10,7 @@ import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -88,6 +89,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
public static final int IMPORT_FAVOURITES_ID = 7; public static final int IMPORT_FAVOURITES_ID = 7;
public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded"; public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded";
private static final int MAX_POINTS_IN_DESCRIPTION = 100;
private FavouritesAdapter favouritesAdapter; private FavouritesAdapter favouritesAdapter;
private FavouritesDbHelper helper; private FavouritesDbHelper helper;
@ -606,29 +609,39 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
} }
} }
private StringBuilder generateHtmlPrint(List<FavoriteGroup> groups) { private String generateHtmlPrint(List<FavoriteGroup> groups) {
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
html.append("<h1>My Favorites</h1>"); html.append("<h1>My Favorites</h1>");
int addedPoints = 0;
for (FavoriteGroup group : groups) { for (FavoriteGroup group : groups) {
html.append("<h3>" + group.getDisplayName(app) + "</h3>"); html.append("<h3>").append(group.getDisplayName(app)).append("</h3>");
for (FavouritePoint fp : group.getPoints()) { for (FavouritePoint fp : group.getPoints()) {
String url = "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "?m=" + fp.getName(); if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
html.append("<p>" + fp.getDisplayName(app) + " - " + "<a href=\"" + url + "\">geo:" break;
+ ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "</a><br>");
if (fp.isAddressSpecified()) {
html.append(": " + fp.getAddress());
html.append("<br>");
} }
if (!Algorithms.isEmpty(fp.getDescription())) {
html.append(": " + fp.getDescription()); float lat = (float) fp.getLatitude();
} float lon = (float) fp.getLongitude();
html.append("</p>"); String url = "geo:" + lat + "," + lon + "?m=" + fp.getName();
html.append("<p>")
.append(fp.getDisplayName(app))
.append(" - <a href=\"")
.append(url)
.append("\">geo:")
.append(lat).append(",").append(lon)
.append("</a><br></p>");
addedPoints++;
}
if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
html.append("<p>...</p>");
break;
} }
} }
return html; return html.toString();
} }
private void shareFavourites() { private void shareFavourites() {
if (favouritesAdapter.isEmpty()) { if (favouritesAdapter.isEmpty()) {
Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show();
@ -646,6 +659,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
File src = null; File src = null;
File dst = null; File dst = null;
Spanned descriptionOfPoints;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -662,9 +676,15 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
List<FavoriteGroup> groups;
if (group != null) { if (group != null) {
helper.saveFile(group.getPoints(), dst); helper.saveFile(group.getPoints(), dst);
groups = new ArrayList<>();
groups.add(group);
} else {
groups = getMyApplication().getFavorites().getFavoriteGroups();
} }
descriptionOfPoints = Html.fromHtml(generateHtmlPrint(groups));
return null; return null;
} }
@ -680,19 +700,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
Algorithms.fileCopy(src, dst); Algorithms.fileCopy(src, dst);
} }
final Intent sendIntent = new Intent(); final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setAction(Intent.ACTION_SEND)
List<FavoriteGroup> groups; .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject))
if (group != null) { .putExtra(Intent.EXTRA_TEXT, descriptionOfPoints)
groups = new ArrayList<>(); .putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst))
groups.add(group); .setType("text/plain")
} else { .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
groups = getMyApplication().getFavorites().getFavoriteGroups();
}
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst));
sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} catch (IOException e) { } catch (IOException e) {
Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show();

View file

@ -124,7 +124,7 @@ public class ProfileSettingsItem extends OsmandSettingsItem {
if (Algorithms.isEmpty(modeBean.userProfileName)) { if (Algorithms.isEmpty(modeBean.userProfileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (appMode != null) { if (appMode != null) {
modeBean.userProfileName = app.getString(appMode.getNameKeyResource()); modeBean.userProfileName = appMode.toHumanString();
} }
} }
int number = 0; int number = 0;

View file

@ -34,6 +34,7 @@ import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -91,7 +92,11 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
String profileName = modeBean.userProfileName; String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) { if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
profileName = app.getString(appMode.getNameKeyResource()); if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = StringUtils.capitalize(modeBean.stringKey);
}
} }
itemHolder.title.setText(profileName); itemHolder.title.setText(profileName);
String routingProfile = ""; String routingProfile = "";

View file

@ -62,6 +62,7 @@ import net.osmand.util.Algorithms;
import net.osmand.view.ThreeStateCheckbox; import net.osmand.view.ThreeStateCheckbox;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -279,7 +280,11 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
String profileName = modeBean.userProfileName; String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) { if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
profileName = appMode.toHumanString(); if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = StringUtils.capitalize(modeBean.stringKey);
}
} }
builder.setTitle(profileName); builder.setTitle(profileName);