Fix several possible npe

This commit is contained in:
Vitaliy 2020-02-26 17:04:31 +02:00
parent c3cbbe799a
commit 09f735eec9
5 changed files with 44 additions and 27 deletions

View file

@ -550,7 +550,11 @@ public class TileSourceManager {
private static String findOneTile(File dir) {
if (dir.isDirectory()) {
for (File file : dir.listFiles()) {
File[] files = dir.listFiles();
if (files == null) {
return null;
}
for (File file : files) {
if (file.isDirectory()) {
String ext = findOneTile(file);
if (ext != null) {

View file

@ -16,6 +16,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
@ -94,8 +95,11 @@ public class DashFavoritesFragment extends DashLocationFragment {
public void setupFavorites() {
View mainView = getView();
final FavouritesDbHelper helper = getMyApplication().getFavorites();
points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
OsmandApplication app = getMyApplication();
if (mainView == null || app == null) {
return;
}
points = new ArrayList<FavouritePoint>(app.getFavorites().getFavouritePoints());
if (points.size() == 0) {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;

View file

@ -71,11 +71,9 @@ import org.apache.commons.logging.Log;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -833,7 +831,9 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
FragmentActivity activity = getActivity();
if (activity != null && regionCenter != null) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
app.getSettings().setMapLocationToShow(
regionCenter.getLatitude(),
regionCenter.getLongitude(),
@ -841,7 +841,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION_SHOW_ON_MAP, ""));
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
MapActivity.launchMapActivityMoveToTop(activity);
}
}
});

View file

@ -1,12 +1,13 @@
package net.osmand.plus.measurementtool;
import android.support.annotation.Nullable;
import android.util.Pair;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.measurementtool.command.MeasurementCommandManager;
import net.osmand.plus.routing.RouteCalculationParams;
@ -212,8 +213,10 @@ public class MeasurementEditingContext {
snapToRoadPairsToCalculate.clear();
findPointsToCalculate(Arrays.asList(before.points, after.points));
RoutingHelper routingHelper = application.getRoutingHelper();
if (!snapToRoadPairsToCalculate.isEmpty() && progressListener != null && !routingHelper.isRouteBeingCalculated()) {
routingHelper.startRouteCalculationThread(getParams(), true, true);
if (progressListener != null && !routingHelper.isRouteBeingCalculated()) {
RouteCalculationParams params = getParams();
if (params != null) {
routingHelper.startRouteCalculationThread(params, true, true);
application.runInUIThread(new Runnable() {
@Override
public void run() {
@ -222,6 +225,7 @@ public class MeasurementEditingContext {
});
}
}
}
private void findPointsToCalculate(List<List<WptPt>> pointsList) {
for (List<WptPt> points : pointsList) {
@ -270,9 +274,12 @@ public class MeasurementEditingContext {
}
}
@Nullable
private RouteCalculationParams getParams() {
final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
if (currentPair == null) {
return null;
}
Location start = new Location("");
start.setLatitude(currentPair.first.getLatitude());
start.setLongitude(currentPair.first.getLongitude());
@ -341,8 +348,9 @@ public class MeasurementEditingContext {
progressListener.refresh();
}
});
if (!snapToRoadPairsToCalculate.isEmpty()) {
application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
RouteCalculationParams params = getParams();
if (params != null) {
application.getRoutingHelper().startRouteCalculationThread(params, true, true);
} else {
application.runInUIThread(new Runnable() {
@Override

View file

@ -454,7 +454,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
}
protected void reloadData() {
new ReloadData(activity, getMyApplication()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
new ReloadData(activity, app).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
@Override