Check blocked/allowed lists for duplicates

This commit is contained in:
Mygod
2021-08-22 02:45:13 -04:00
parent f50d579fd3
commit abf6913de4

View File

@@ -331,24 +331,27 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
} }
} }
dialogView.maxClientWrapper.error = maxClientError dialogView.maxClientWrapper.error = maxClientError
val blockedListError = try { val listsNoError = if (Build.VERSION.SDK_INT >= 30) {
val (blockedList, blockedListError) = try {
(dialogView.blockedList.text ?: "").split(nonMacChars) (dialogView.blockedList.text ?: "").split(nonMacChars)
.filter { it.isNotEmpty() }.forEach { MacAddressCompat.fromString(it).toPlatform() } .filter { it.isNotEmpty() }.map { MacAddressCompat.fromString(it).toPlatform() }.toSet() to null
null
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
e.readableMessage null to e.readableMessage
} }
dialogView.blockedListWrapper.error = blockedListError dialogView.blockedListWrapper.error = blockedListError
val allowedListError = try { val allowedListError = try {
(dialogView.allowedList.text ?: "").split(nonMacChars) (dialogView.allowedList.text ?: "").split(nonMacChars).filter { it.isNotEmpty() }.forEach {
.filter { it.isNotEmpty() }.forEach { MacAddressCompat.fromString(it).toPlatform() } val mac = MacAddressCompat.fromString(it).toPlatform()
require(blockedList?.contains(mac) != true) { "A MAC address exists in both client lists" }
}
null null
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
e.readableMessage e.readableMessage
} }
dialogView.allowedListWrapper.error = allowedListError dialogView.allowedListWrapper.error = allowedListError
val canCopy = timeoutError == null && bssidValid && maxClientError == null && blockedListError == null && blockedListError == null && allowedListError == null
allowedListError == null } else true
val canCopy = timeoutError == null && bssidValid && maxClientError == null && listsNoError
(dialog as? AlertDialog)?.getButton(DialogInterface.BUTTON_POSITIVE)?.isEnabled = (dialog as? AlertDialog)?.getButton(DialogInterface.BUTTON_POSITIVE)?.isEnabled =
ssidLength in 1..32 && passwordValid && isBandValid && canCopy ssidLength in 1..32 && passwordValid && isBandValid && canCopy
dialogView.toolbar.menu.findItem(android.R.id.copy).isEnabled = canCopy dialogView.toolbar.menu.findItem(android.R.id.copy).isEnabled = canCopy