Updated osmandSettings structure

This commit is contained in:
Denis 2014-08-11 19:03:19 +03:00
parent 2c12da8043
commit ca75574f57
5 changed files with 31 additions and 25 deletions

View file

@ -16,6 +16,7 @@ import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.api.SettingsAPIImpl;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity; import android.app.Activity;
@ -24,15 +25,14 @@ import android.view.Window;
public class OsmAndAppCustomization { public class OsmAndAppCustomization {
protected OsmandApplication app; protected OsmandApplication app;
protected OsmandSettings osmandSettings;
public void setup(OsmandApplication app) { public void setup(OsmandApplication app) {
this.app = app; this.app = app;
this.osmandSettings = new OsmandSettings(app, new net.osmand.plus.api.SettingsAPIImpl(app));
} }
public OsmandSettings createSettings(SettingsAPI api) { public OsmandSettings getOsmandSettings(){ return osmandSettings;}
return new OsmandSettings(app, api);
}
// Main menu // Main menu
public boolean checkExceptionsOnStart() { public boolean checkExceptionsOnStart() {
return true; return true;

View file

@ -24,12 +24,14 @@ import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.api.SettingsAPIImpl;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.sherpafy.SherpafyCustomization;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import net.osmand.plus.voice.CommandPlayerException; import net.osmand.plus.voice.CommandPlayerException;
import net.osmand.plus.voice.CommandPlayerFactory; import net.osmand.plus.voice.CommandPlayerFactory;
@ -126,9 +128,6 @@ public class OsmandApplication extends Application {
} }
super.onCreate(); super.onCreate();
new Toast(this); // activate in UI thread to avoid further exceptions new Toast(this); // activate in UI thread to avoid further exceptions
appCustomization = new OsmAndAppCustomization();
appCustomization.setup(this);
sqliteAPI = new SQLiteAPIImpl(this); sqliteAPI = new SQLiteAPIImpl(this);
try { try {
bRouterServiceConnection = BRouterServiceConnection.connect(this); bRouterServiceConnection = BRouterServiceConnection.connect(this);
@ -136,13 +135,21 @@ public class OsmandApplication extends Application {
e.printStackTrace(); e.printStackTrace();
} }
// settings used everywhere so they need to be created first if(Version.isSherpafy(this)) {
osmandSettings = appCustomization.createSettings(new net.osmand.plus.api.SettingsAPIImpl(this)); appCustomization = new SherpafyCustomization();
} else {
appCustomization = new OsmAndAppCustomization();
}
appCustomization.setup(this);
osmandSettings = appCustomization.getOsmandSettings();
// always update application mode to default // always update application mode to default
if(!osmandSettings.FOLLOW_THE_ROUTE.get()){ if(!osmandSettings.FOLLOW_THE_ROUTE.get()){
osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get()); osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get());
} }
applyTheme(this); applyTheme(this);
routingHelper = new RoutingHelper(this, player); routingHelper = new RoutingHelper(this, player);

View file

@ -197,7 +197,6 @@ public class MainMenuActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if(Version.isSherpafy(getMyApplication())) { if(Version.isSherpafy(getMyApplication())) {
final Intent mapIntent = new Intent(this, TourViewActivity.class); final Intent mapIntent = new Intent(this, TourViewActivity.class);
getMyApplication().setAppCustomization(new SherpafyCustomization());
startActivity(mapIntent); startActivity(mapIntent);
finish(); finish();
return; return;

View file

@ -11,18 +11,17 @@ import java.util.TreeSet;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LocationPoint;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.api.FileSettingsAPIImpl; import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import net.osmand.plus.sherpafy.TourInformation.StageInformation; import net.osmand.plus.sherpafy.TourInformation.StageInformation;
@ -38,7 +37,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private static final String SELECTED_TOUR = "selected_tour"; private static final String SELECTED_TOUR = "selected_tour";
private static final String ACCESS_CODE = "access_code"; private static final String ACCESS_CODE = "access_code";
private static final String SELECTED_STAGE = "selected_stage"; private static final String SELECTED_STAGE = "selected_stage";
private OsmandSettings originalSettings;
private CommonPreference<String> selectedTourPref; private CommonPreference<String> selectedTourPref;
private CommonPreference<String> selectedStagePref; private CommonPreference<String> selectedStagePref;
private List<TourInformation> tourPresent = new ArrayList<TourInformation>(); private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
@ -47,14 +46,15 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private File toursFolder; private File toursFolder;
private CommonPreference<String> accessCodePref; private CommonPreference<String> accessCodePref;
private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>(); private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>();
private SettingsAPI originalApi;
@Override @Override
public void setup(OsmandApplication app) { public void setup(OsmandApplication app) {
super.setup(app); super.setup(app);
originalSettings = createSettings(app.getSettings().getSettingsAPI()); originalApi = osmandSettings.getSettingsAPI();
selectedTourPref = originalSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal(); selectedTourPref = osmandSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal();
accessCodePref = originalSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal(); accessCodePref = osmandSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal();
toursFolder = new File(originalSettings.getExternalStorageDirectory(), "osmand/tours"); toursFolder = new File(osmandSettings.getExternalStorageDirectory(), "osmand/tours");
} }
public boolean setAccessCode(String acCode) { public boolean setAccessCode(String acCode) {
@ -162,7 +162,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} }
} }
if (selectedName == null) { if (selectedName == null) {
app.getSettings().setSettingsAPI(originalSettings.getSettingsAPI()); app.getSettings().setSettingsAPI(originalApi);
} }
} }
} }

View file

@ -67,9 +67,9 @@ public class TourViewActivity extends SherlockFragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { // if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
getMyApplication().setAppCustomization(new SherpafyCustomization()); // getMyApplication().setAppCustomization(new SherpafyCustomization());
} // }
customization = (SherpafyCustomization) getMyApplication().getAppCustomization(); customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
setTheme(R.style.OsmandLightTheme); setTheme(R.style.OsmandLightTheme);
((OsmandApplication) getApplication()).setLanguage(this); ((OsmandApplication) getApplication()).setLanguage(this);