Skip to content

Commit

Permalink
don't invoke protections toggle listener without user interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lmac012 committed Nov 16, 2023
1 parent c8fee28 commit f92d55e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class SiteProtectionsToggle @JvmOverloads constructor(

fun setOnProtectionsToggledListener(listener: (Boolean) -> Unit) {
binding.protectionsSwitch.setOnCheckedChangeListener { _, isChecked ->
listener.invoke(isChecked)
if (isChecked != areProtectionsEnabled()) {
listener.invoke(isChecked)
}
}
}

Expand Down Expand Up @@ -80,4 +82,11 @@ class SiteProtectionsToggle @JvmOverloads constructor(
}
}
}

private fun areProtectionsEnabled(): Boolean = when (state) {
SiteProtectionsState.ENABLED -> true
SiteProtectionsState.DISABLED,
SiteProtectionsState.DISABLED_BY_REMOTE_CONFIG,
-> false
}
}

0 comments on commit f92d55e

Please sign in to comment.