mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-29 00:32:11 -07:00
Do not backup/restore app settings
This commit is contained in:
parent
fb2f78b9ee
commit
a36fc3ae71
@ -31,7 +31,6 @@ import java.util.Arrays;
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.data.AppDatabase;
|
||||
import de.tadris.fitness.data.UserPreferences;
|
||||
import de.tadris.fitness.util.unit.UnitUtils;
|
||||
|
||||
public class BackupController {
|
||||
@ -41,7 +40,6 @@ public class BackupController {
|
||||
private final Context context;
|
||||
private final File output;
|
||||
private final ExportStatusListener listener;
|
||||
private UserPreferences preferences;
|
||||
private AppDatabase database;
|
||||
|
||||
private FitoTrackDataContainer dataContainer;
|
||||
@ -55,10 +53,6 @@ public class BackupController {
|
||||
public void exportData() throws IOException {
|
||||
listener.onStatusChanged(0, context.getString(R.string.initialising));
|
||||
init();
|
||||
listener.onStatusChanged(10, context.getString(R.string.preferences));
|
||||
newContainer();
|
||||
|
||||
saveSettingsToContainer();
|
||||
listener.onStatusChanged(20, context.getString(R.string.workouts));
|
||||
saveWorkoutsToContainer();
|
||||
listener.onStatusChanged(40, context.getString(R.string.locationData));
|
||||
@ -69,32 +63,23 @@ public class BackupController {
|
||||
}
|
||||
|
||||
private void init(){
|
||||
preferences= Instance.getInstance(context).userPreferences;
|
||||
database= Instance.getInstance(context).db;
|
||||
UnitUtils.setUnit(context); // Ensure unit system is correct
|
||||
}
|
||||
|
||||
private void newContainer(){
|
||||
dataContainer= new FitoTrackDataContainer();
|
||||
dataContainer.version= VERSION;
|
||||
dataContainer.workouts= new ArrayList<>();
|
||||
dataContainer.samples= new ArrayList<>();
|
||||
}
|
||||
|
||||
private void saveSettingsToContainer(){
|
||||
FitoTrackSettings settings= new FitoTrackSettings();
|
||||
settings.weight= preferences.getUserWeight();
|
||||
settings.mapStyle= preferences.getMapStyle();
|
||||
settings.preferredUnitSystem= String.valueOf(UnitUtils.CHOSEN_SYSTEM.getId());
|
||||
dataContainer.settings= settings;
|
||||
dataContainer.setVersion(VERSION);
|
||||
dataContainer.setWorkouts(new ArrayList<>());
|
||||
dataContainer.setSamples(new ArrayList<>());
|
||||
}
|
||||
|
||||
private void saveWorkoutsToContainer(){
|
||||
dataContainer.workouts.addAll(Arrays.asList(database.workoutDao().getWorkouts()));
|
||||
dataContainer.getWorkouts().addAll(Arrays.asList(database.workoutDao().getWorkouts()));
|
||||
}
|
||||
|
||||
private void saveSamplesToContainer(){
|
||||
dataContainer.samples.addAll(Arrays.asList(database.workoutDao().getSamples()));
|
||||
dataContainer.getSamples().addAll(Arrays.asList(database.workoutDao().getSamples()));
|
||||
}
|
||||
|
||||
private void writeContainerToOutputFile() throws IOException {
|
||||
|
||||
@ -31,18 +31,16 @@ import de.tadris.fitness.data.WorkoutSample;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
class FitoTrackDataContainer {
|
||||
|
||||
int version;
|
||||
List<Workout> workouts;
|
||||
List<WorkoutSample> samples;
|
||||
FitoTrackSettings settings;
|
||||
private int version;
|
||||
private List<Workout> workouts;
|
||||
private List<WorkoutSample> samples;
|
||||
|
||||
public FitoTrackDataContainer(){}
|
||||
|
||||
public FitoTrackDataContainer(int version, List<Workout> workouts, List<WorkoutSample> samples, FitoTrackSettings settings) {
|
||||
public FitoTrackDataContainer(int version, List<Workout> workouts, List<WorkoutSample> samples) {
|
||||
this.version = version;
|
||||
this.workouts = workouts;
|
||||
this.samples = samples;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
@ -69,11 +67,5 @@ class FitoTrackDataContainer {
|
||||
this.samples = samples;
|
||||
}
|
||||
|
||||
public FitoTrackSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setSettings(FitoTrackSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.export;
|
||||
|
||||
public class FitoTrackSettings {
|
||||
|
||||
String preferredUnitSystem;
|
||||
int weight;
|
||||
String mapStyle;
|
||||
|
||||
public FitoTrackSettings(){}
|
||||
|
||||
public FitoTrackSettings(String preferredUnitSystem, int weight, String mapStyle) {
|
||||
this.preferredUnitSystem = preferredUnitSystem;
|
||||
this.weight = weight;
|
||||
this.mapStyle = mapStyle;
|
||||
}
|
||||
|
||||
public String getPreferredUnitSystem() {
|
||||
return preferredUnitSystem;
|
||||
}
|
||||
|
||||
public void setPreferredUnitSystem(String preferredUnitSystem) {
|
||||
this.preferredUnitSystem = preferredUnitSystem;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getMapStyle() {
|
||||
return mapStyle;
|
||||
}
|
||||
|
||||
public void setMapStyle(String mapStyle) {
|
||||
this.mapStyle = mapStyle;
|
||||
}
|
||||
}
|
||||
@ -19,10 +19,8 @@
|
||||
|
||||
package de.tadris.fitness.export;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
@ -54,9 +52,6 @@ public class RestoreController {
|
||||
listener.onStatusChanged(0, context.getString(R.string.loadingFile));
|
||||
loadDataFromFile();
|
||||
checkVersion();
|
||||
listener.onStatusChanged(40, context.getString(R.string.preferences));
|
||||
restoreSettings();
|
||||
|
||||
restoreDatabase();
|
||||
listener.onStatusChanged(100, context.getString(R.string.finished));
|
||||
}
|
||||
@ -68,21 +63,11 @@ public class RestoreController {
|
||||
}
|
||||
|
||||
private void checkVersion() throws UnsupportedVersionException {
|
||||
if(dataContainer.version != 1){
|
||||
throw new UnsupportedVersionException("Version Code" + dataContainer.version + " is unsupported!");
|
||||
if (dataContainer.getVersion() != 1) {
|
||||
throw new UnsupportedVersionException("Version Code" + dataContainer.getVersion() + " is unsupported!");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
private void restoreSettings(){
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit().clear()
|
||||
.putInt("weight", dataContainer.settings.weight)
|
||||
.putString("unitSystem", dataContainer.settings.preferredUnitSystem)
|
||||
.putBoolean("firstStart", false).putString("mapStyle", dataContainer.settings.mapStyle)
|
||||
.commit();
|
||||
}
|
||||
|
||||
private void restoreDatabase(){
|
||||
database.runInTransaction(() -> {
|
||||
resetDatabase();
|
||||
@ -97,8 +82,8 @@ public class RestoreController {
|
||||
|
||||
private void restoreWorkouts(){
|
||||
listener.onStatusChanged(60, context.getString(R.string.workouts));
|
||||
if(dataContainer.workouts != null){
|
||||
for(Workout workout : dataContainer.workouts){
|
||||
if (dataContainer.getWorkouts() != null) {
|
||||
for (Workout workout : dataContainer.getWorkouts()) {
|
||||
database.workoutDao().insertWorkout(workout);
|
||||
}
|
||||
}
|
||||
@ -106,8 +91,8 @@ public class RestoreController {
|
||||
|
||||
private void restoreSamples(){
|
||||
listener.onStatusChanged(80, context.getString(R.string.locationData));
|
||||
if(dataContainer.samples != null){
|
||||
for(WorkoutSample sample : dataContainer.samples){
|
||||
if (dataContainer.getSamples() != null) {
|
||||
for (WorkoutSample sample : dataContainer.getSamples()) {
|
||||
database.workoutDao().insertSample(sample);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
<string name="errorImportFailed">Der Datenimport ist fehlgeschlagen.</string>
|
||||
<string name="exportAsGpxFile">Als GPX-Datei exportieren</string>
|
||||
<string name="exportData">Daten exportieren</string>
|
||||
<string name="exportDataSummary">Erstellt ein Backup von all deinen Einstellungen und deiner Workoutdaten</string>
|
||||
<string name="exportDataSummary">Erstellt ein Backup von all deinern Workoutdaten</string>
|
||||
<string name="exporting">Exportieren</string>
|
||||
<string name="finished">Fertig</string>
|
||||
<string name="gps">GPS</string>
|
||||
|
||||
@ -115,7 +115,6 @@
|
||||
<string name="pref_unit_system">Sistema preferido de unidades</string>
|
||||
<string name="settings">Ajustes</string>
|
||||
<string name="exportData">Datos de exportación</string>
|
||||
<string name="exportDataSummary">Esto toma una copia de seguridad de todas sus preferencias y datos de entrenamiento</string>
|
||||
<string name="importBackup">Importar copia de seguridad</string>
|
||||
<string name="importBackupSummary">Restaurar una copia de seguridad</string>
|
||||
<string name="gps">GPS</string>
|
||||
|
||||
@ -136,7 +136,7 @@
|
||||
<string name="pref_unit_system">Preferred system of units</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="exportData">Export Data</string>
|
||||
<string name="exportDataSummary">This takes a backup of all your preferences and workout data</string>
|
||||
<string name="exportDataSummary">This takes a backup of all your workout data</string>
|
||||
<string name="importBackup">Import Data Backup</string>
|
||||
<string name="importBackupSummary">Restore a taken backup</string>
|
||||
<string name="gps">GPS</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user