From b356c186565744f960e1a4e9b0f5e507428c2072 Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Sat, 22 Jun 2024 12:31:45 +0200 Subject: [PATCH] feat: Show popup for reset profile action. --- .../profile/ProfileResetPreferenceAction.kt | 25 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/obd/graphs/preferences/profile/ProfileResetPreferenceAction.kt b/app/src/main/java/org/obd/graphs/preferences/profile/ProfileResetPreferenceAction.kt index 27bc11dd..2adbaefc 100644 --- a/app/src/main/java/org/obd/graphs/preferences/profile/ProfileResetPreferenceAction.kt +++ b/app/src/main/java/org/obd/graphs/preferences/profile/ProfileResetPreferenceAction.kt @@ -20,9 +20,16 @@ package org.obd.graphs.preferences.profile import android.content.Context import android.util.AttributeSet +import android.util.Log +import androidx.appcompat.app.AlertDialog import androidx.preference.Preference +import org.obd.graphs.R +import org.obd.graphs.SCREEN_LOCK_PROGRESS_EVENT +import org.obd.graphs.SCREEN_UNLOCK_PROGRESS_EVENT import org.obd.graphs.activity.navigateToPreferencesScreen +import org.obd.graphs.bl.trip.tripManager import org.obd.graphs.profile.profile +import org.obd.graphs.sendBroadcastEvent class ProfileResetPreferenceAction( context: Context, @@ -31,8 +38,22 @@ class ProfileResetPreferenceAction( init { setOnPreferenceClickListener { - profile.reset() - navigateToPreferencesScreen("pref.profiles") + val builder = AlertDialog.Builder(context) + val title = context.getString(R.string.pref_profile_reset_confirmation_dialog) + val yes = context.getString(R.string.trip_delete_dialog_ask_question_yes) + val no = context.getString(R.string.trip_delete_dialog_ask_question_no) + + builder.setMessage(title) + .setCancelable(false) + .setPositiveButton(yes) { _, _ -> + profile.reset() + navigateToPreferencesScreen("pref.profiles") + } + .setNegativeButton(no) { dialog, _ -> + dialog.dismiss() + } + val alert = builder.create() + alert.show() true } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b8e7a91..dc083390 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -348,6 +348,7 @@ Make a backup from user preferences This operation makes a backup from user preferences + This operation resets all the custom settings to the factory defaults. Are you sure u want to execute it? Reset to factory settings Save current vehicle profile preferences This operation resets profile preferences