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) {
(dialogView.blockedList.text ?: "").split(nonMacChars) val (blockedList, blockedListError) = try {
.filter { it.isNotEmpty() }.forEach { MacAddressCompat.fromString(it).toPlatform() } (dialogView.blockedList.text ?: "").split(nonMacChars)
null .filter { it.isNotEmpty() }.map { MacAddressCompat.fromString(it).toPlatform() }.toSet() to 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()
null require(blockedList?.contains(mac) != true) { "A MAC address exists in both client lists" }
} catch (e: IllegalArgumentException) { }
e.readableMessage null
} } catch (e: IllegalArgumentException) {
dialogView.allowedListWrapper.error = allowedListError e.readableMessage
val canCopy = timeoutError == null && bssidValid && maxClientError == null && blockedListError == null && }
allowedListError == null dialogView.allowedListWrapper.error = allowedListError
blockedListError == 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