Fix preference reset

pull/1004/head
Alex Baker 4 years ago
parent 0388422553
commit 6b2729604b

@ -1,7 +1,6 @@
package org.tasks.injection
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import androidx.annotation.StringRes
@ -63,15 +62,17 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
dialogBuilder
.newDialog()
.setMessage(R.string.restart_required)
.setPositiveButton(R.string.restart_now) { _: DialogInterface?, _: Int ->
val nextIntent = Intent(context, MainActivity::class.java)
nextIntent.putExtra(MainActivity.OPEN_FILTER, null as Filter?)
ProcessPhoenix.triggerRebirth(context, nextIntent)
}
.setPositiveButton(R.string.restart_now) { _, _ -> restart() }
.setNegativeButton(R.string.restart_later, null)
.show()
}
protected fun restart() {
val nextIntent = Intent(context, MainActivity::class.java)
nextIntent.putExtra(MainActivity.OPEN_FILTER, null as Filter?)
ProcessPhoenix.triggerRebirth(context, nextIntent)
}
protected fun tintColorPreference(resId: Int, tint: Int) {
val pref = findPreference(resId)
pref.icon = DrawableUtil.getWrapped(requireContext(), R.drawable.color_picker)

@ -8,6 +8,7 @@ import static com.google.common.collect.Sets.newHashSet;
import static java.util.Collections.emptySet;
import static org.tasks.Strings.isNullOrEmpty;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@ -197,18 +198,22 @@ public class Preferences {
return firstDayOfWeek < 1 || firstDayOfWeek > 7 ? 0 : firstDayOfWeek;
}
@SuppressLint("ApplySharedPref")
public void clear() {
prefs.edit().clear().apply();
prefs.edit().clear().commit();
}
public void setDefaults() {
setDefaultValues(context, R.xml.preferences, true);
setDefaultValues(context, R.xml.preferences_task_defaults, true);
setDefaultValues(context, R.xml.preferences_synchronization, true);
setDefaultValues(context, R.xml.preferences_notifications, true);
setDefaultValues(context, R.xml.preferences_look_and_feel, true);
setDefaultValues(context, R.xml.preferences_notifications, true);
setDefaultValues(context, R.xml.preferences_synchronization, true);
setDefaultValues(context, R.xml.preferences_task_defaults, true);
setDefaultValues(context, R.xml.preferences_date_and_time, true);
setDefaultValues(context, R.xml.preferences_navigation_drawer, true);
setDefaultValues(context, R.xml.preferences_backups, true);
setDefaultValues(context, R.xml.preferences_advanced, true);
setDefaultValues(context, R.xml.help_and_feedback, true);
BeastModePreferences.setDefaultOrder(this, context);
}

@ -205,7 +205,7 @@ class Advanced : InjectingPreferenceFragment() {
.setMessage(R.string.EPr_reset_preferences_warning)
.setPositiveButton(R.string.EPr_reset_preferences) { _, _ ->
preferences.reset()
exitProcess(0)
restart()
}
.setNegativeButton(android.R.string.cancel, null)
.show()
@ -217,7 +217,7 @@ class Advanced : InjectingPreferenceFragment() {
.setMessage(R.string.EPr_delete_task_data_warning)
.setPositiveButton(R.string.EPr_delete_task_data) { _, _ ->
requireContext().deleteDatabase(database.name)
exitProcess(0)
restart()
}
.setNegativeButton(android.R.string.cancel, null)
.show()

Loading…
Cancel
Save