From 5524ff2adf5651d85de366b9a6f08efeee59fb2b Mon Sep 17 00:00:00 2001 From: Serg Date: Tue, 22 Oct 2024 13:00:45 -0400 Subject: [PATCH] Adds a confirmation dialog on Exit --- android/brave_java_resources.gni | 1 + .../chrome/browser/app/BraveActivity.java | 29 ++++++++++++++++++- .../res/layout/brave_exit_confirmation.xml | 18 ++++++++++++ .../android/strings/android_brave_strings.grd | 3 ++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 android/java/res/layout/brave_exit_confirmation.xml diff --git a/android/brave_java_resources.gni b/android/brave_java_resources.gni index 6057e4ee680c..de8ee7f56852 100644 --- a/android/brave_java_resources.gni +++ b/android/brave_java_resources.gni @@ -792,6 +792,7 @@ brave_java_resources = [ "java/res/layout/brave_bottom_new_tab_button.xml", "java/res/layout/brave_custom_tabs_toolbar.xml", "java/res/layout/brave_dialog_preference.xml", + "java/res/layout/brave_exit_confirmation.xml", "java/res/layout/brave_leo_reset_dialog.xml", "java/res/layout/brave_news_card_menu.xml", "java/res/layout/brave_news_load_new_content.xml", diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index 73afd9938b2b..578d5ddb28bf 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -11,6 +11,7 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; import android.content.SharedPreferences; @@ -22,6 +23,7 @@ import android.os.Handler; import android.text.TextUtils; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -401,7 +403,7 @@ public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) { if (currentTab == null) { return false; } else if (id == R.id.exit_id) { - ApplicationLifetime.terminate(false); + exitBrave(); } else if (id == R.id.set_default_browser) { BraveSetDefaultBrowserUtils.showBraveSetDefaultBrowserDialog(BraveActivity.this, true); } else if (id == R.id.brave_rewards_id) { @@ -2469,4 +2471,29 @@ public MultiInstanceManager getMultiInstanceManager() { BraveReflectionUtil.getField( ChromeTabbedActivity.class, "mMultiInstanceManager", this); } + + private void exitBrave() { + LayoutInflater inflater = + (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.brave_exit_confirmation, null); + DialogInterface.OnClickListener onClickListener = + (dialog, button) -> { + if (button == AlertDialog.BUTTON_POSITIVE) { + ApplicationLifetime.terminate(false); + } else { + dialog.dismiss(); + } + }; + + AlertDialog.Builder alert = + new AlertDialog.Builder(this, R.style.ThemeOverlay_BrowserUI_AlertDialog); + AlertDialog alertDialog = + alert.setTitle(R.string.menu_exit) + .setView(view) + .setPositiveButton(R.string.brave_action_yes, onClickListener) + .setNegativeButton(R.string.brave_action_no, onClickListener) + .create(); + alertDialog.getDelegate().setHandleNativeActionModesEnabled(false); + alertDialog.show(); + } } diff --git a/android/java/res/layout/brave_exit_confirmation.xml b/android/java/res/layout/brave_exit_confirmation.xml new file mode 100644 index 000000000000..b52cc63cbde8 --- /dev/null +++ b/android/java/res/layout/brave_exit_confirmation.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index ab7b73866c01..cb2dd0fca9c8 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -4066,6 +4066,9 @@ If you don't accept this request, VPN will not reconnect and your internet conne Show undo button when tabs are closed + + Are you sure you want to exit Brave? +