From 99182791f9c6a23c3f3eba3a4cd8181799457bbe Mon Sep 17 00:00:00 2001 From: jannis Date: Tue, 10 Sep 2019 20:01:14 +0200 Subject: [PATCH] put map style setting into data backup --- .../fitness/activity/SettingsActivity.java | 6 ++-- .../tadris/fitness/data/UserPreferences.java | 4 +++ .../de/tadris/fitness/map/MapManager.java | 5 ++- .../tadris/fitness/util/export/Exporter.java | 8 ++--- .../util/export/FitoTrackSettings.java | 31 ++++++++++++++++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/de/tadris/fitness/activity/SettingsActivity.java b/app/src/main/java/de/tadris/fitness/activity/SettingsActivity.java index 1841eab..567789d 100644 --- a/app/src/main/java/de/tadris/fitness/activity/SettingsActivity.java +++ b/app/src/main/java/de/tadris/fitness/activity/SettingsActivity.java @@ -257,10 +257,8 @@ public class SettingsActivity extends PreferenceActivity { Exporter.importData(getBaseContext(), uri, (progress, action) -> mHandler.post(() -> dialogController.setProgress(progress, action))); - mHandler.post(() -> { - // DO on backup finished - dialogController.cancel(); - }); + // DO on backup finished + mHandler.post(dialogController::cancel); }catch (Exception e){ e.printStackTrace(); mHandler.post(() -> { diff --git a/app/src/main/java/de/tadris/fitness/data/UserPreferences.java b/app/src/main/java/de/tadris/fitness/data/UserPreferences.java index 831ac6b..385be76 100644 --- a/app/src/main/java/de/tadris/fitness/data/UserPreferences.java +++ b/app/src/main/java/de/tadris/fitness/data/UserPreferences.java @@ -35,4 +35,8 @@ public class UserPreferences { return preferences.getInt("weight", 80); } + public String getMapStyle(){ + return preferences.getString("mapStyle", "osm.mapnik"); + } + } diff --git a/app/src/main/java/de/tadris/fitness/map/MapManager.java b/app/src/main/java/de/tadris/fitness/map/MapManager.java index 786c7c4..caa54c7 100644 --- a/app/src/main/java/de/tadris/fitness/map/MapManager.java +++ b/app/src/main/java/de/tadris/fitness/map/MapManager.java @@ -19,8 +19,6 @@ package de.tadris.fitness.map; -import android.preference.PreferenceManager; - import org.mapsforge.core.model.LatLong; import org.mapsforge.map.android.graphics.AndroidGraphicFactory; 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.download.TileDownloadLayer; +import de.tadris.fitness.Instance; import de.tadris.fitness.map.tilesource.FitoTrackTileSource; import de.tadris.fitness.map.tilesource.HumanitarianTileSource; import de.tadris.fitness.map.tilesource.MapnikTileSource; @@ -39,7 +38,7 @@ public class MapManager { public static TileDownloadLayer setupMap(MapView mapView, TileSources.Purpose purpose){ FitoTrackTileSource tileSource; - String chosenTileLayer= PreferenceManager.getDefaultSharedPreferences(mapView.getContext()).getString("mapStyle", "osm.mapnik"); + String chosenTileLayer= Instance.getInstance(mapView.getContext()).userPreferences.getMapStyle(); switch (chosenTileLayer){ case "osm.humanitarian": tileSource= HumanitarianTileSource.INSTANCE; break; case "thunderforest.outdoors": tileSource= ThunderforestTileSource.OUTDOORS; break; diff --git a/app/src/main/java/de/tadris/fitness/util/export/Exporter.java b/app/src/main/java/de/tadris/fitness/util/export/Exporter.java index d93fc0c..6914fe6 100644 --- a/app/src/main/java/de/tadris/fitness/util/export/Exporter.java +++ b/app/src/main/java/de/tadris/fitness/util/export/Exporter.java @@ -29,7 +29,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; @@ -59,6 +58,7 @@ public class Exporter { listener.onStatusChanged(10, context.getString(R.string.preferences)); FitoTrackSettings settings= new FitoTrackSettings(); settings.weight= preferences.getUserWeight(); + settings.mapStyle= preferences.getMapStyle(); settings.preferredUnitSystem= String.valueOf(UnitUtils.CHOSEN_SYSTEM.getId()); container.settings= settings; @@ -76,14 +76,14 @@ public class Exporter { } @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)); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(JsonParser.Feature.IGNORE_UNDEFINED, true); FitoTrackDataContainer container = xmlMapper.readValue(context.getContentResolver().openInputStream(input), FitoTrackDataContainer.class); 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)); @@ -91,7 +91,7 @@ public class Exporter { .edit().clear() .putInt("weight", container.settings.weight) .putString("unitSystem", container.settings.preferredUnitSystem) - .putBoolean("firstStart", false) + .putBoolean("firstStart", false).putString("mapStyle", container.settings.mapStyle) .commit(); AppDatabase database= Instance.getInstance(context).db; diff --git a/app/src/main/java/de/tadris/fitness/util/export/FitoTrackSettings.java b/app/src/main/java/de/tadris/fitness/util/export/FitoTrackSettings.java index 645b9af..7d6527c 100644 --- a/app/src/main/java/de/tadris/fitness/util/export/FitoTrackSettings.java +++ b/app/src/main/java/de/tadris/fitness/util/export/FitoTrackSettings.java @@ -1,15 +1,36 @@ +/* + * Copyright (c) 2019 Jannis Scheibe + * + * 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 . + */ + package de.tadris.fitness.util.export; public class FitoTrackSettings { String preferredUnitSystem; int weight; + String mapStyle; public FitoTrackSettings(){} - public FitoTrackSettings(String preferredUnitSystem, int weight) { + public FitoTrackSettings(String preferredUnitSystem, int weight, String mapStyle) { this.preferredUnitSystem = preferredUnitSystem; this.weight = weight; + this.mapStyle = mapStyle; } public String getPreferredUnitSystem() { @@ -27,4 +48,12 @@ public class FitoTrackSettings { public void setWeight(int weight) { this.weight = weight; } + + public String getMapStyle() { + return mapStyle; + } + + public void setMapStyle(String mapStyle) { + this.mapStyle = mapStyle; + } }