put map style setting into data backup

This commit is contained in:
jannis 2019-09-10 20:01:14 +02:00
parent e2e0efea32
commit 99182791f9
5 changed files with 42 additions and 12 deletions

View File

@ -257,10 +257,8 @@ public class SettingsActivity extends PreferenceActivity {
Exporter.importData(getBaseContext(), uri, Exporter.importData(getBaseContext(), uri,
(progress, action) -> mHandler.post(() -> dialogController.setProgress(progress, action))); (progress, action) -> mHandler.post(() -> dialogController.setProgress(progress, action)));
mHandler.post(() -> {
// DO on backup finished // DO on backup finished
dialogController.cancel(); mHandler.post(dialogController::cancel);
});
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
mHandler.post(() -> { mHandler.post(() -> {

View File

@ -35,4 +35,8 @@ public class UserPreferences {
return preferences.getInt("weight", 80); return preferences.getInt("weight", 80);
} }
public String getMapStyle(){
return preferences.getString("mapStyle", "osm.mapnik");
}
} }

View File

@ -19,8 +19,6 @@
package de.tadris.fitness.map; package de.tadris.fitness.map;
import android.preference.PreferenceManager;
import org.mapsforge.core.model.LatLong; import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory; import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.util.AndroidUtil; import org.mapsforge.map.android.util.AndroidUtil;
@ -28,6 +26,7 @@ import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.layer.cache.TileCache; import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.download.TileDownloadLayer; import org.mapsforge.map.layer.download.TileDownloadLayer;
import de.tadris.fitness.Instance;
import de.tadris.fitness.map.tilesource.FitoTrackTileSource; import de.tadris.fitness.map.tilesource.FitoTrackTileSource;
import de.tadris.fitness.map.tilesource.HumanitarianTileSource; import de.tadris.fitness.map.tilesource.HumanitarianTileSource;
import de.tadris.fitness.map.tilesource.MapnikTileSource; import de.tadris.fitness.map.tilesource.MapnikTileSource;
@ -39,7 +38,7 @@ public class MapManager {
public static TileDownloadLayer setupMap(MapView mapView, TileSources.Purpose purpose){ public static TileDownloadLayer setupMap(MapView mapView, TileSources.Purpose purpose){
FitoTrackTileSource tileSource; FitoTrackTileSource tileSource;
String chosenTileLayer= PreferenceManager.getDefaultSharedPreferences(mapView.getContext()).getString("mapStyle", "osm.mapnik"); String chosenTileLayer= Instance.getInstance(mapView.getContext()).userPreferences.getMapStyle();
switch (chosenTileLayer){ switch (chosenTileLayer){
case "osm.humanitarian": tileSource= HumanitarianTileSource.INSTANCE; break; case "osm.humanitarian": tileSource= HumanitarianTileSource.INSTANCE; break;
case "thunderforest.outdoors": tileSource= ThunderforestTileSource.OUTDOORS; break; case "thunderforest.outdoors": tileSource= ThunderforestTileSource.OUTDOORS; break;

View File

@ -29,7 +29,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -59,6 +58,7 @@ public class Exporter {
listener.onStatusChanged(10, context.getString(R.string.preferences)); listener.onStatusChanged(10, context.getString(R.string.preferences));
FitoTrackSettings settings= new FitoTrackSettings(); FitoTrackSettings settings= new FitoTrackSettings();
settings.weight= preferences.getUserWeight(); settings.weight= preferences.getUserWeight();
settings.mapStyle= preferences.getMapStyle();
settings.preferredUnitSystem= String.valueOf(UnitUtils.CHOSEN_SYSTEM.getId()); settings.preferredUnitSystem= String.valueOf(UnitUtils.CHOSEN_SYSTEM.getId());
container.settings= settings; container.settings= settings;
@ -76,14 +76,14 @@ public class Exporter {
} }
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void importData(Context context, Uri input, ExportStatusListener listener) throws IOException{ public static void importData(Context context, Uri input, ExportStatusListener listener) throws IOException, UnsupportedVersionException {
listener.onStatusChanged(0, context.getString(R.string.loadingFile)); listener.onStatusChanged(0, context.getString(R.string.loadingFile));
XmlMapper xmlMapper = new XmlMapper(); XmlMapper xmlMapper = new XmlMapper();
xmlMapper.configure(JsonParser.Feature.IGNORE_UNDEFINED, true); xmlMapper.configure(JsonParser.Feature.IGNORE_UNDEFINED, true);
FitoTrackDataContainer container = xmlMapper.readValue(context.getContentResolver().openInputStream(input), FitoTrackDataContainer.class); FitoTrackDataContainer container = xmlMapper.readValue(context.getContentResolver().openInputStream(input), FitoTrackDataContainer.class);
if(container.version != 1){ if(container.version != 1){
throw new UnsupportedEncodingException("Version Code" + container.version + " is unsupported!"); throw new UnsupportedVersionException("Version Code" + container.version + " is unsupported!");
} }
listener.onStatusChanged(40, context.getString(R.string.preferences)); listener.onStatusChanged(40, context.getString(R.string.preferences));
@ -91,7 +91,7 @@ public class Exporter {
.edit().clear() .edit().clear()
.putInt("weight", container.settings.weight) .putInt("weight", container.settings.weight)
.putString("unitSystem", container.settings.preferredUnitSystem) .putString("unitSystem", container.settings.preferredUnitSystem)
.putBoolean("firstStart", false) .putBoolean("firstStart", false).putString("mapStyle", container.settings.mapStyle)
.commit(); .commit();
AppDatabase database= Instance.getInstance(context).db; AppDatabase database= Instance.getInstance(context).db;

View File

@ -1,15 +1,36 @@
/*
* Copyright (c) 2019 Jannis Scheibe <jannis@tadris.de>
*
* This file is part of FitoTrack
*
* FitoTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FitoTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.tadris.fitness.util.export; package de.tadris.fitness.util.export;
public class FitoTrackSettings { public class FitoTrackSettings {
String preferredUnitSystem; String preferredUnitSystem;
int weight; int weight;
String mapStyle;
public FitoTrackSettings(){} public FitoTrackSettings(){}
public FitoTrackSettings(String preferredUnitSystem, int weight) { public FitoTrackSettings(String preferredUnitSystem, int weight, String mapStyle) {
this.preferredUnitSystem = preferredUnitSystem; this.preferredUnitSystem = preferredUnitSystem;
this.weight = weight; this.weight = weight;
this.mapStyle = mapStyle;
} }
public String getPreferredUnitSystem() { public String getPreferredUnitSystem() {
@ -27,4 +48,12 @@ public class FitoTrackSettings {
public void setWeight(int weight) { public void setWeight(int weight) {
this.weight = weight; this.weight = weight;
} }
public String getMapStyle() {
return mapStyle;
}
public void setMapStyle(String mapStyle) {
this.mapStyle = mapStyle;
}
} }