-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve the review forgotten cards dialog #20620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nourhanbakry
wants to merge
5
commits into
ankidroid:main
Choose a base branch
from
nourhanbakry:Improve-the-Review-forgotten-cards-dialog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−7
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ import android.app.Dialog | |
| import android.content.res.Resources | ||
| import android.os.Bundle | ||
| import android.os.Parcelable | ||
| import android.text.InputFilter | ||
| import android.text.Spanned | ||
| import android.util.TypedValue | ||
| import android.view.WindowManager | ||
| import android.view.inputmethod.EditorInfo | ||
|
|
@@ -88,6 +90,7 @@ import com.ichi2.utils.setPaddingRelative | |
| import com.ichi2.utils.textAsIntOrNull | ||
| import com.ichi2.utils.title | ||
| import kotlinx.coroutines.Deferred | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.parcelize.Parcelize | ||
| import net.ankiweb.rsdroid.BackendException | ||
|
|
@@ -335,10 +338,18 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |
| if (contextMenuOption == EXTEND_NEW || contextMenuOption == EXTEND_REV) { | ||
| inputType = EditorInfo.TYPE_CLASS_NUMBER or EditorInfo.TYPE_NUMBER_FLAG_SIGNED | ||
| } | ||
| if (contextMenuOption == STUDY_FORGOT) { | ||
| filters = arrayOf(InputFilter.LengthFilter(9), NoLeadingZeroFilter()) | ||
| val initialValue = defaultValue.toIntOrNull() ?: 1 | ||
| binding.detailsEditText2Layout.suffixText = resources.getQuantityString(R.plurals.set_due_date_label_suffix, initialValue) | ||
| } | ||
| } | ||
|
|
||
| val positiveBtnLabel = | ||
| if (contextMenuOption == STUDY_TAGS) { | ||
| TR.customStudyChooseTags().toSentenceCase(R.string.sentence_choose_tags) | ||
| } else if (contextMenuOption == STUDY_FORGOT) { | ||
| getString(R.string.dialog_positive_create) | ||
| } else { | ||
| getString(R.string.dialog_ok) | ||
| } | ||
|
|
@@ -421,8 +432,41 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |
| } | ||
| } | ||
|
|
||
| binding.detailsEditText2.doAfterTextChanged { | ||
| binding.detailsEditText2.doAfterTextChanged { text -> | ||
| dialog.positiveButton.isEnabled = userInputValue != null && userInputValue != 0 | ||
| val value = text?.toString()?.toIntOrNull() | ||
|
|
||
| if (contextMenuOption == STUDY_FORGOT) { | ||
| if (userInputValue == null) { | ||
| dialog.positiveButton.isEnabled = false | ||
| binding.detailsEditText2Layout.error = getString(R.string.invalid_value) | ||
| return@doAfterTextChanged | ||
| } | ||
| if (userInputValue == 0) { | ||
| binding.detailsEditText2Layout.error = getString(R.string.custom_study_ahead_prevent_leading_zeros) | ||
| dialog.positiveButton.isEnabled = false | ||
| return@doAfterTextChanged | ||
| } | ||
|
|
||
| val storedValue = value ?: return@doAfterTextChanged | ||
| binding.detailsEditText2Layout.suffixText = resources.getQuantityString(R.plurals.set_due_date_label_suffix, storedValue) | ||
|
|
||
| val currentValue = userInputValue | ||
|
|
||
| lifecycleScope.launch { | ||
| val hasCards = hasMatchingCards(contextMenuOption, userInputValue) | ||
|
|
||
| if (currentValue != userInputValue) return@launch | ||
|
|
||
| if (hasCards) { | ||
| binding.detailsEditText2Layout.error = null | ||
| dialog.positiveButton.isEnabled = true | ||
| } else { | ||
| binding.detailsEditText2Layout.error = getString(R.string.no_cards_matched_criteria) | ||
| dialog.positiveButton.isEnabled = false | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Show soft keyboard | ||
|
|
@@ -484,6 +528,29 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |
| } | ||
| } | ||
|
|
||
| private suspend fun hasMatchingCards( | ||
| option: ContextMenuOption, | ||
| input: Int?, | ||
| ): Boolean { | ||
| if (option != STUDY_FORGOT) return true | ||
|
|
||
| val value = input ?: return false | ||
| if (value <= 0) return false | ||
|
|
||
| return try { | ||
| withCol { | ||
| val currentDeckName = decks.name(viewModel.deckId) | ||
|
|
||
| val hasForgottenCards = | ||
| findCards("deck:\"$currentDeckName\" rated:$value:1").isNotEmpty() | ||
| hasForgottenCards | ||
| } | ||
| } catch (e: Exception) { | ||
| Timber.e(e) | ||
| true | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Loads [CustomStudyDefaults] from the backend | ||
| * | ||
|
|
@@ -508,7 +575,7 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |
| when (selectedSubDialog) { | ||
| EXTEND_NEW -> deferredDefaults.getCompleted().labelForNewQueueAvailable() | ||
| EXTEND_REV -> deferredDefaults.getCompleted().labelForReviewQueueAvailable() | ||
| STUDY_FORGOT, | ||
| STUDY_FORGOT -> TR.customStudyReviewForgottenCards() | ||
| STUDY_AHEAD, | ||
| STUDY_PREVIEW, | ||
| STUDY_TAGS, | ||
|
|
@@ -564,6 +631,25 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |
| * Represents actions for managing custom study sessions and extending study limits. | ||
| * These actions are passed between fragments and activities via the FragmentResult API. | ||
| */ | ||
| class NoLeadingZeroFilter : InputFilter { | ||
| override fun filter( | ||
| source: CharSequence?, | ||
| start: Int, | ||
| end: Int, | ||
| dest: Spanned?, | ||
| dstart: Int, | ||
| dend: Int, | ||
| ): CharSequence? { | ||
| val newText = dest?.replaceRange(dstart, dend, source?.subSequence(start, end) ?: "") | ||
|
|
||
| return if (newText != null && newText.length > 1 && newText.startsWith("0")) { | ||
| "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here as well : see this comment #20618 (comment) |
||
| } else { | ||
| null | ||
| } | ||
| } | ||
| } | ||
|
|
||
| enum class CustomStudyAction { | ||
| EXTEND_STUDY_LIMITS, | ||
| CUSTOM_STUDY_SESSION, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
TR.customStudyNoCardsMatchedTheCriteriaYouinstead of the string resource here to avoid duplication