Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Button to Reset Settings in SettingScreen #978

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values-de/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="pref_track_chunks">Hochladen während der Fahrt</string>

<!-- Settings Activity -->
<string name="reset_to_default">Zurücksetzen</string>
<string name="reset">zurücksetzen</string>
<string name="pref_settings_general">Allgemeine Einstellungen</string>
<string name="pref_settings_general_summary">Anzeige, Sprachausgabe, automatisches Hochladen ...</string>
<string name="pref_settings_autoconnect">Verbindungseinstellungen</string>
Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="pref_track_chunks">Track Chunk Upload</string>

<!-- Settings Activity -->
<string name="reset_to_default">Reset to default</string>
<string name="reset">reset</string>
<string name="pref_settings_general">General Settings</string>
<string name="pref_settings_general_summary">Display, Verbal Announcements, Automatic Upload ...</string>
<string name="pref_settings_autoconnect">Connection Settings</string>
Expand Down
6 changes: 5 additions & 1 deletion org.envirocar.app/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:iconSpaceReserved="false">

<Preference
android:key="@string/reset"
android:title="@string/reset_to_default"
app:iconSpaceReserved="false"
/>
<PreferenceCategory
android:title="@string/pref_settings_general"
app:iconSpaceReserved="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.envirocar.app.views.settings;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

Expand All @@ -28,6 +29,7 @@
import androidx.preference.CheckBoxPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;

import org.envirocar.app.R;
import org.envirocar.app.handler.ApplicationSettings;
Expand Down Expand Up @@ -62,6 +64,7 @@ public static class SettingsFragment extends PreferenceFragmentCompat {
private Preference enableGPSMode;
private Preference gpsTrimDuration;
private Preference gpsAutoRecording;
private Preference resetToDefault;

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand All @@ -78,7 +81,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
this.enableGPSMode = findPreference(getString(R.string.prefkey_enable_gps_based_track_recording));
this.gpsTrimDuration = findPreference(getString(R.string.prefkey_track_trim_duration));
this.gpsAutoRecording = findPreference(getString(R.string.prefkey_gps_mode_ar));

this.resetToDefault=findPreference(getString(R.string.reset));

// set initial state
this.searchInterval.setVisible(((CheckBoxPreference) automaticRecording).isChecked());
Expand All @@ -98,6 +101,17 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
gpsAutoRecording.setVisible((boolean) newValue);
return true;
}));
this.resetToDefault.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.edit().clear().apply();
// Update your UI to reflect the new state of the preferences
getActivity().recreate();
return true;
}
});

}

@Override
Expand Down