Skip to content

Add display/enable conditions to buttons in AddWordDialogFragment#33

Open
qminlh wants to merge 1 commit intoadgad:masterfrom
qminlh:key-dialog-buttons-conditions
Open

Add display/enable conditions to buttons in AddWordDialogFragment#33
qminlh wants to merge 1 commit intoadgad:masterfrom
qminlh:key-dialog-buttons-conditions

Conversation

@qminlh
Copy link
Copy Markdown

@qminlh qminlh commented May 3, 2023

Description

There are cases where some of AddWordDialogFragment's buttons are not expected - for example, the Move up button when adding a new key. To combat this, this pull request introduces conditions for some of these buttons - the following conditions have been added:

  • Move up: visible if index > -1 (when editing existing key), disabled if index == 0 (when the topmost key is chosen)
  • Delete: disabled if keyCount <= 1 (to avoid making the list empty)

As a bonus, dialog title has also been changed to "Add Key" when adding a key.

Screenshots

Before After
Adding a new key add-before add-after
Editing the topmost key edit-first-before edit-first-after
Editing the only key edit-only-before edit-only-after

Additional notes

  • The reason why I added a condition for Delete button is to keep already implemented logic - currently it is impossible to delete the last key, as the key with index 0 can't be removed (this change also makes it possible to remove it, as long as the list will not be empty afterwards). By the way, keep in mind that it's still possible to delete all keys by importing a file containing empty array.
  • Changing the state of the buttons needs to be done in onStart, as the getButton method returns null if the dialog is not fully created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant