Proper fix of NPE

This commit is contained in:
Victor Shcherb 2015-01-08 11:46:47 +01:00
parent c50a5764c3
commit fa172a8899
6 changed files with 27 additions and 52 deletions

View file

@ -14,7 +14,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.dashboard.DashAudioVideoNotesFragment;
import net.osmand.plus.dashboard.DashDownloadMapsFragment;
import net.osmand.plus.dashboard.DashErrorFragment;
import net.osmand.plus.dashboard.DashFavoritesFragment;
@ -72,7 +71,6 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
private static final int HELP_ID = 0;
private static final int SETTINGS_ID = 1;
private static final int EXIT_ID = 2;
private OsmAndLocationProvider lp;
@Override
@ -101,7 +99,6 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
return;
}
setContentView(R.layout.dashboard);
lp = getMyApplication().getLocationProvider();
String textVersion = Version.getFullVersion(getMyApplication());
if (textVersion.indexOf("#") != -1) {
@ -494,12 +491,8 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
if (f instanceof DashDownloadMapsFragment && !f.isDetached()) {
((DashDownloadMapsFragment) f).refreshData();
}
if (f instanceof DashAudioVideoNotesFragment && !f.isDetached()) {
((DashAudioVideoNotesFragment) f).setupNotes();
}
//Needed to reliably initialize DashFavoritesFragement on devices without compass
// [Victor]: This doesn't look as a proper place, then it highly depends on internet connection and download list
if (f instanceof DashFavoritesFragment && !f.isDetached()) {
((DashFavoritesFragment) f).setupFavorites();
}

View file

@ -67,10 +67,6 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
public void setupNotes() {
View mainView = getView();
if (mainView == null) {
return;
}
if (plugin == null){
mainView.setVisibility(View.GONE);
return;

View file

@ -1,15 +1,31 @@
package net.osmand.plus.dashboard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.views.DirectionDrawable;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -18,22 +34,6 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.*;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchPOIActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.views.DirectionDrawable;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by Denis on 24.11.2014.
@ -172,7 +172,7 @@ public class DashFavoritesFragment extends DashBaseFragment {
return;
}
for(int i =0; i<arrows.size(); i++){
for (int i = 0; i < arrows.size(); i++) {
arrows.get(i).setVisibility(View.VISIBLE);
updateArrow(points.get(i), arrows.get(i));
}
@ -247,12 +247,7 @@ public class DashFavoritesFragment extends DashBaseFragment {
} else {
loc = new LatLon(0f, 0f);
}
this.loc = loc;
updateArrows();
}
private OsmAndLocationProvider getLocationProvider() {
return getMyApplication().getLocationProvider();
}
}

View file

@ -72,6 +72,12 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
super.onResume();
downloadListIndexThread.setUiActivity(this);
}
@Override
protected void onPause() {
super.onPause();
downloadListIndexThread.setUiActivity(null);
}
public void updateDownloadList(List<IndexItem> list) {

View file

@ -61,12 +61,6 @@ public class DownloadActivity extends BaseDownloadActivity {
public static final String SINGLE_TAB = "SINGLE_TAB";
@Override
protected void onDestroy() {
super.onDestroy();
BaseDownloadActivity.downloadListIndexThread.resetUiActivity(DownloadActivity.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);

View file

@ -121,15 +121,6 @@ public class DownloadIndexesThread {
public List<IndexItem> getItemsToUpdate() { return itemsToUpdate;}
public void resetUiActivity(Class<?> downloadActivityClass) {
if (uiActivity== null){
return;
}
if (uiActivity.getClass().equals(downloadActivityClass)){
uiActivity = null;
}
}
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {