Skip to content

Commit

Permalink
Adds a confirmation dialog on Exit
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyZhukovsky committed Oct 22, 2024
1 parent dc8a84d commit 5524ff2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 28 additions & 1 deletion android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}
18 changes: 18 additions & 0 deletions android/java/res/layout/brave_exit_confirmation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
style="@style/AlertDialogContent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/brave_exit_confirmation" />

</LinearLayout>

3 changes: 3 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4066,6 +4066,9 @@ If you don't accept this request, VPN will not reconnect and your internet conne
<message name="IDS_SHOW_UNDO_WHEN_TABS_CLOSED" desc="Menu item to show undo button when tabs are closed">
Show undo button when tabs are closed
</message>
<message name="IDS_BRAVE_EXIT_CONFIRMATION" desc="A confirmation shown on Exit Brave">
Are you sure you want to exit Brave?
</message>
</messages>
</release>
</grit>

0 comments on commit 5524ff2

Please sign in to comment.