Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RepositionCardFragment : DialogFragment() {
title(text = title)
customView(binding.root)
negativeButton(R.string.dialog_cancel)
positiveButton(R.string.dialog_ok) {
positiveButton(R.string.reposition) {
val position =
binding.startInputEditText.textAsIntOrNull() ?: return@positiveButton
val step =
Expand All @@ -88,13 +88,42 @@ class RepositionCardFragment : DialogFragment() {
}
}

// Disable OK button if either field is empty
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
val updateButtonState = {
val startText = binding.startInputEditText.text?.toString() ?: ""
val stepText = binding.stepInputEditText.text?.toString() ?: ""
positiveButton.isEnabled = startText.isNotEmpty() && stepText.isNotEmpty()
}

binding.startInputEditText.addTextChangedListener(object : android.text.TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: android.text.Editable?) {
updateButtonState()
}
})

binding.stepInputEditText.addTextChangedListener(object : android.text.TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: android.text.Editable?) {
updateButtonState()
}
})

// Only automatically show the keyboard in portrait mode
// In landscape mode, the keyboard would take up too much screen space and hide the dialog
val isPortrait = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
if (isPortrait) {
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
}

// Initial button state check
dialog.setOnShowListener {
updateButtonState()
}

return dialog
}

Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/res/layout/fragment_reposition_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
android:inputType="number"
android:text="0"
android:maxLines="1"
android:maxLength="10"
tools:ignore="HardcodedText" />
</com.google.android.material.textfield.TextInputLayout>

Expand All @@ -68,6 +69,7 @@
android:inputType="number"
android:text="1"
android:maxLines="1"
android:maxLength="10"
tools:ignore="HardcodedText" />
</com.google.android.material.textfield.TextInputLayout>

Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

<string name="dialog_cancel">Cancel</string>
<string name="dialog_ok">OK</string>
<string name="reposition">Reposition</string>
<string name="dialog_confirm" tools:ignore="UnusedResources">Confirm</string>
<string name="dialog_no">No</string>
<string name="dialog_yes">Yes</string>
Expand Down
Loading