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.Instance;
|
||||||
import de.tadris.fitness.R;
|
import de.tadris.fitness.R;
|
||||||
import de.tadris.fitness.data.AppDatabase;
|
import de.tadris.fitness.data.AppDatabase;
|
||||||
import de.tadris.fitness.data.UserPreferences;
|
|
||||||
import de.tadris.fitness.util.unit.UnitUtils;
|
import de.tadris.fitness.util.unit.UnitUtils;
|
||||||
|
|
||||||
public class BackupController {
|
public class BackupController {
|
||||||
@ -41,7 +40,6 @@ public class BackupController {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
private final File output;
|
private final File output;
|
||||||
private final ExportStatusListener listener;
|
private final ExportStatusListener listener;
|
||||||
private UserPreferences preferences;
|
|
||||||
private AppDatabase database;
|
private AppDatabase database;
|
||||||
|
|
||||||
private FitoTrackDataContainer dataContainer;
|
private FitoTrackDataContainer dataContainer;
|
||||||
@ -55,10 +53,6 @@ public class BackupController {
|
|||||||
public void exportData() throws IOException {
|
public void exportData() throws IOException {
|
||||||
listener.onStatusChanged(0, context.getString(R.string.initialising));
|
listener.onStatusChanged(0, context.getString(R.string.initialising));
|
||||||
init();
|
init();
|
||||||
listener.onStatusChanged(10, context.getString(R.string.preferences));
|
|
||||||
newContainer();
|
|
||||||
|
|
||||||
saveSettingsToContainer();
|
|
||||||
listener.onStatusChanged(20, context.getString(R.string.workouts));
|
listener.onStatusChanged(20, context.getString(R.string.workouts));
|
||||||
saveWorkoutsToContainer();
|
saveWorkoutsToContainer();
|
||||||
listener.onStatusChanged(40, context.getString(R.string.locationData));
|
listener.onStatusChanged(40, context.getString(R.string.locationData));
|
||||||
@ -69,32 +63,23 @@ public class BackupController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init(){
|
private void init(){
|
||||||
preferences= Instance.getInstance(context).userPreferences;
|
|
||||||
database= Instance.getInstance(context).db;
|
database= Instance.getInstance(context).db;
|
||||||
UnitUtils.setUnit(context); // Ensure unit system is correct
|
UnitUtils.setUnit(context); // Ensure unit system is correct
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newContainer(){
|
private void newContainer(){
|
||||||
dataContainer= new FitoTrackDataContainer();
|
dataContainer= new FitoTrackDataContainer();
|
||||||
dataContainer.version= VERSION;
|
dataContainer.setVersion(VERSION);
|
||||||
dataContainer.workouts= new ArrayList<>();
|
dataContainer.setWorkouts(new ArrayList<>());
|
||||||
dataContainer.samples= new ArrayList<>();
|
dataContainer.setSamples(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveWorkoutsToContainer(){
|
private void saveWorkoutsToContainer(){
|
||||||
dataContainer.workouts.addAll(Arrays.asList(database.workoutDao().getWorkouts()));
|
dataContainer.getWorkouts().addAll(Arrays.asList(database.workoutDao().getWorkouts()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveSamplesToContainer(){
|
private void saveSamplesToContainer(){
|
||||||
dataContainer.samples.addAll(Arrays.asList(database.workoutDao().getSamples()));
|
dataContainer.getSamples().addAll(Arrays.asList(database.workoutDao().getSamples()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeContainerToOutputFile() throws IOException {
|
private void writeContainerToOutputFile() throws IOException {
|
||||||
|
|||||||
@ -31,18 +31,16 @@ import de.tadris.fitness.data.WorkoutSample;
|
|||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
class FitoTrackDataContainer {
|
class FitoTrackDataContainer {
|
||||||
|
|
||||||
int version;
|
private int version;
|
||||||
List<Workout> workouts;
|
private List<Workout> workouts;
|
||||||
List<WorkoutSample> samples;
|
private List<WorkoutSample> samples;
|
||||||
FitoTrackSettings settings;
|
|
||||||
|
|
||||||
public FitoTrackDataContainer(){}
|
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.version = version;
|
||||||
this.workouts = workouts;
|
this.workouts = workouts;
|
||||||
this.samples = samples;
|
this.samples = samples;
|
||||||
this.settings = settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVersion() {
|
public int getVersion() {
|
||||||
@ -69,11 +67,5 @@ class FitoTrackDataContainer {
|
|||||||
this.samples = samples;
|
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;
|
package de.tadris.fitness.export;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
@ -54,9 +52,6 @@ public class RestoreController {
|
|||||||
listener.onStatusChanged(0, context.getString(R.string.loadingFile));
|
listener.onStatusChanged(0, context.getString(R.string.loadingFile));
|
||||||
loadDataFromFile();
|
loadDataFromFile();
|
||||||
checkVersion();
|
checkVersion();
|
||||||
listener.onStatusChanged(40, context.getString(R.string.preferences));
|
|
||||||
restoreSettings();
|
|
||||||
|
|
||||||
restoreDatabase();
|
restoreDatabase();
|
||||||
listener.onStatusChanged(100, context.getString(R.string.finished));
|
listener.onStatusChanged(100, context.getString(R.string.finished));
|
||||||
}
|
}
|
||||||
@ -68,21 +63,11 @@ public class RestoreController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkVersion() throws UnsupportedVersionException {
|
private void checkVersion() throws UnsupportedVersionException {
|
||||||
if(dataContainer.version != 1){
|
if (dataContainer.getVersion() != 1) {
|
||||||
throw new UnsupportedVersionException("Version Code" + dataContainer.version + " is unsupported!");
|
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(){
|
private void restoreDatabase(){
|
||||||
database.runInTransaction(() -> {
|
database.runInTransaction(() -> {
|
||||||
resetDatabase();
|
resetDatabase();
|
||||||
@ -97,8 +82,8 @@ public class RestoreController {
|
|||||||
|
|
||||||
private void restoreWorkouts(){
|
private void restoreWorkouts(){
|
||||||
listener.onStatusChanged(60, context.getString(R.string.workouts));
|
listener.onStatusChanged(60, context.getString(R.string.workouts));
|
||||||
if(dataContainer.workouts != null){
|
if (dataContainer.getWorkouts() != null) {
|
||||||
for(Workout workout : dataContainer.workouts){
|
for (Workout workout : dataContainer.getWorkouts()) {
|
||||||
database.workoutDao().insertWorkout(workout);
|
database.workoutDao().insertWorkout(workout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,8 +91,8 @@ public class RestoreController {
|
|||||||
|
|
||||||
private void restoreSamples(){
|
private void restoreSamples(){
|
||||||
listener.onStatusChanged(80, context.getString(R.string.locationData));
|
listener.onStatusChanged(80, context.getString(R.string.locationData));
|
||||||
if(dataContainer.samples != null){
|
if (dataContainer.getSamples() != null) {
|
||||||
for(WorkoutSample sample : dataContainer.samples){
|
for (WorkoutSample sample : dataContainer.getSamples()) {
|
||||||
database.workoutDao().insertSample(sample);
|
database.workoutDao().insertSample(sample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
<string name="errorImportFailed">Der Datenimport ist fehlgeschlagen.</string>
|
<string name="errorImportFailed">Der Datenimport ist fehlgeschlagen.</string>
|
||||||
<string name="exportAsGpxFile">Als GPX-Datei exportieren</string>
|
<string name="exportAsGpxFile">Als GPX-Datei exportieren</string>
|
||||||
<string name="exportData">Daten 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="exporting">Exportieren</string>
|
||||||
<string name="finished">Fertig</string>
|
<string name="finished">Fertig</string>
|
||||||
<string name="gps">GPS</string>
|
<string name="gps">GPS</string>
|
||||||
|
|||||||
@ -115,7 +115,6 @@
|
|||||||
<string name="pref_unit_system">Sistema preferido de unidades</string>
|
<string name="pref_unit_system">Sistema preferido de unidades</string>
|
||||||
<string name="settings">Ajustes</string>
|
<string name="settings">Ajustes</string>
|
||||||
<string name="exportData">Datos de exportación</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="importBackup">Importar copia de seguridad</string>
|
||||||
<string name="importBackupSummary">Restaurar una copia de seguridad</string>
|
<string name="importBackupSummary">Restaurar una copia de seguridad</string>
|
||||||
<string name="gps">GPS</string>
|
<string name="gps">GPS</string>
|
||||||
|
|||||||
@ -136,7 +136,7 @@
|
|||||||
<string name="pref_unit_system">Preferred system of units</string>
|
<string name="pref_unit_system">Preferred system of units</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="exportData">Export Data</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="importBackup">Import Data Backup</string>
|
||||||
<string name="importBackupSummary">Restore a taken backup</string>
|
<string name="importBackupSummary">Restore a taken backup</string>
|
||||||
<string name="gps">GPS</string>
|
<string name="gps">GPS</string>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user