diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java index 02e571f4b5..2146bfe0f8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java @@ -11,6 +11,7 @@ import net.osmand.binary.RouteDataBundle; import net.osmand.binary.StringBundle; import net.osmand.binary.StringBundleWriter; import net.osmand.binary.StringBundleXmlWriter; +import net.osmand.util.Algorithms; import org.xmlpull.v1.XmlSerializer; @@ -38,20 +39,22 @@ public class RouteExporter { RouteDataResources resources = new RouteDataResources(locations); final RouteDataBundle bundle = new RouteDataBundle(resources); - for (RouteSegmentResult sr : route) { - sr.collectTypes(resources); - } - for (RouteSegmentResult sr : route) { - sr.collectNames(resources); - } + if (!Algorithms.isEmpty(route)) { + for (RouteSegmentResult sr : route) { + sr.collectTypes(resources); + } + for (RouteSegmentResult sr : route) { + sr.collectNames(resources); + } - List routeItems = new ArrayList<>(); - for (RouteSegmentResult sr : route) { - RouteDataBundle itemBundle = new RouteDataBundle(resources); - sr.writeToBundle(itemBundle); - routeItems.add(itemBundle); + List routeItems = new ArrayList<>(); + for (RouteSegmentResult sr : route) { + RouteDataBundle itemBundle = new RouteDataBundle(resources); + sr.writeToBundle(itemBundle); + routeItems.add(itemBundle); + } + bundle.putBundleList("route", "segment", routeItems); } - bundle.putBundleList("route", "segment", routeItems); List typeList = new ArrayList<>(); Map rules = resources.getRules(); diff --git a/OsmAnd/res/layout/download_tiles.xml b/OsmAnd/res/layout/download_tiles.xml index 371f92e6e8..9dbec76cfd 100644 --- a/OsmAnd/res/layout/download_tiles.xml +++ b/OsmAnd/res/layout/download_tiles.xml @@ -25,6 +25,7 @@ android:id="@+id/ZoomToDownload" style="@style/Widget.Styled.Slider" android:layout_width="fill_parent" + android:stepSize="1" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding" diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java index 42ae7eaf64..6749b1e118 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java @@ -51,11 +51,12 @@ public class DownloadTilesDialog { public void openDialog(){ BaseMapLayer mainLayer = mapView.getMainLayer(); - if(!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()){ + if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) { Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show(); + return; } final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap(); - if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){ + if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) { Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show(); return; } @@ -66,29 +67,28 @@ public class DownloadTilesDialog { // calculate pixel rectangle AlertDialog.Builder builder = new AlertDialog.Builder(ctx); - LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.download_tiles, null); - - - - ((TextView)view.findViewById(R.id.MinZoom)).setText(zoom+""); //$NON-NLS-1$ - ((TextView)view.findViewById(R.id.MaxZoom)).setText(max+""); //$NON-NLS-1$ + + ((TextView) view.findViewById(R.id.MinZoom)).setText(String.valueOf(zoom)); + ((TextView) view.findViewById(R.id.MaxZoom)).setText(String.valueOf(max)); + final Slider slider = (Slider) view.findViewById(R.id.ZoomToDownload); - slider.setValueTo(max - zoom); - int progress = (max - zoom) / 2; - slider.setValue(progress); - final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription)); final String template = ctx.getString(R.string.tiles_to_download_estimated_size); - - + updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) slider.getValue()); - slider.addOnChangeListener(new Slider.OnChangeListener() { - @Override - public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { - updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value); - } - }); + if (max > zoom) { + slider.setValueTo(max - zoom); + int progress = (max - zoom) / 2; + slider.setValue(progress); + slider.addOnChangeListener(new Slider.OnChangeListener() { + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value); + } + }); + } builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener(){ @Override diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ImagesPagerAdapter.java b/OsmAnd/src/net/osmand/plus/download/ui/ImagesPagerAdapter.java index af3cea834c..18fe293f60 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ImagesPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ImagesPagerAdapter.java @@ -12,6 +12,7 @@ import com.squareup.picasso.Picasso; import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; +import net.osmand.util.Algorithms; import java.util.List; @@ -56,19 +57,24 @@ public class ImagesPagerAdapter extends PagerAdapter { imageView.setScaleType(ImageView.ScaleType.FIT_XY); final String imageUrl = imageUrls.get(position); - Picasso.get().load(imageUrl).into(imageView, new Callback() { - @Override - public void onSuccess() { - imageView.setVisibility(View.VISIBLE); - picassoUtils.setResultLoaded(imageUrl, true); - } + if (!Algorithms.isEmpty(imageUrl)) { + Picasso.get().load(imageUrl).into(imageView, new Callback() { + @Override + public void onSuccess() { + imageView.setVisibility(View.VISIBLE); + picassoUtils.setResultLoaded(imageUrl, true); + } + + @Override + public void onError(Exception e) { + imageView.setVisibility(View.INVISIBLE); + picassoUtils.setResultLoaded(imageUrl, false); + } + }); + } else { + imageView.setVisibility(View.INVISIBLE); + } - @Override - public void onError(Exception e) { - imageView.setVisibility(View.INVISIBLE); - picassoUtils.setResultLoaded(imageUrl, false); - } - }); return imageView; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 9534f06f1d..822b3cb170 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Bundle; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -167,8 +166,9 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override public void setCategory(String name, int color) { FavouritesDbHelper helper = getHelper(); - if (helper != null) { - FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(requireContext(), name)); + Context ctx = getContext(); + if (helper != null && ctx != null) { + FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(ctx, name)); this.group = group; super.setCategory(name, group != null ? group.getColor() : 0); } @@ -176,10 +176,13 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override protected String getLastUsedGroup() { - OsmandApplication app = requireMyApplication(); - String lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get(); - if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { - lastCategory = ""; + String lastCategory = ""; + OsmandApplication app = getMyApplication(); + if (app != null) { + lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get(); + if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { + lastCategory = ""; + } } return lastCategory; } @@ -325,11 +328,14 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { private void doEditFavorite(FavouritePoint favorite, String name, String category, String description, @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, FavouritesDbHelper helper) { - requireMyApplication().getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); - favorite.setColor(color); - favorite.setBackgroundType(backgroundType); - favorite.setIconId(iconId); - helper.editFavouriteName(favorite, name, category, description); + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); + favorite.setColor(color); + favorite.setBackgroundType(backgroundType); + favorite.setIconId(iconId); + helper.editFavouriteName(favorite, name, category, description); + } } private void doAddFavorite(String name, String category, String description, @ColorInt int color,