Disable the apply button while the group is being updated

This commit is contained in:
nielsandriesse 2020-10-06 14:15:37 +11:00
parent 389b4b9768
commit 6d724fe349

View File

@ -42,6 +42,8 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
private val originalMembers = HashSet<String>() private val originalMembers = HashSet<String>()
private val members = HashSet<String>() private val members = HashSet<String>()
private var hasNameChanged = false private var hasNameChanged = false
private var isLoading = false
set(newValue) { field = newValue; invalidateOptionsMenu() }
private lateinit var groupID: String private lateinit var groupID: String
private lateinit var originalName: String private lateinit var originalName: String
@ -121,7 +123,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_edit_closed_group, menu) menuInflater.inflate(R.menu.menu_edit_closed_group, menu)
return members.isNotEmpty() return members.isNotEmpty() && !isLoading
} }
// endregion // endregion
@ -171,8 +173,8 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
// region Interaction // region Interaction
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when(item.itemId) { when (item.itemId) {
R.id.action_apply -> commitChanges() R.id.action_apply -> if (!isLoading) { commitChanges() }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
@ -244,13 +246,16 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
} }
if (isSSKBasedClosedGroup) { if (isSSKBasedClosedGroup) {
isLoading = true
loader.fadeIn() loader.fadeIn()
ClosedGroupsProtocol.update(this, groupPublicKey!!, members.map { it.address.serialize() }, name).successUi { ClosedGroupsProtocol.update(this, groupPublicKey!!, members.map { it.address.serialize() }, name).successUi {
loader.fadeOut() loader.fadeOut()
isLoading = false
finish() finish()
}.failUi { exception -> }.failUi { exception ->
val message = if (exception is ClosedGroupsProtocol.Error) exception.description else "An error occurred" val message = if (exception is ClosedGroupsProtocol.Error) exception.description else "An error occurred"
Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show() Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show()
isLoading = false
} }
} else { } else {
GroupManager.updateGroup(this, groupID, members, null, name, admins) GroupManager.updateGroup(this, groupID, members, null, name, admins)