add undo function for clear events

This commit is contained in:
akaessens 2020-09-27 13:30:29 +02:00
parent 8335ffeada
commit e549ca7676
3 changed files with 17 additions and 6 deletions

View File

@ -43,12 +43,20 @@ public class SettingsActivity extends AppCompatActivity {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
SharedPreferences prefs = preference.getSharedPreferences(); final SharedPreferences prefs = preference.getSharedPreferences();
final String undo = prefs.getString("events", "");
prefs.edit().remove("events").apply(); prefs.edit().remove("events").apply();
Snackbar.make(getActivity().findViewById(android.R.id.content), Snackbar.make(getActivity().findViewById(android.R.id.content),
getString(R.string.preferences_event_snackbar), Snackbar.LENGTH_SHORT).show(); getString(R.string.preferences_event_snackbar), Snackbar.LENGTH_SHORT)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
prefs.edit().putString("events", undo).apply();
}
}).show();
return true; return true;
} }

View File

@ -19,4 +19,5 @@
<string name="preferences_event_setting">Veranstaltungsliste löschen</string> <string name="preferences_event_setting">Veranstaltungsliste löschen</string>
<string name="preferences_event_snackbar">"Veranstaltungen gelöscht "</string> <string name="preferences_event_snackbar">"Veranstaltungen gelöscht "</string>
<string name="done">Fertig</string> <string name="done">Fertig</string>
<string name="undo">Rückgängig</string>
</resources> </resources>

View File

@ -8,9 +8,6 @@
<!-- Input hints --> <!-- Input hints -->
<string name="hint_add_link">Event link</string> <string name="hint_add_link">Event link</string>
<string name="done">Done</string>
<string name="helper_add_link">Paste Facebook link to the event</string> <string name="helper_add_link">Paste Facebook link to the event</string>
<string name="button_add">Add to calendar</string> <string name="button_add">Add to calendar</string>
<string name="tooltip_paste">Paste content from clipboard into the URL input box</string> <string name="tooltip_paste">Paste content from clipboard into the URL input box</string>
@ -22,7 +19,7 @@
<string name="error_connection">Error: Unable to connect</string> <string name="error_connection">Error: Unable to connect</string>
<string name="error_unknown">Error: Unknown Error</string> <string name="error_unknown">Error: Unknown Error</string>
<string name="event_placeholder" translatable="false">Placeholder</string>
<!-- Preferences --> <!-- Preferences -->
<string name="preferences_scraper_header" translatable="false">Scraper</string> <string name="preferences_scraper_header" translatable="false">Scraper</string>
@ -33,4 +30,9 @@
<string name="preferences_event_setting">Clear event list</string> <string name="preferences_event_setting">Clear event list</string>
<string name="preferences_event_snackbar">Events list cleared</string> <string name="preferences_event_snackbar">Events list cleared</string>
<!-- others -->
<string name="event_placeholder" translatable="false">Placeholder</string>
<string name="done">Done</string>
<string name="undo">Undo</string>
</resources> </resources>