Skip to content

Commit

Permalink
refactor(custom-study): rename 'STUDY_NEW/REV' to 'EXTEND_X'
Browse files Browse the repository at this point in the history
  • Loading branch information
david-allison committed Jan 3, 2025
1 parent c0f375d commit c7900de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.analytics.AnalyticsDialogFragment
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.EXTEND_NEW
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.EXTEND_REV
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_AHEAD
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_FORGOT
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_NEW
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_PREVIEW
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_REV
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.ContextMenuOption.STUDY_TAGS
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.CustomStudyDefaults.Companion.toDomainModel
import com.ichi2.anki.dialogs.tags.TagsDialog
Expand Down Expand Up @@ -194,8 +194,8 @@ class CustomStudyDialog(
)
requireActivity().showDialogFragment(dialogFragment)
}
STUDY_NEW,
STUDY_REV,
EXTEND_NEW,
EXTEND_REV,
STUDY_FORGOT,
STUDY_AHEAD,
STUDY_PREVIEW,
Expand Down Expand Up @@ -295,7 +295,7 @@ class CustomStudyDialog(
setSelectAllOnFocus(true)
requestFocus()
// a user may enter a negative value when extending limits
if (contextMenuOption == STUDY_NEW || contextMenuOption == STUDY_REV) {
if (contextMenuOption == EXTEND_NEW || contextMenuOption == EXTEND_REV) {
inputType = EditorInfo.TYPE_CLASS_NUMBER or EditorInfo.TYPE_NUMBER_FLAG_SIGNED
}
}
Expand Down Expand Up @@ -335,8 +335,8 @@ class CustomStudyDialog(
customStudyRequest {
deckId = dialogDeckId
when (contextMenuOption) {
STUDY_NEW -> newLimitDelta = userEntry
STUDY_REV -> reviewLimitDelta = userEntry
EXTEND_NEW -> newLimitDelta = userEntry
EXTEND_REV -> reviewLimitDelta = userEntry
STUDY_FORGOT -> forgotDays = userEntry
STUDY_AHEAD -> reviewAheadDays = userEntry
STUDY_PREVIEW -> previewDays = userEntry
Expand All @@ -349,7 +349,7 @@ class CustomStudyDialog(
collection.sched.customStudy(request)
}
when (contextMenuOption) {
STUDY_NEW, STUDY_REV ->
EXTEND_NEW, EXTEND_REV ->
customStudyListener?.onExtendStudyLimits()
STUDY_FORGOT, STUDY_AHEAD, STUDY_PREVIEW -> customStudyListener?.onCreateCustomStudySession()
STUDY_TAGS -> TODO("This branch has not been covered before")
Expand All @@ -363,7 +363,7 @@ class CustomStudyDialog(
STUDY_FORGOT -> sharedPrefs().edit { putInt("forgottenDays", userEntry) }
STUDY_AHEAD -> sharedPrefs().edit { putInt("aheadDays", userEntry) }
STUDY_PREVIEW -> sharedPrefs().edit { putInt("previewDays", userEntry) }
STUDY_NEW, STUDY_REV -> {
EXTEND_NEW, EXTEND_REV -> {
// Nothing to do in ankidroid. The default value is provided by the backend.
}
STUDY_TAGS -> TODO("This branch has not been covered before")
Expand Down Expand Up @@ -402,11 +402,11 @@ class CustomStudyDialog(
* @see ContextMenuData
*/
private fun buildMenuItems(): List<ContextMenuData> =
mutableListOf(STUDY_NEW, STUDY_REV, STUDY_FORGOT, STUDY_AHEAD, STUDY_PREVIEW, STUDY_TAGS).map { option ->
mutableListOf(EXTEND_NEW, EXTEND_REV, STUDY_FORGOT, STUDY_AHEAD, STUDY_PREVIEW, STUDY_TAGS).map { option ->
val enabled =
when (option) {
STUDY_NEW -> defaults.extendNew.isUsable
STUDY_REV -> defaults.extendReview.isUsable
EXTEND_NEW -> defaults.extendNew.isUsable
EXTEND_REV -> defaults.extendReview.isUsable
else -> true
}
ContextMenuData(option, enabled)
Expand All @@ -416,8 +416,8 @@ class CustomStudyDialog(
private val text1: String
get() =
when (selectedSubDialog) {
STUDY_NEW -> defaults.labelForNewQueueAvailable()
STUDY_REV -> defaults.labelForReviewQueueAvailable()
EXTEND_NEW -> defaults.labelForNewQueueAvailable()
EXTEND_REV -> defaults.labelForReviewQueueAvailable()
STUDY_FORGOT,
STUDY_AHEAD,
STUDY_PREVIEW,
Expand All @@ -431,8 +431,8 @@ class CustomStudyDialog(
get() {
val res = resources
return when (selectedSubDialog) {
STUDY_NEW -> res.getString(R.string.custom_study_new_extend)
STUDY_REV -> res.getString(R.string.custom_study_rev_extend)
EXTEND_NEW -> res.getString(R.string.custom_study_new_extend)
EXTEND_REV -> res.getString(R.string.custom_study_rev_extend)
STUDY_FORGOT -> res.getString(R.string.custom_study_forgotten)
STUDY_AHEAD -> res.getString(R.string.custom_study_ahead)
STUDY_PREVIEW -> res.getString(R.string.custom_study_preview)
Expand All @@ -447,8 +447,8 @@ class CustomStudyDialog(
get() {
val prefs = requireActivity().sharedPrefs()
return when (selectedSubDialog) {
STUDY_NEW -> defaults.extendNew.initialValue.toString()
STUDY_REV -> defaults.extendReview.initialValue.toString()
EXTEND_NEW -> defaults.extendNew.initialValue.toString()
EXTEND_REV -> defaults.extendReview.initialValue.toString()
STUDY_FORGOT -> prefs.getInt("forgottenDays", 1).toString()
STUDY_AHEAD -> prefs.getInt("aheadDays", 1).toString()
STUDY_PREVIEW -> prefs.getInt("previewDays", 1).toString()
Expand Down Expand Up @@ -521,7 +521,7 @@ class CustomStudyDialog(

/**
* A [context menu item][ContextMenuOption], and whether it is usable.
* Example: [STUDY_NEW] would be unusable if there are no new cards
* Example: [EXTEND_NEW] would be unusable if there are no new cards
*/
data class ContextMenuData(
val item: ContextMenuOption,
Expand All @@ -536,10 +536,10 @@ class CustomStudyDialog(
val getTitle: Resources.() -> String,
) {
/** Increase today's new card limit */
STUDY_NEW({ TR.customStudyIncreaseTodaysNewCardLimit() }),
EXTEND_NEW({ TR.customStudyIncreaseTodaysNewCardLimit() }),

/** Increase today's review card limit */
STUDY_REV({ TR.customStudyIncreaseTodaysReviewCardLimit() }),
EXTEND_REV({ TR.customStudyIncreaseTodaysReviewCardLimit() }),

/** Review forgotten cards */
STUDY_FORGOT({ TR.customStudyReviewForgottenCards() }),
Expand Down
7 changes: 6 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/utils/ext/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ fun View.setPaddingRelative(
top: DisplayPixels,
end: DisplayPixels,
bottom: DisplayPixels,
) = setPaddingRelative(start.toPx(context), top.toPx(context), end.toPx(context), bottom.toPx(context))
) = setPaddingRelative(
start.toPx(context),
top.toPx(context),
end.toPx(context),
bottom.toPx(context),
)

/** Returns a [DisplayPixels] instance equal to this [Int] number of display pixels. */
val Int.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CustomStudyDialogTest : RobolectricTest() {

// extend limits with a value of '1'
withCustomStudyFragment(
args = argumentsDisplayingSubscreen(ContextMenuOption.STUDY_NEW),
args = argumentsDisplayingSubscreen(ContextMenuOption.EXTEND_NEW),
) { dialogFragment: CustomStudyDialog ->

onSubscreenEditText()
Expand All @@ -154,7 +154,7 @@ class CustomStudyDialogTest : RobolectricTest() {

// ensure 'newExtendByValue' is used by our UI
withCustomStudyFragment(
args = argumentsDisplayingSubscreen(ContextMenuOption.STUDY_NEW),
args = argumentsDisplayingSubscreen(ContextMenuOption.EXTEND_NEW),
) { dialogFragment: CustomStudyDialog ->
onSubscreenEditText()
.check(matches(withText(newExtendByValue.toString())))
Expand Down

0 comments on commit c7900de

Please sign in to comment.