Skip to content
Open
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 @@ -24,6 +24,7 @@ import androidx.core.content.edit
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.core.widget.doAfterTextChanged
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.setFragmentResult
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -56,6 +57,7 @@ import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.libanki.DeckId
import com.ichi2.anki.observability.undoableOp
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.ui.NonLeadingZeroInputFilter
import com.ichi2.anki.ui.internationalization.sentenceCase
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
import com.ichi2.anki.utils.ext.getIntOrNull
Expand Down Expand Up @@ -281,6 +283,8 @@ class CustomStudyDialog : AnalyticsDialogFragment() {
binding.detailsText1.text = text1
binding.detailsText2.text = text2

binding.detailsText2.isVisible = text2.isNotEmpty()

binding.cardsStateSelectorLayout.isVisible = contextMenuOption == STUDY_TAGS
binding.cardsStateSelector.apply {
fun setAdapterAndSelection(
Expand Down Expand Up @@ -310,18 +314,39 @@ class CustomStudyDialog : AnalyticsDialogFragment() {
setAdapterAndSelection(cardStates, viewModel.selectedCardStateIndex)
}
binding.detailsEditText2.apply {
filters += NonLeadingZeroInputFilter

setText(defaultValue)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this line

// Give EditText focus and show keyboard
setSelectAllOnFocus(true)
requestFocus()
// a user may enter a negative value when extending limits
if (contextMenuOption == EXTEND_NEW || contextMenuOption == EXTEND_REV) {
inputType = EditorInfo.TYPE_CLASS_NUMBER or EditorInfo.TYPE_NUMBER_FLAG_SIGNED
}

if (contextMenuOption == STUDY_FORGOT) {
binding.detailsEditText2Layout.suffixText =
resources.getQuantityString(
R.plurals.set_due_date_label_suffix,
defaultValue.toIntOrNull() ?: 0,
)
doOnTextChanged { text, _, _, _ ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be slightly inefficient
consider doAfterTextChanged which fires once per text change

val currentValue = text?.toString()?.toIntOrNull()
binding.detailsEditText2Layout.suffixText =
resources.getQuantityString(
R.plurals.set_due_date_label_suffix,
currentValue ?: 0,
)
}
}
}
val positiveBtnLabel =
if (contextMenuOption == STUDY_TAGS) {
TR.sentenceCase.chooseTags
} else if (contextMenuOption == STUDY_FORGOT) {
getString(R.string.dialog_positive_create)
} else {
getString(R.string.dialog_ok)
}
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<string name="intent_aedict_category">To add cards to AnkiDroid remove all Notepad categories or add one named “default”</string>
<string name="custom_study_new_extend">Increase/decrease (“-3”) today’s new card limit by</string>
<string name="custom_study_rev_extend">Increase/decrease (“-3”) today’s review limit by</string>
<string name="custom_study_forgotten">Review cards forgotten in last x days:</string>
<string name="custom_study_forgotten">Review forgotten cards</string>
<string name="custom_study_ahead">Review ahead by x days:</string>
<string name="custom_study_preview">Preview new cards added in the last x days:</string>
<string name="custom_study_tags">Select x cards from the deck:</string>
Expand Down
Loading