-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix #15760: Convert undo/redo labels to sentence case #20372
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
flowerjunjie
wants to merge
1
commit into
ankidroid:main
Choose a base branch
from
flowerjunjie:fix/issue-15760
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.
Open
Changes from all commits
Commits
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,3 +48,130 @@ fun String.toSentenceCase( | |
| if (this.equals(resString, ignoreCase = true)) return resString | ||
| return this | ||
| } | ||
|
|
||
| /** | ||
| * A map of Title Case action names to their sentence case resource IDs. | ||
| * Used for undo/redo label conversion. | ||
| */ | ||
| private val actionToSentenceCaseMap = mapOf( | ||
|
Member
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. Where did you get these strings from? Could you add the source to the commit message? |
||
| "Empty Cards" to R.string.sentence_empty_cards, | ||
| "Custom Study" to R.string.sentence_custom_study, | ||
| "Set Due Date" to R.string.sentence_set_due_date, | ||
| "Suspend Card" to R.string.sentence_suspend_card, | ||
| "Answer Card" to R.string.sentence_answer_card, | ||
| "Add Deck" to R.string.sentence_add_deck, | ||
| "Add Note" to R.string.sentence_add_note, | ||
| "Update Tag" to R.string.sentence_update_tag, | ||
| "Update Note" to R.string.sentence_update_note, | ||
| "Update Card" to R.string.sentence_update_card, | ||
| "Update Deck" to R.string.sentence_update_deck, | ||
| "Reset Card" to R.string.sentence_reset_card, | ||
| "Build Deck" to R.string.sentence_build_deck, | ||
| "Add Note Type" to R.string.sentence_add_notetype, | ||
| "Remove Note Type" to R.string.sentence_remove_notetype, | ||
| "Update Note Type" to R.string.sentence_update_notetype, | ||
| "Update Config" to R.string.sentence_update_config, | ||
| "Card Info" to R.string.sentence_card_info, | ||
| "Previous Card Info" to R.string.sentence_previous_card_info, | ||
| "Set Flag" to R.string.sentence_set_flag, | ||
| "Auto Advance" to R.string.sentence_auto_advance, | ||
| "Bury Card" to R.string.sentence_bury_card, | ||
| "Bury Note" to R.string.sentence_bury_note, | ||
| "Unbury/Unsuspend" to R.string.sentence_unbury_unsuspend, | ||
| "Rename" to R.string.sentence_rename, | ||
| "Reposition" to R.string.sentence_reposition, | ||
| "Forget Card" to R.string.sentence_forget_card, | ||
| "Toggle Load Balancer" to R.string.sentence_toggle_load_balancer, | ||
| ) | ||
|
|
||
| /** | ||
| * Converts an action name from Title Case to sentence case. | ||
| * | ||
| * @param context The context to access resources | ||
| * @param action The action name in Title Case (e.g., "Empty Cards") | ||
| * @return The action name in sentence case (e.g., "empty cards") | ||
| */ | ||
| fun actionToSentenceCase( | ||
| context: Context, | ||
| action: String, | ||
| ): String { | ||
| val resId = actionToSentenceCaseMap[action] | ||
| return if (resId != null) { | ||
| context.getString(resId) | ||
| } else { | ||
| // Fallback: convert to lowercase except first letter | ||
| action.replaceFirstChar { it.uppercaseChar() }.let { titleCase -> | ||
| titleCase.split(" ").joinToString(" ") { word -> | ||
| if (word == titleCase.split(" ").first()) { | ||
| word.replaceFirstChar { it.uppercaseChar() } | ||
| } else { | ||
| word.lowercase() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Converts undo label to sentence case. | ||
| * Handles patterns like "Undo Empty Cards" -> "Undo empty cards" | ||
| * | ||
| * @param context The context to access resources | ||
| * @param action The action name (e.g., "Empty Cards") | ||
| * @return The sentence case version (e.g., "Undo empty cards") | ||
| */ | ||
| fun undoLabelToSentenceCase( | ||
| context: Context, | ||
| action: String, | ||
| ): String { | ||
| val actionSentenceCase = actionToSentenceCase(context, action) | ||
| return "Undo $actionSentenceCase" | ||
| } | ||
|
|
||
| /** | ||
| * Converts redo label to sentence case. | ||
| * Handles patterns like "Redo Empty Cards" -> "Redo empty cards" | ||
| * | ||
| * @param context The context to access resources | ||
| * @param action The action name (e.g., "Empty Cards") | ||
| * @return The sentence case version (e.g., "Redo empty cards") | ||
| */ | ||
| fun redoLabelToSentenceCase( | ||
| context: Context, | ||
| action: String, | ||
| ): String { | ||
| val actionSentenceCase = actionToSentenceCase(context, action) | ||
| return "Redo $actionSentenceCase" | ||
| } | ||
|
|
||
| /** | ||
| * Converts "undone" message to sentence case. | ||
| * Handles patterns like "Empty Cards undone" -> "Empty cards undone" | ||
| * | ||
| * @param context The context to access resources | ||
| * @param action The action name (e.g., "Empty Cards") | ||
| * @return The sentence case version (e.g., "Empty cards undone") | ||
| */ | ||
| fun undoneMessageToSentenceCase( | ||
| context: Context, | ||
| action: String, | ||
| ): String { | ||
| val actionSentenceCase = actionToSentenceCase(context, action) | ||
| return "$actionSentenceCase undone" | ||
| } | ||
|
|
||
| /** | ||
| * Converts "redone" message to sentence case. | ||
| * Handles patterns like "Empty Cards redone" -> "Empty cards redone" | ||
| * | ||
| * @param context The context to access resources | ||
| * @param action The action name (e.g., "Empty Cards") | ||
| * @return The sentence case version (e.g., "Empty cards redone") | ||
| */ | ||
| fun redoneMessageToSentenceCase( | ||
| context: Context, | ||
| action: String, | ||
| ): String { | ||
| val actionSentenceCase = actionToSentenceCase(context, action) | ||
| return "$actionSentenceCase redone" | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -15,13 +15,15 @@ | |
| */ | ||
| package com.ichi2.anki.ui.windows.reviewer | ||
|
|
||
| import android.content.Context | ||
| import androidx.lifecycle.SavedStateHandle | ||
| import androidx.lifecycle.viewModelScope | ||
| import anki.collection.OpChanges | ||
| import anki.frontend.SetSchedulingStatesRequest | ||
| import anki.scheduler.CardAnswer.Rating | ||
| import com.ichi2.anki.AbstractFlashcardViewer | ||
| import com.ichi2.anki.AbstractFlashcardViewer.Companion.RESULT_NO_MORE_CARDS | ||
| import com.ichi2.anki.AnkiDroidApp | ||
| import com.ichi2.anki.CollectionManager.TR | ||
| import com.ichi2.anki.CollectionManager.withCol | ||
| import com.ichi2.anki.Flag | ||
|
|
@@ -344,12 +346,14 @@ class ReviewerViewModel( | |
|
|
||
| private suspend fun undo() { | ||
| Timber.v("ReviewerViewModel::undo") | ||
| actionFeedbackFlow.emit(tryUndo()) | ||
| val context = AnkiDroidApp.instance.applicationContext | ||
|
Member
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.
|
||
| actionFeedbackFlow.emit(tryUndo(context)) | ||
| } | ||
|
|
||
| private suspend fun redo() { | ||
| Timber.v("ReviewerViewModel::redo") | ||
| actionFeedbackFlow.emit(tryRedo()) | ||
| val context = AnkiDroidApp.instance.applicationContext | ||
| actionFeedbackFlow.emit(tryRedo(context)) | ||
| } | ||
|
|
||
| private suspend fun userAction( | ||
|
|
@@ -568,8 +572,23 @@ class ReviewerViewModel( | |
|
|
||
| private suspend fun updateUndoAndRedoLabels() { | ||
| Timber.v("ReviewerViewModel::updateUndoAndRedoLabels") | ||
| undoLabelFlow.emit(withCol { undoLabel() }) | ||
| redoLabelFlow.emit(withCol { redoLabel() }) | ||
| val context = AnkiDroidApp.instance.applicationContext | ||
| undoLabelFlow.emit( | ||
| withCol { undoLabel() }?.let { label -> | ||
| // Extract action name from "Undo {Action}" format | ||
| label.removePrefix("Undo ").let { action -> | ||
| com.ichi2.anki.ui.internationalization.undoLabelToSentenceCase(context, action) | ||
| } | ||
| } | ||
| ) | ||
| redoLabelFlow.emit( | ||
| withCol { redoLabel() }?.let { label -> | ||
| // Extract action name from "Redo {Action}" format | ||
| label.removePrefix("Redo ").let { action -> | ||
| com.ichi2.anki.ui.internationalization.redoLabelToSentenceCase(context, action) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| private suspend fun updateNextTimes() { | ||
|
|
||
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.
Contextshould not be a parameter here, this method should not have a direct Android dependency.