Skip to content

Commit 702705e

Browse files
Add button to delete all WireGuard configs (#2595)
Add a new button in the toggle buttons to delete all the added WireGuard config options at once. Show a dialog box before deleting which indicates that it's irreversible (unless they still have access to the wireguard files). Add Malayalam translation for the dialog.
1 parent f7bdb50 commit 702705e

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

app/src/full/java/com/celzero/bravedns/ui/activity/WgMainActivity.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ class WgMainActivity :
366366
}
367367
}
368368
b.createFab.setOnClickListener { openTunnelEditorActivity() }
369+
b.deleteAllFab.setOnClickListener { showDeleteAllInterfacesDialog() }
369370

370371
b.wgGeneralToggleBtn.setOnClickListener {
371372
if (WireguardManager.oneWireGuardEnabled()) {
@@ -386,6 +387,45 @@ class WgMainActivity :
386387
}
387388
}
388389

390+
private fun showDeleteAllInterfacesDialog() {
391+
val builder = MaterialAlertDialogBuilder(this, R.style.App_Dialog_NoDim)
392+
val delText =
393+
getString(
394+
R.string.two_argument_space,
395+
getString(R.string.config_delete_all_dialog_title),
396+
getString(R.string.lbl_wireguard)
397+
)
398+
builder.setTitle(delText)
399+
builder.setMessage(getString(R.string.config_delete_all_dialog_desc))
400+
builder.setCancelable(true)
401+
builder.setPositiveButton(delText) { _, _ ->
402+
io {
403+
val allConfigs = WireguardManager.getAllMappings().map { it.id };
404+
allConfigs.forEach { configId ->
405+
WireguardManager.deleteConfig(configId)
406+
logEvent(
407+
"Delete WireGuard config",
408+
"User deleted WireGuard config with id $configId through Delete All"
409+
)
410+
};
411+
uiCtx {
412+
Utilities.showToastUiCentered(
413+
this,
414+
getString(R.string.config_add_success_toast),
415+
Toast.LENGTH_SHORT
416+
)
417+
finish()
418+
}
419+
}
420+
}
421+
422+
builder.setNegativeButton(this.getString(R.string.lbl_cancel)) { _, _ ->
423+
// no-op
424+
}
425+
val dialog = builder.create()
426+
dialog.show()
427+
}
428+
389429
private fun openTunnelEditorActivity() {
390430
val intent = Intent(this, WgConfigEditorActivity::class.java)
391431
startActivity(intent)
@@ -446,18 +486,22 @@ class WgMainActivity :
446486
b.createFab.visibility = View.VISIBLE
447487
b.importFab.visibility = View.VISIBLE
448488
b.qrCodeFab.visibility = View.VISIBLE
489+
b.deleteAllFab.visibility = View.VISIBLE
449490
b.createFab.animate().translationY(-resources.getDimension(R.dimen.standard_55))
450491
b.importFab.animate().translationY(-resources.getDimension(R.dimen.standard_105))
451492
b.qrCodeFab.animate().translationY(-resources.getDimension(R.dimen.standard_155))
493+
b.deleteAllFab.animate().translationY(-resources.getDimension(R.dimen.standard_205))
452494
}
453495

454496
private fun collapseFab() {
455497
b.createFab.animate().translationY(resources.getDimension(R.dimen.standard_0))
456498
b.importFab.animate().translationY(resources.getDimension(R.dimen.standard_0))
457499
b.qrCodeFab.animate().translationY(resources.getDimension(R.dimen.standard_0))
500+
b.deleteAllFab.animate().translationY(resources.getDimension(R.dimen.standard_0))
458501
b.createFab.visibility = View.GONE
459502
b.importFab.visibility = View.GONE
460503
b.qrCodeFab.visibility = View.GONE
504+
b.deleteAllFab.visibility = View.GONE
461505
}
462506

463507
private fun logEvent(msg: String, details: String) {

app/src/main/res/layout/activity_wireguard_main.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@
173173
app:layout_constraintBottom_toBottomOf="parent"
174174
app:layout_constraintEnd_toEndOf="parent" />
175175

176+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
177+
android:id="@+id/delete_all_fab"
178+
android:layout_width="wrap_content"
179+
android:layout_height="wrap_content"
180+
android:layout_marginEnd="10dp"
181+
android:layout_marginBottom="40dp"
182+
android:clickable="true"
183+
android:contentDescription="@string/lbl_delete"
184+
android:focusable="true"
185+
android:text="@string/lbl_delete"
186+
android:textColor="?attr/primaryTextColor"
187+
app:backgroundTint="@color/chipColorBgHighlightLight"
188+
app:fabSize="mini"
189+
app:icon="@android:drawable/ic_menu_delete"
190+
app:iconTint="@android:color/transparent"
191+
app:iconTintMode="add"
192+
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
193+
app:layout_constraintBottom_toBottomOf="parent"
194+
app:layout_constraintEnd_toEndOf="parent" />
195+
176196
<com.google.android.material.floatingactionbutton.FloatingActionButton
177197
android:id="@+id/wg_add_fab"
178198
android:layout_width="wrap_content"

app/src/main/res/values-ml/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
<string name="status_exposed" description="This is a large message in a scary color. It indicates that DNS queries can be surveilled or modified in transit." translatable="true">സംരക്ഷിച്ചിട്ടില്ല</string>
4949
<string name="brbs_restore_dialog_failure_positive" translatable="true">പുനഃസ്ഥാപിക്കാൻ വീണ്ടും ശ്രമിക്കുക</string>
5050
<string name="private_dns_dialog_positive" translatable="true">ക്രമീകരണങ്ങളിലേക്ക് പോകുക</string>
51+
<string name="config_delete_all_dialog_desc">ഈ നിയമനം എല്ലാ വയർഗാര്ഡ്‌ വി.പി.എൻ. ക്രമീകരണങ്ങളേയും മായിച്ച് ഇല്ലാതാക്കും. ഇത് പിൻവലിക്കാൻ കഴിയാത്ത ഏർപ്പാടാണ്.</string>
52+
<string name="config_delete_all_dialog_title">" എല്ലാം മായിക്കുക"</string>
5153
</resources>

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<dimen name="standard_55">70dp</dimen>
3232
<dimen name="standard_105">140dp</dimen>
3333
<dimen name="standard_155">210dp</dimen>
34+
<dimen name="standard_205">280dp</dimen>
3435

3536
</resources>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,9 @@
16151615
<string name="config_delete_dialog_title" translatable="true">Delete</string>
16161616
<string name="config_add_success_toast" translatable="true">Done</string>
16171617

1618+
<string name="config_delete_all_dialog_desc" translatable="true">Are you sure you want to delete ALL WireGuard VPN configurations? This is IRREVERSIBLE.</string>
1619+
<string name="config_delete_all_dialog_title" translatable="true">Delete All</string>
1620+
16181621
<string name="include_all_app_wg_dialog_title" translatable="true">Include all apps</string>
16191622
<string name="include_all_app_wg_dialog_desc" translatable="true">Use this WireGuard VPN for all apps?</string>
16201623

0 commit comments

Comments
 (0)