From 28885f7645916fb5ddcd1ff44b87ff1764effc2f Mon Sep 17 00:00:00 2001 From: delphvr Date: Sun, 20 Oct 2024 10:41:36 +0200 Subject: [PATCH] naming convention warnings refactor Local variable naming convention refactor Private property naming convention refactor Class naming convention refactor last naming convention warnings resolved revert unwanted changes in naming refactor correction asked for the mistakes in naming refactor --- .../com/ichi2/anki/AbstractFlashcardViewer.kt | 6 +-- .../java/com/ichi2/anki/AnkiDroidJsAPI.kt | 40 +++++++++---------- .../com/ichi2/anki/AnkiDroidJsAPIConstants.kt | 24 +++++------ .../java/com/ichi2/anki/CardTemplateEditor.kt | 2 +- .../java/com/ichi2/anki/ModelFieldEditor.kt | 32 +++++++-------- .../anki/dialogs/CardSideSelectionDialog.kt | 2 +- .../dialogs/customstudy/CustomStudyDialog.kt | 4 +- .../java/com/ichi2/anki/jsaddons/AddonData.kt | 6 +-- .../ichi2/anki/jsaddons/TgzPackageExtract.kt | 6 +-- .../fields/AudioRecordingField.kt | 2 +- .../anki/multimediacard/fields/ImageField.kt | 2 +- .../multimediacard/fields/MediaClipField.kt | 2 +- .../anki/multimediacard/fields/TextField.kt | 2 +- .../impl/MultimediaEditableNote.kt | 2 +- .../com/ichi2/anki/noteeditor/FieldState.kt | 20 +++++----- .../NotificationsSettingsFragment.kt | 2 +- .../anki/provider/CardContentProvider.kt | 4 +- .../servicelayer/PreferenceUpgradeService.kt | 6 +-- .../main/java/com/ichi2/anki/utils/Time.kt | 28 ++++++------- .../src/main/java/com/ichi2/libanki/Card.kt | 12 +++--- .../main/java/com/ichi2/libanki/Collection.kt | 4 +- .../src/main/java/com/ichi2/libanki/Consts.kt | 10 ++--- .../java/com/ichi2/libanki/NotetypeJson.kt | 2 +- .../main/java/com/ichi2/libanki/Notetypes.kt | 8 ++-- .../exception/ConfirmModSchemaException.kt | 2 +- .../java/com/ichi2/libanki/sched/Scheduler.kt | 4 +- .../main/java/com/ichi2/utils/ImportUtils.kt | 8 ++-- .../src/main/java/com/ichi2/utils/TagsUtil.kt | 6 +-- .../cardanalysis/CardAnalysisWidgetConfig.kt | 13 +++--- .../deckpicker/DeckPickerWidgetConfig.kt | 10 +++-- .../java/com/ichi2/anki/NoteEditorTest.kt | 2 +- .../test/java/com/ichi2/anki/ReviewerTest.kt | 6 +-- .../ichi2/anki/dialogs/tags/TagsListTest.kt | 4 +- .../anki/preferences/PreferencesSimpleTest.kt | 4 +- .../ichi2/anki/reviewer/BindingAndroidTest.kt | 30 +++++++------- .../com/ichi2/anki/reviewer/BindingTest.kt | 20 +++++----- .../UpgradeGesturesToControlsTest.kt | 12 +++--- .../UpgradeGesturesToControlsTestNoParam.kt | 6 +-- .../test/java/com/ichi2/libanki/TagsTest.kt | 40 +++++++++---------- .../test/java/com/ichi2/testutils/JvmTest.kt | 12 +++--- .../com/ichi2/utils/UniqueArrayListTest.kt | 4 +- .../java/com/ichi2/anki/FlashCardsContract.kt | 6 +-- .../java/com/ichi2/anki/api/ApiUtilsTest.kt | 6 +-- 43 files changed, 214 insertions(+), 209 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt index 023326932312..ee664c7483f8 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt @@ -132,7 +132,7 @@ import com.ichi2.libanki.CardId import com.ichi2.libanki.ChangeManager import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts -import com.ichi2.libanki.Consts.BUTTON_TYPE +import com.ichi2.libanki.Consts.ButtonType import com.ichi2.libanki.DeckId import com.ichi2.libanki.Decks import com.ichi2.libanki.Sound.getAvTag @@ -856,7 +856,7 @@ abstract class AbstractFlashcardViewer : } } - open fun answerCard(@BUTTON_TYPE ease: Int) = preventSimultaneousExecutions(ANSWER_CARD) { + open fun answerCard(@ButtonType ease: Int) = preventSimultaneousExecutions(ANSWER_CARD) { launchCatchingTask { if (inAnswer) { return@launchCatchingTask @@ -876,7 +876,7 @@ abstract class AbstractFlashcardViewer : } } - open suspend fun answerCardInner(@BUTTON_TYPE ease: Int) { + open suspend fun answerCardInner(@ButtonType ease: Int) { // Legacy tests assume they can call answerCard() even outside of Reviewer withCol { sched.answerCard(currentCard!!, ease) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt index 709593ed4a7b..d16eac520e61 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt @@ -25,14 +25,14 @@ import android.net.Uri import androidx.lifecycle.lifecycleScope import com.github.zafarkhaja.semver.Version import com.google.android.material.snackbar.Snackbar -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeBuryCard -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeBuryNote -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeError -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeFlagCard -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeMarkCard -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeSetDue -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeSuspendCard -import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeSuspendNote +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_BURT_NOTE +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_BURY_CARD +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_ERROR +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_FLAG_CARD +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_MARK_CARD +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_SET_DUE +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_SUSPEND_CARD +import com.ichi2.anki.AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_SUSPEND_NOTE import com.ichi2.anki.AnkiDroidJsAPIConstants.flagCommands import com.ichi2.anki.cardviewer.ViewerCommand import com.ichi2.anki.model.CardsOrNotes @@ -144,7 +144,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { } return false } - val versionCurrent = Version.parse(AnkiDroidJsAPIConstants.currentJsApiVersion) + val versionCurrent = Version.parse(AnkiDroidJsAPIConstants.CURRENT_JS_API_VERSION) val versionSupplied = Version.parse(apiVer) /* @@ -160,7 +160,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { activity.runOnUiThread { activity.showSnackbar(context.getString(R.string.update_js_api_version, apiDevContact)) } - versionSupplied.isHigherThanOrEquivalentTo(Version.parse(AnkiDroidJsAPIConstants.minimumJsApiVersion)) + versionSupplied.isHigherThanOrEquivalentTo(Version.parse(AnkiDroidJsAPIConstants.MINIMUM_JS_API_VERSION)) } else -> { activity.runOnUiThread { @@ -207,21 +207,21 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { "nextTime4" -> convertToByteArray(apiContract, cardDataForJsAPI.nextTime4) "toggleFlag" -> { if (apiParams !in flagCommands) { - showDeveloperContact(ankiJsErrorCodeFlagCard, apiContract.cardSuppliedDeveloperContact) + showDeveloperContact(ANKI_JS_ERROR_CODE_FLAG_CARD, apiContract.cardSuppliedDeveloperContact) return@withContext convertToByteArray(apiContract, false) } convertToByteArray(apiContract, activity.executeCommand(flagCommands[apiParams]!!)) } - "markCard" -> processAction({ activity.executeCommand(ViewerCommand.MARK) }, apiContract, ankiJsErrorCodeMarkCard, ::convertToByteArray) - "buryCard" -> processAction(activity::buryCard, apiContract, ankiJsErrorCodeBuryCard, ::convertToByteArray) - "buryNote" -> processAction(activity::buryNote, apiContract, ankiJsErrorCodeBuryNote, ::convertToByteArray) - "suspendCard" -> processAction(activity::suspendCard, apiContract, ankiJsErrorCodeSuspendCard, ::convertToByteArray) - "suspendNote" -> processAction(activity::suspendNote, apiContract, ankiJsErrorCodeSuspendNote, ::convertToByteArray) + "markCard" -> processAction({ activity.executeCommand(ViewerCommand.MARK) }, apiContract, ANKI_JS_ERROR_CODE_MARK_CARD, ::convertToByteArray) + "buryCard" -> processAction(activity::buryCard, apiContract, ANKI_JS_ERROR_CODE_BURY_CARD, ::convertToByteArray) + "buryNote" -> processAction(activity::buryNote, apiContract, ANKI_JS_ERROR_CODE_BURT_NOTE, ::convertToByteArray) + "suspendCard" -> processAction(activity::suspendCard, apiContract, ANKI_JS_ERROR_CODE_SUSPEND_CARD, ::convertToByteArray) + "suspendNote" -> processAction(activity::suspendNote, apiContract, ANKI_JS_ERROR_CODE_SUSPEND_NOTE, ::convertToByteArray) "setCardDue" -> { try { val days = apiParams.toInt() if (days < 0 || days > 9999) { - showDeveloperContact(ankiJsErrorCodeSetDue, apiContract.cardSuppliedDeveloperContact) + showDeveloperContact(ANKI_JS_ERROR_CODE_SET_DUE, apiContract.cardSuppliedDeveloperContact) return@withContext convertToByteArray(apiContract, false) } activity.launchCatchingTask { @@ -229,7 +229,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { } return@withContext convertToByteArray(apiContract, true) } catch (e: NumberFormatException) { - showDeveloperContact(ankiJsErrorCodeSetDue, apiContract.cardSuppliedDeveloperContact) + showDeveloperContact(ANKI_JS_ERROR_CODE_SET_DUE, apiContract.cardSuppliedDeveloperContact) return@withContext convertToByteArray(apiContract, false) } } @@ -367,7 +367,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { } "sttStop" -> convertToByteArray(apiContract, speechRecognizer.stop()) else -> { - showDeveloperContact(ankiJsErrorCodeError, apiContract.cardSuppliedDeveloperContact) + showDeveloperContact(ANKI_JS_ERROR_CODE_ERROR, apiContract.cardSuppliedDeveloperContact) throw Exception("unhandled request: $methodName") } } @@ -394,7 +394,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { "console.log('${context.getString(R.string.search_card_js_api_no_results)}')", null ) - showDeveloperContact(AnkiDroidJsAPIConstants.ankiJsErrorCodeSearchCard, apiContract.cardSuppliedDeveloperContact) + showDeveloperContact(AnkiDroidJsAPIConstants.ANKI_JS_ERROR_CODE_SEARCH_CARD, apiContract.cardSuppliedDeveloperContact) return@withContext convertToByteArray(apiContract, false) } val searchResult: MutableList = ArrayList() diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPIConstants.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPIConstants.kt index 146e8f7ec52f..662e9aa285db 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPIConstants.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPIConstants.kt @@ -22,21 +22,21 @@ import com.ichi2.anki.cardviewer.ViewerCommand object AnkiDroidJsAPIConstants { // JS API ERROR CODE - const val ankiJsErrorCodeError: Int = -1 - const val ankiJsErrorCodeDefault: Int = 0 - const val ankiJsErrorCodeMarkCard: Int = 1 - const val ankiJsErrorCodeFlagCard: Int = 2 + const val ANKI_JS_ERROR_CODE_ERROR: Int = -1 + const val ANKI_JS_ERROR_CODE_DEFAULT: Int = 0 + const val ANKI_JS_ERROR_CODE_MARK_CARD: Int = 1 + const val ANKI_JS_ERROR_CODE_FLAG_CARD: Int = 2 - const val ankiJsErrorCodeBuryCard: Int = 3 - const val ankiJsErrorCodeSuspendCard: Int = 4 - const val ankiJsErrorCodeBuryNote: Int = 5 - const val ankiJsErrorCodeSuspendNote: Int = 6 - const val ankiJsErrorCodeSetDue: Int = 7 - const val ankiJsErrorCodeSearchCard: Int = 8 + const val ANKI_JS_ERROR_CODE_BURY_CARD: Int = 3 + const val ANKI_JS_ERROR_CODE_SUSPEND_CARD: Int = 4 + const val ANKI_JS_ERROR_CODE_BURT_NOTE: Int = 5 + const val ANKI_JS_ERROR_CODE_SUSPEND_NOTE: Int = 6 + const val ANKI_JS_ERROR_CODE_SET_DUE: Int = 7 + const val ANKI_JS_ERROR_CODE_SEARCH_CARD: Int = 8 // js api developer contact - const val currentJsApiVersion = "0.0.3" - const val minimumJsApiVersion = "0.0.3" + const val CURRENT_JS_API_VERSION = "0.0.3" + const val MINIMUM_JS_API_VERSION = "0.0.3" val flagCommands = mapOf( "none" to ViewerCommand.UNSET_FLAG, diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt index b51a308c8ecc..dd7662c9f3e9 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt @@ -187,7 +187,7 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener { } /** - * Loads or reloads [tempModel] in [R.id.template_previewer_fragment] if the view is fragmented. Do nothing otherwise. + * Loads or reloads [tempModel] in [R.id.fragment_container] if the view is fragmented. Do nothing otherwise. */ private fun loadTemplatePreviewerFragmentIfFragmented() { if (!fragmented) { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt index 6c0dfe4a4152..7644184bac31 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt @@ -165,14 +165,14 @@ class ModelFieldEditor : AnkiActivity(), LocaleSelectionDialogHandler { fieldNameInput = FixedEditText(this).apply { focusWithKeyboard() } - fieldNameInput?.let { _fieldNameInput -> - _fieldNameInput.isSingleLine = true + fieldNameInput?.let { fieldNameInput -> + fieldNameInput.isSingleLine = true AlertDialog.Builder(this).show { - customView(view = _fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) + customView(view = fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) title(R.string.model_field_editor_add) positiveButton(R.string.dialog_ok) { // Name is valid, now field is added - val fieldName = uniqueName(_fieldNameInput) + val fieldName = uniqueName(fieldNameInput) try { addField(fieldName, true) } catch (e: ConfirmModSchemaException) { @@ -284,15 +284,15 @@ class ModelFieldEditor : AnkiActivity(), LocaleSelectionDialogHandler { */ private fun renameFieldDialog() { fieldNameInput = FixedEditText(this).apply { focusWithKeyboard() } - fieldNameInput?.let { _fieldNameInput -> - _fieldNameInput.isSingleLine = true - _fieldNameInput.setText(fieldsLabels[currentPos]) - _fieldNameInput.setSelection(_fieldNameInput.text!!.length) + fieldNameInput?.let { fieldNameInput -> + fieldNameInput.isSingleLine = true + fieldNameInput.setText(fieldsLabels[currentPos]) + fieldNameInput.setSelection(fieldNameInput.text!!.length) AlertDialog.Builder(this).show { - customView(view = _fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) + customView(view = fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) title(R.string.model_field_editor_rename) positiveButton(R.string.rename) { - if (uniqueName(_fieldNameInput) == null) { + if (uniqueName(fieldNameInput) == null) { return@positiveButton } // Field is valid, now rename @@ -329,22 +329,22 @@ class ModelFieldEditor : AnkiActivity(), LocaleSelectionDialogHandler { */ private fun repositionFieldDialog() { fieldNameInput = FixedEditText(this).apply { focusWithKeyboard() } - fieldNameInput?.let { _fieldNameInput -> - _fieldNameInput.setRawInputType(InputType.TYPE_CLASS_NUMBER) + fieldNameInput?.let { fieldNameInput -> + fieldNameInput.setRawInputType(InputType.TYPE_CLASS_NUMBER) AlertDialog.Builder(this).show { - customView(view = _fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) + customView(view = fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32) title(text = String.format(resources.getString(R.string.model_field_editor_reposition), 1, fieldsLabels.size)) positiveButton(R.string.dialog_ok) { - val newPosition = _fieldNameInput.text.toString() + val newPosition = fieldNameInput.text.toString() val pos: Int = try { newPosition.toInt() } catch (n: NumberFormatException) { Timber.w(n) - _fieldNameInput.error = resources.getString(R.string.toast_out_of_range) + fieldNameInput.error = resources.getString(R.string.toast_out_of_range) return@positiveButton } if (pos < 1 || pos > fieldsLabels.size) { - _fieldNameInput.error = resources.getString(R.string.toast_out_of_range) + fieldNameInput.error = resources.getString(R.string.toast_out_of_range) } else { // Input is valid, now attempt to modify try { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CardSideSelectionDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CardSideSelectionDialog.kt index 14fd445593f8..6a28c8337b41 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CardSideSelectionDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CardSideSelectionDialog.kt @@ -23,7 +23,7 @@ import com.ichi2.anki.reviewer.CardSide import com.ichi2.utils.show import com.ichi2.utils.title -/** Allows selecting between [CardSide.QUESTION], [CardSide.ANSWER] or [CardSide.BOTH0] */ +/** Allows selecting between [CardSide.QUESTION], [CardSide.ANSWER] or [CardSide.BOTH] */ class CardSideSelectionDialog { companion object { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt index e04ccfb0af6c..f1737364022e 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt @@ -57,7 +57,7 @@ import com.ichi2.anki.showThemedToast import com.ichi2.annotations.NeedsTest import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts -import com.ichi2.libanki.Consts.DYN_PRIORITY +import com.ichi2.libanki.Consts.DynPriority import com.ichi2.libanki.Deck import com.ichi2.libanki.DeckId import com.ichi2.utils.HashUtil.hashMapInit @@ -493,7 +493,7 @@ class CustomStudyDialog(private val collection: Collection, private val customSt val ar = dyn.getJSONArray("terms") ar.getJSONArray(0).put(0, "deck:\"" + deckToStudyName + "\" " + terms[0]) ar.getJSONArray(0).put(1, terms[1]) - @DYN_PRIORITY val priority = terms[2] as Int + @DynPriority val priority = terms[2] as Int ar.getJSONArray(0).put(2, priority) dyn.put("resched", resched) // Rebuild the filtered deck diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/jsaddons/AddonData.kt b/AnkiDroid/src/main/java/com/ichi2/anki/jsaddons/AddonData.kt index f65111d33f24..34663fbc05d8 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/jsaddons/AddonData.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/jsaddons/AddonData.kt @@ -16,7 +16,7 @@ package com.ichi2.anki.jsaddons -import com.ichi2.anki.AnkiDroidJsAPIConstants.currentJsApiVersion +import com.ichi2.anki.AnkiDroidJsAPIConstants.CURRENT_JS_API_VERSION import com.ichi2.anki.jsaddons.AddonsConst.ANKIDROID_JS_ADDON_KEYWORDS import com.ichi2.anki.jsaddons.AddonsConst.NOTE_EDITOR_ADDON import com.ichi2.anki.jsaddons.AddonsConst.REVIEWER_ADDON @@ -123,8 +123,8 @@ fun getAddonModelFromAddonData(addonData: AddonData): Pair if (stream.read(signature) != signature.size) { return false } } - return GZIP_SIGNATURE.contentEquals(signature) + return _gzipSignature.contentEquals(signature) } /** diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/AudioRecordingField.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/AudioRecordingField.kt index c7809439631c..d9322822df19 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/AudioRecordingField.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/AudioRecordingField.kt @@ -14,6 +14,6 @@ class AudioRecordingField : AudioField() { override var name: String? = null companion object { - private const val serialVersionUID = 5033819217738174719L + private const val SERIAL_VERSION_UID = 5033819217738174719L } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/ImageField.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/ImageField.kt index 6bb7d3407abc..260efca90b2e 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/ImageField.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/ImageField.kt @@ -71,7 +71,7 @@ class ImageField : FieldBase(), IField { } companion object { - private const val serialVersionUID = 4431611060655809687L + private const val SERIAL_VERSION_UID = 4431611060655809687L @VisibleForTesting @NeedsTest("files with HTML illegal chars can be imported and rendered") diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/MediaClipField.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/MediaClipField.kt index a5017b2542a4..18281ad703c2 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/MediaClipField.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/MediaClipField.kt @@ -13,6 +13,6 @@ class MediaClipField : AudioField() { override var name: String? = null companion object { - private const val serialVersionUID = 2937641017832762987L + private const val SERIAL_VERSION_UID = 2937641017832762987L } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/TextField.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/TextField.kt index 60b198599dc7..890bbc963744 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/TextField.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/fields/TextField.kt @@ -58,6 +58,6 @@ class TextField : FieldBase(), IField { } companion object { - private const val serialVersionUID = -6508967905716947525L + private const val SERIAL_VERSION_UID = -6508967905716947525L } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/impl/MultimediaEditableNote.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/impl/MultimediaEditableNote.kt index f03986b2664c..c0e7dfd26dc7 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/impl/MultimediaEditableNote.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/impl/MultimediaEditableNote.kt @@ -109,6 +109,6 @@ class MultimediaEditableNote : IMultimediaEditableNote { get() = fields.isNullOrEmpty() companion object { - private const val serialVersionUID = -6161821367135636659L + private const val SERIAL_VERSION_UID = -6161821367135636659L } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/FieldState.kt b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/FieldState.kt index 6526178ae7c8..2c74cc353573 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/FieldState.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/FieldState.kt @@ -69,12 +69,12 @@ class FieldState private constructor(private val editor: NoteEditor) { private fun recreateFieldsFromState(): List { val editLines: MutableList = ArrayList(savedFieldData!!.size) for (state in savedFieldData!!) { - val edit_line_view = FieldEditLine(editor.requireContext()) - if (edit_line_view.id == 0) { - edit_line_view.id = View.generateViewId() + val editLineView = FieldEditLine(editor.requireContext()) + if (editLineView.id == 0) { + editLineView.id = View.generateViewId() } - edit_line_view.loadState(state) - editLines.add(edit_line_view) + editLineView.loadState(state) + editLines.add(editLineView) } return editLines } @@ -83,11 +83,11 @@ class FieldState private constructor(private val editor: NoteEditor) { val fields = getFields(type) val editLines: MutableList = ArrayList(fields.size) for (i in fields.indices) { - val edit_line_view = FieldEditLine(editor.requireContext()) - editLines.add(edit_line_view) - edit_line_view.name = fields[i][0] - edit_line_view.setContent(fields[i][1], type.replaceNewlines) - edit_line_view.setOrd(i) + val editLineView = FieldEditLine(editor.requireContext()) + editLines.add(editLineView) + editLineView.name = fields[i][0] + editLineView.setContent(fields[i][1], type.replaceNewlines) + editLineView.setOrd(i) } return editLines } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/NotificationsSettingsFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/NotificationsSettingsFragment.kt index 43d79eb054d7..3d250c75aebd 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/NotificationsSettingsFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/NotificationsSettingsFragment.kt @@ -39,7 +39,7 @@ class NotificationsSettingsFragment : SettingsFragment() { override fun initSubscreen() { if (AdaptionUtil.isXiaomiRestrictedLearningDevice) { /** These preferences should be searchable or not based - * on this same condition at [Preferences.configureSearchBar] */ + * on this same condition at [HeaderFragment.configureSearchBar] */ preferenceScreen.removePreference(requirePreference(R.string.pref_notifications_vibrate_key)) preferenceScreen.removePreference(requirePreference(R.string.pref_notifications_blink_key)) } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt b/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt index a68514c2597d..d4c8fea50294 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt @@ -37,7 +37,7 @@ import com.ichi2.anki.utils.ext.description import com.ichi2.libanki.Card import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts -import com.ichi2.libanki.Consts.BUTTON_TYPE +import com.ichi2.libanki.Consts.ButtonType import com.ichi2.libanki.Deck import com.ichi2.libanki.DeckId import com.ichi2.libanki.Decks @@ -1080,7 +1080,7 @@ class CardContentProvider : ContentProvider() { } } - private fun answerCard(col: Collection, cardToAnswer: Card?, @BUTTON_TYPE ease: Int, timeTaken: Long) { + private fun answerCard(col: Collection, cardToAnswer: Card?, @ButtonType ease: Int, timeTaken: Long) { try { if (cardToAnswer != null) { if (timeTaken != -1L) { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/PreferenceUpgradeService.kt b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/PreferenceUpgradeService.kt index e27bc60a84aa..2a69a2024c57 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/PreferenceUpgradeService.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/PreferenceUpgradeService.kt @@ -84,7 +84,7 @@ object PreferenceUpgradeService { companion object { /** A version code where the value doesn't matter as we're not using the result */ private const val IGNORED_LEGACY_VERSION_CODE = 0L - const val upgradeVersionPrefKey = "preferenceUpgradeVersion" + const val UPGRADE_VERSION_PREF_KEY = "preferenceUpgradeVersion" /** Returns all instances of preference upgrade classes */ private fun getAllInstances(legacyPreviousVersionCode: LegacyVersionIdentifier) = sequence { @@ -121,11 +121,11 @@ object PreferenceUpgradeService { } internal fun getPreferenceVersion(preferences: SharedPreferences) = - preferences.getInt(upgradeVersionPrefKey, 0) + preferences.getInt(UPGRADE_VERSION_PREF_KEY, 0) internal fun setPreferenceVersion(preferences: SharedPreferences, versionIdentifier: VersionIdentifier) { Timber.i("upgrading preference version to '$versionIdentifier'") - preferences.edit { putInt(upgradeVersionPrefKey, versionIdentifier) } + preferences.edit { putInt(UPGRADE_VERSION_PREF_KEY, versionIdentifier) } } /** Returns the collection of all preference version numbers */ diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/utils/Time.kt b/AnkiDroid/src/main/java/com/ichi2/anki/utils/Time.kt index 0483df1e3d78..80af6a661e1c 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/utils/Time.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/utils/Time.kt @@ -51,39 +51,39 @@ private const val TIME_YEAR = 12.0 * TIME_MONTH * @return The time quantity string. Something like "3 minutes left" or "2 hours left". */ fun remainingTime(context: Context, time_s: Long): String { - val time_x: Int // Time in unit x - val remaining_seconds: Int // Time not counted in the number in unit x + val timeX: Int // Time in unit x + val remainingSeconds: Int // Time not counted in the number in unit x val remaining: Int // Time in the unit smaller than x val res = context.resources return if (time_s < TIME_HOUR_LONG) { // get time remaining, but never less than 1 - time_x = max( + timeX = max( (time_s / TIME_MINUTE).roundToInt(), 1 ) - res.getQuantityString(R.plurals.reviewer_window_title, time_x, time_x) + res.getQuantityString(R.plurals.reviewer_window_title, timeX, timeX) // It used to be minutes only. So the word "minutes" is not // explicitly written in the ressource name. } else if (time_s < TIME_DAY_LONG) { - time_x = (time_s / TIME_HOUR_LONG).toInt() - remaining_seconds = (time_s % TIME_HOUR_LONG).toInt() + timeX = (time_s / TIME_HOUR_LONG).toInt() + remainingSeconds = (time_s % TIME_HOUR_LONG).toInt() remaining = - (remaining_seconds.toFloat() / TIME_MINUTE).roundToInt() + (remainingSeconds.toFloat() / TIME_MINUTE).roundToInt() res.getQuantityString( R.plurals.reviewer_window_title_hours_new, - time_x, - time_x, + timeX, + timeX, remaining ) } else { - time_x = (time_s / TIME_DAY_LONG).toInt() - remaining_seconds = (time_s.toFloat() % TIME_DAY_LONG).toInt() + timeX = (time_s / TIME_DAY_LONG).toInt() + remainingSeconds = (time_s.toFloat() % TIME_DAY_LONG).toInt() remaining = - (remaining_seconds / TIME_HOUR).roundToInt() + (remainingSeconds / TIME_HOUR).roundToInt() res.getQuantityString( R.plurals.reviewer_window_title_days_new, - time_x, - time_x, + timeX, + timeX, remaining ) } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt index adfaa2bb5d6f..9becf53108bb 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt @@ -20,8 +20,8 @@ package com.ichi2.libanki import androidx.annotation.VisibleForTesting import anki.cards.FsrsMemoryState import com.ichi2.anki.utils.ext.ifZero -import com.ichi2.libanki.Consts.CARD_QUEUE -import com.ichi2.libanki.Consts.CARD_TYPE +import com.ichi2.libanki.Consts.CardQueue +import com.ichi2.libanki.Consts.CardType import com.ichi2.libanki.TemplateManager.TemplateRenderContext.TemplateRenderOutput import com.ichi2.libanki.utils.LibAnkiAlias import com.ichi2.libanki.utils.NotInLibAnki @@ -75,12 +75,12 @@ open class Card : Cloneable { var mod: Long = 0 private var usn = 0 - @get:CARD_TYPE - @CARD_TYPE + @get:CardType + @CardType var type = 0 - @get:CARD_QUEUE - @CARD_QUEUE + @get:CardQueue + @CardQueue var queue = 0 var due: Int = 0 var ivl = 0 diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt index aec72a8bd187..7d040fa11731 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt @@ -210,8 +210,8 @@ class Collection( fun reopen(afterFullSync: Boolean = false): Boolean { Timber.i("(Re)opening Database: %s", path) return if (dbClosed) { - val (db_, created) = Storage.openDB(path, backend, afterFullSync) - dbInternal = db_ + val (database, created) = Storage.openDB(path, backend, afterFullSync) + dbInternal = database load() if (afterFullSync) { _loadScheduler() diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt index 5d389080aa52..2bf49224a917 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt @@ -31,7 +31,7 @@ object Consts { @Retention(AnnotationRetention.SOURCE) @IntDef(QUEUE_TYPE_MANUALLY_BURIED, QUEUE_TYPE_SIBLING_BURIED, QUEUE_TYPE_SUSPENDED, QUEUE_TYPE_NEW, QUEUE_TYPE_LRN, QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN, QUEUE_TYPE_PREVIEW) - annotation class CARD_QUEUE + annotation class CardQueue // Card types const val CARD_TYPE_NEW = 0 @@ -41,7 +41,7 @@ object Consts { @Retention(AnnotationRetention.SOURCE) @IntDef(CARD_TYPE_NEW, CARD_TYPE_LRN, CARD_TYPE_REV, CARD_TYPE_RELEARNING) - annotation class CARD_TYPE + annotation class CardType // dynamic deck order const val DYN_OLDEST = 0 @@ -57,7 +57,7 @@ object Consts { @Retention(AnnotationRetention.SOURCE) @IntDef(DYN_OLDEST, DYN_RANDOM, DYN_SMALLINT, DYN_BIGINT, DYN_LAPSES, DYN_ADDED, DYN_DUE, DYN_REVADDED, DYN_DUEPRIORITY) - annotation class DYN_PRIORITY + annotation class DynPriority // model types const val MODEL_STD = 0 @@ -65,7 +65,7 @@ object Consts { @Retention(AnnotationRetention.SOURCE) @IntDef(MODEL_STD, MODEL_CLOZE) - annotation class MODEL_TYPE + annotation class ModelType const val STARTING_FACTOR = 2500 @@ -85,7 +85,7 @@ object Consts { @Retention(AnnotationRetention.SOURCE) @IntDef(BUTTON_ONE, BUTTON_TWO, BUTTON_THREE, BUTTON_FOUR) - annotation class BUTTON_TYPE + annotation class ButtonType // The labels defined in consts.py are in AnkiDroid's resources files. const val DEFAULT_DECK_ID: Long = 1 diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/NotetypeJson.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/NotetypeJson.kt index 6d7df733fcee..ad47812be4ed 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/NotetypeJson.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/NotetypeJson.kt @@ -131,7 +131,7 @@ class NotetypeJson : JSONObject { } // TODO: Not constrained - @Consts.MODEL_TYPE + @Consts.ModelType var type: Int get() = getInt("type") set(value) { diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt index 59b82724bbdb..f3f16fa1f155 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt @@ -363,9 +363,9 @@ class Notetypes(val col: Collection) { } @LibAnkiAlias("rename_field") - fun renameField(notetype: NotetypeJson, field: Field, new_name: String) { + fun renameField(notetype: NotetypeJson, field: Field, newName: String) { assert(notetype.flds.jsonObjectIterable().contains(field)) - field["name"] = new_name + field["name"] = newName } /** Modifies schema. */ @@ -634,11 +634,11 @@ class Notetypes(val col: Collection) { companion object { const val NOT_FOUND_NOTE_TYPE = -1L - fun newTemplate(name: String): JSONObject = JSONObject(defaultTemplate).also { + fun newTemplate(name: String): JSONObject = JSONObject(DEFAULT_TEMPLATE).also { it.put("name", name) } - private const val defaultTemplate = + private const val DEFAULT_TEMPLATE = ( "{\"name\": \"\", " + "\"ord\": null, " + "\"qfmt\": \"\", " + "\"afmt\": \"\", " + "\"did\": null, " + "\"bqfmt\": \"\"," + "\"bafmt\": \"\"," + "\"bfont\": \"\"," + diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/exception/ConfirmModSchemaException.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/exception/ConfirmModSchemaException.kt index 17651ad08ae7..b8faab965316 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/exception/ConfirmModSchemaException.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/exception/ConfirmModSchemaException.kt @@ -31,6 +31,6 @@ class ConfirmModSchemaException : Exception() { /** * */ - private const val serialVersionUID = -9215098969154590797L + private const val SERIAL_VERSION_UID = -9215098969154590797L } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt index 27c1a1ef8e30..b51bb4dfc977 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt @@ -293,7 +293,7 @@ open class Scheduler(val col: Collection) { /** * Bury all cards for note until next session. - * @param nid The id of the targeted note. + * @param nids The id of the targeted note. */ open fun buryNotes(nids: List): OpChangesWithCount { return col.backend.buryOrSuspendCards( @@ -684,7 +684,7 @@ open class Scheduler(val col: Collection) { * @param ease The button number (easy, good etc.) * @return A string like “1 min” or “1.7 mo” */ - open fun nextIvlStr(card: Card, @Consts.BUTTON_TYPE ease: Int): String { + open fun nextIvlStr(card: Card, @Consts.ButtonType ease: Int): String { val secs = nextIvl(card, ease) return col.backend.formatTimespan(secs.toFloat(), FormatTimespanRequest.Context.ANSWER_BUTTONS) } diff --git a/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt b/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt index 36243cd08be7..0005a29faead 100644 --- a/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt +++ b/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt @@ -48,7 +48,7 @@ import java.util.Locale object ImportUtils { /* A filename should be shortened if over this threshold */ - private const val fileNameShorteningThreshold = 100 + private const val FILE_NAME_SHORTENING_THRESHOLD = 100 /** * This code is used in multiple places to handle package imports @@ -236,13 +236,13 @@ object ImportUtils { // #6137 - filenames can be too long when URLEncoded return try { val encoded = URLEncoder.encode(fileName, "UTF-8") - if (encoded.length <= fileNameShorteningThreshold) { + if (encoded.length <= FILE_NAME_SHORTENING_THRESHOLD) { Timber.d("No filename truncation necessary") fileName } else { - Timber.d("Filename was longer than %d, shortening", fileNameShorteningThreshold) + Timber.d("Filename was longer than %d, shortening", FILE_NAME_SHORTENING_THRESHOLD) // take 90 instead of 100 so we don't get the extension - val substringLength = fileNameShorteningThreshold - 10 + val substringLength = FILE_NAME_SHORTENING_THRESHOLD - 10 val shortenedFileName = encoded.substring(0, substringLength) + "..." + getExtension(fileName) Timber.d("Shortened filename '%s' to '%s'", fileName, shortenedFileName) // if we don't decode, % is double-encoded diff --git a/AnkiDroid/src/main/java/com/ichi2/utils/TagsUtil.kt b/AnkiDroid/src/main/java/com/ichi2/utils/TagsUtil.kt index 1cf4327ee67e..14165bd6b2d3 100644 --- a/AnkiDroid/src/main/java/com/ichi2/utils/TagsUtil.kt +++ b/AnkiDroid/src/main/java/com/ichi2/utils/TagsUtil.kt @@ -34,7 +34,7 @@ object TagsUtil { return updated } - private const val blankSubstituent = "blank" + private const val BLANK_SUBSTITUENT = "blank" /** * Utility method that decomposes a hierarchy tag into several parts. @@ -44,7 +44,7 @@ object TagsUtil { val parts = tag.split("::").asSequence() return parts.map { // same as the way Anki Desktop deals with an empty tag subpart - it.ifEmpty { blankSubstituent } + it.ifEmpty { BLANK_SUBSTITUENT } }.toList() } @@ -54,7 +54,7 @@ object TagsUtil { */ fun getUniformedTag(tag: String): String { val parts = getTagParts(tag) - return if (tag.endsWith("::") && parts.last() == blankSubstituent) { + return if (tag.endsWith("::") && parts.last() == BLANK_SUBSTITUENT) { parts.subList(0, parts.size - 1) } else { parts diff --git a/AnkiDroid/src/main/java/com/ichi2/widget/cardanalysis/CardAnalysisWidgetConfig.kt b/AnkiDroid/src/main/java/com/ichi2/widget/cardanalysis/CardAnalysisWidgetConfig.kt index 95acb45cfe49..a88f0402ef72 100644 --- a/AnkiDroid/src/main/java/com/ichi2/widget/cardanalysis/CardAnalysisWidgetConfig.kt +++ b/AnkiDroid/src/main/java/com/ichi2/widget/cardanalysis/CardAnalysisWidgetConfig.kt @@ -60,14 +60,9 @@ class CardAnalysisWidgetConfig : AnkiActivity(), DeckSelectionListener, BaseSnac lateinit var deckAdapter: WidgetConfigScreenAdapter private lateinit var cardAnalysisWidgetPreferences: CardAnalysisWidgetPreferences - /** - * Maximum number of decks allowed in the widget. - */ - private val MAX_DECKS_ALLOWED = 1 private var hasUnsavedChanges = false private var isAdapterObserverRegistered = false private lateinit var onBackPressedCallback: OnBackPressedCallback - private val EXTRA_SELECTED_DECK_IDS = "card_analysis_widget_selected_deck_ids" /** Tracks coroutine running [initializeUIComponents]: must be run on a non-empty collection */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) @@ -352,6 +347,14 @@ class CardAnalysisWidgetConfig : AnkiActivity(), DeckSelectionListener, BaseSnac cardAnalysisWidgetPreferences.deleteDeckData(appWidgetId) } } + + companion object { + /** + * Maximum number of decks allowed in the widget. + */ + private const val MAX_DECKS_ALLOWED = 1 + private const val EXTRA_SELECTED_DECK_IDS = "card_analysis_widget_selected_deck_ids" + } } fun ContextWrapper.unregisterReceiverSilently(receiver: BroadcastReceiver) { diff --git a/AnkiDroid/src/main/java/com/ichi2/widget/deckpicker/DeckPickerWidgetConfig.kt b/AnkiDroid/src/main/java/com/ichi2/widget/deckpicker/DeckPickerWidgetConfig.kt index 48c0c6bc20da..0bfbf1986dc6 100644 --- a/AnkiDroid/src/main/java/com/ichi2/widget/deckpicker/DeckPickerWidgetConfig.kt +++ b/AnkiDroid/src/main/java/com/ichi2/widget/deckpicker/DeckPickerWidgetConfig.kt @@ -65,10 +65,6 @@ class DeckPickerWidgetConfig : AnkiActivity(), DeckSelectionListener, BaseSnackb lateinit var deckAdapter: WidgetConfigScreenAdapter private lateinit var deckPickerWidgetPreferences: DeckPickerWidgetPreferences - /** - * Maximum number of decks allowed in the widget. - */ - private val MAX_DECKS_ALLOWED = 5 private var hasUnsavedChanges = false private var isAdapterObserverRegistered = false private lateinit var onBackPressedCallback: OnBackPressedCallback @@ -442,6 +438,12 @@ class DeckPickerWidgetConfig : AnkiActivity(), DeckSelectionListener, BaseSnackb context?.let { deckPickerWidgetPreferences.deleteDeckData(appWidgetId) } } } + companion object { + /** + * Maximum number of decks allowed in the widget. + */ + private const val MAX_DECKS_ALLOWED = 5 + } } /** diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt index 07cd8f04b943..db71f3a72bb7 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt @@ -198,7 +198,7 @@ class NoteEditorTest : RobolectricTest() { } } - @Test() + @Test fun testHandleMultimediaActionsDisplaysBottomSheet() { val intent = NoteEditorLauncher.AddNote().getIntent(targetContext) ActivityScenario.launchActivityForResult(intent).use { scenario -> diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt index 5d57a5041a18..9fe2d609973c 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt @@ -93,7 +93,7 @@ class ReviewerTest : RobolectricTest() { val tags = listOf("tag1", "tag2") // Define an arbitrary filter - val ARBITRARY_FILTER = CardStateFilter.DUE + val arbitraryFilter = CardStateFilter.DUE // Assert that currentCard is not null before calling onSelectedTags assertNotNull("currentCard should not be null", viewer.currentCard) @@ -102,7 +102,7 @@ class ReviewerTest : RobolectricTest() { Timber.d("Before first call to onSelectedTags") // Call onSelectedTags method - viewer.onSelectedTags(tags, emptyList(), ARBITRARY_FILTER) + viewer.onSelectedTags(tags, emptyList(), arbitraryFilter) Timber.d("After first call to onSelectedTags") @@ -112,7 +112,7 @@ class ReviewerTest : RobolectricTest() { Timber.d("Before second call to onSelectedTags") // Call onSelectedTags method again - viewer.onSelectedTags(tags, emptyList(), ARBITRARY_FILTER) + viewer.onSelectedTags(tags, emptyList(), arbitraryFilter) Timber.d("After second call to onSelectedTags") diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsListTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsListTest.kt index fe1a62a8a29b..6e654a024f8c 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsListTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsListTest.kt @@ -494,7 +494,7 @@ class TagsListTest { "Need solution to only mock the sort() method." ) fun test_sort_will_not_call_collectionsSort() { - Mockito.mockStatic(Collections::class.java).use { MockCollection -> + Mockito.mockStatic(Collections::class.java).use { mockCollection -> assertEquals(TAGS, tagsList.copyOfAllTagList()) tagsList.sort() @@ -504,7 +504,7 @@ class TagsListTest { tagsList.copyOfAllTagList() ) - MockCollection.verify({ Collections.sort(ArgumentMatchers.any(), ArgumentMatchers.any>()) }, Mockito.never()) + mockCollection.verify({ Collections.sort(ArgumentMatchers.any(), ArgumentMatchers.any>()) }, Mockito.never()) } } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/preferences/PreferencesSimpleTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/PreferencesSimpleTest.kt index 41715499927c..bcedeab709ed 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/preferences/PreferencesSimpleTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/PreferencesSimpleTest.kt @@ -30,8 +30,8 @@ import java.util.stream.Stream class PreferencesSimpleTest { @ParameterizedTest @MethodSource("buildCategorySummary_LTR_Test_args") - fun buildCategorySummary_LTR_Test(entries: Array, expected_summary: String) { - assertThat(HeaderPreference.buildHeaderSummary(*entries), equalTo(expected_summary)) + fun buildCategorySummary_LTR_Test(entries: Array, expectedSummary: String) { + assertThat(HeaderPreference.buildHeaderSummary(*entries), equalTo(expectedSummary)) } companion object { diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingAndroidTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingAndroidTest.kt index bd5ead0696e4..5a2cbe1bebff 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingAndroidTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingAndroidTest.kt @@ -35,23 +35,23 @@ class BindingAndroidTest : RobolectricTest() { @Test fun testKeycodeToString() { // These use native functions. We may need KeyEvent.keyCodeToString - assertEquals(BindingTest.keyPrefix + "87", Binding.keyCode(KeyEvent.KEYCODE_MEDIA_NEXT).toString()) - assertEquals(BindingTest.keyPrefix + "Ctrl+88", Binding.keyCode(ctrl(), KeyEvent.KEYCODE_MEDIA_PREVIOUS).toString()) - assertEquals(BindingTest.keyPrefix + "Shift+25", Binding.keyCode(shift(), KeyEvent.KEYCODE_VOLUME_DOWN).toString()) - assertEquals(BindingTest.keyPrefix + "Alt+24", Binding.keyCode(alt(), KeyEvent.KEYCODE_VOLUME_UP).toString()) + assertEquals(BindingTest.KEY_PREFIX + "87", Binding.keyCode(KeyEvent.KEYCODE_MEDIA_NEXT).toString()) + assertEquals(BindingTest.KEY_PREFIX + "Ctrl+88", Binding.keyCode(ctrl(), KeyEvent.KEYCODE_MEDIA_PREVIOUS).toString()) + assertEquals(BindingTest.KEY_PREFIX + "Shift+25", Binding.keyCode(shift(), KeyEvent.KEYCODE_VOLUME_DOWN).toString()) + assertEquals(BindingTest.KEY_PREFIX + "Alt+24", Binding.keyCode(alt(), KeyEvent.KEYCODE_VOLUME_UP).toString()) } @Test fun testFromString() { - assertBindingEquals(Binding.unicode('Ä'), Binding.fromString(BindingTest.unicodePrefix + "Ä")) - assertBindingEquals(Binding.unicode(ctrl(), 'Ä'), Binding.fromString(BindingTest.unicodePrefix + "Ctrl+Ä")) - assertBindingEquals(Binding.unicode(shift(), 'Ä'), Binding.fromString(BindingTest.unicodePrefix + "Shift+Ä")) - assertBindingEquals(Binding.unicode(alt(), 'Ä'), Binding.fromString(BindingTest.unicodePrefix + "Alt+Ä")) - assertBindingEquals(Binding.keyCode(KeyEvent.KEYCODE_MEDIA_NEXT), Binding.fromString(BindingTest.keyPrefix + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_MEDIA_NEXT))) - assertBindingEquals(Binding.keyCode(ctrl(), KeyEvent.KEYCODE_MEDIA_PREVIOUS), Binding.fromString(BindingTest.keyPrefix + "Ctrl+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_MEDIA_PREVIOUS))) - assertBindingEquals(Binding.keyCode(shift(), KeyEvent.KEYCODE_VOLUME_DOWN), Binding.fromString(BindingTest.keyPrefix + "Shift+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_VOLUME_DOWN))) - assertBindingEquals(Binding.keyCode(alt(), KeyEvent.KEYCODE_VOLUME_UP), Binding.fromString(BindingTest.keyPrefix + "Alt+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_VOLUME_UP))) - assertBindingEquals(Binding.gesture(Gesture.TAP_TOP), Binding.fromString(BindingTest.gesturePrefix + Gesture.TAP_TOP.name)) + assertBindingEquals(Binding.unicode('Ä'), Binding.fromString(BindingTest.UNICODE_PREFIX + "Ä")) + assertBindingEquals(Binding.unicode(ctrl(), 'Ä'), Binding.fromString(BindingTest.UNICODE_PREFIX + "Ctrl+Ä")) + assertBindingEquals(Binding.unicode(shift(), 'Ä'), Binding.fromString(BindingTest.UNICODE_PREFIX + "Shift+Ä")) + assertBindingEquals(Binding.unicode(alt(), 'Ä'), Binding.fromString(BindingTest.UNICODE_PREFIX + "Alt+Ä")) + assertBindingEquals(Binding.keyCode(KeyEvent.KEYCODE_MEDIA_NEXT), Binding.fromString(BindingTest.KEY_PREFIX + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_MEDIA_NEXT))) + assertBindingEquals(Binding.keyCode(ctrl(), KeyEvent.KEYCODE_MEDIA_PREVIOUS), Binding.fromString(BindingTest.KEY_PREFIX + "Ctrl+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_MEDIA_PREVIOUS))) + assertBindingEquals(Binding.keyCode(shift(), KeyEvent.KEYCODE_VOLUME_DOWN), Binding.fromString(BindingTest.KEY_PREFIX + "Shift+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_VOLUME_DOWN))) + assertBindingEquals(Binding.keyCode(alt(), KeyEvent.KEYCODE_VOLUME_UP), Binding.fromString(BindingTest.KEY_PREFIX + "Alt+" + KeyEvent.keyCodeToString(KeyEvent.KEYCODE_VOLUME_UP))) + assertBindingEquals(Binding.gesture(Gesture.TAP_TOP), Binding.fromString(BindingTest.GESTURE_PREFIX + Gesture.TAP_TOP.name)) } @Test @@ -63,7 +63,7 @@ class BindingAndroidTest : RobolectricTest() { @Test @Config(qualifiers = "en") fun gesture_toDisplayString() { - assertEquals("${BindingTest.gesturePrefix} Touch top", Binding.gesture(Gesture.TAP_TOP).toDisplayString()) + assertEquals("${BindingTest.GESTURE_PREFIX} Touch top", Binding.gesture(Gesture.TAP_TOP).toDisplayString()) } private fun Binding.toDisplayString(): String { @@ -80,4 +80,4 @@ class BindingAndroidTest : RobolectricTest() { private fun axis(axis: Axis, fl: Float) = Binding.AxisButtonBinding(axis, fl) private fun axisBindingFromString(suffix: String) = - Binding.fromString(BindingTest.joystickPrefix + suffix) + Binding.fromString(BindingTest.JOYSTICK_PREFIX + suffix) diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingTest.kt index 89a140ca3b14..04cf3e602bf6 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/reviewer/BindingTest.kt @@ -51,16 +51,16 @@ class BindingTest { @Test fun testUnicodeToString() { - assertEquals(unicodePrefix + "Ä", Binding.unicode('Ä').toString()) - assertEquals(unicodePrefix + "Ctrl+Ä", Binding.unicode(Binding.ModifierKeys.ctrl(), 'Ä').toString()) - assertEquals(unicodePrefix + "Shift+Ä", Binding.unicode(Binding.ModifierKeys.shift(), 'Ä').toString()) - assertEquals(unicodePrefix + "Alt+Ä", Binding.unicode(Binding.ModifierKeys.alt(), 'Ä').toString()) - assertEquals(unicodePrefix + "Ctrl+Alt+Shift+Ä", Binding.unicode(allModifierKeys(), 'Ä').toString()) + assertEquals(UNICODE_PREFIX + "Ä", Binding.unicode('Ä').toString()) + assertEquals(UNICODE_PREFIX + "Ctrl+Ä", Binding.unicode(Binding.ModifierKeys.ctrl(), 'Ä').toString()) + assertEquals(UNICODE_PREFIX + "Shift+Ä", Binding.unicode(Binding.ModifierKeys.shift(), 'Ä').toString()) + assertEquals(UNICODE_PREFIX + "Alt+Ä", Binding.unicode(Binding.ModifierKeys.alt(), 'Ä').toString()) + assertEquals(UNICODE_PREFIX + "Ctrl+Alt+Shift+Ä", Binding.unicode(allModifierKeys(), 'Ä').toString()) } @Test fun testGestureToString() { - assertEquals(gesturePrefix + "TAP_TOP", Binding.gesture(Gesture.TAP_TOP).toString()) + assertEquals(GESTURE_PREFIX + "TAP_TOP", Binding.gesture(Gesture.TAP_TOP).toString()) } @Test @@ -88,10 +88,10 @@ class BindingTest { } companion object { - const val gesturePrefix = '\u235D' - const val keyPrefix = '\u2328' - const val unicodePrefix = '\u2705' - const val joystickPrefix = '◯' + const val GESTURE_PREFIX = '\u235D' + const val KEY_PREFIX = '\u2328' + const val UNICODE_PREFIX = '\u2705' + const val JOYSTICK_PREFIX = '◯' fun allModifierKeys() = Binding.ModifierKeys(shift = true, ctrl = true, alt = true) fun unicodeCharacter(c: Char): Binding.UnicodeCharacter { diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTest.kt index 787649f563c7..3d9b16584944 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTest.kt @@ -23,7 +23,7 @@ import com.ichi2.anki.reviewer.Binding.Companion.keyCode import com.ichi2.anki.reviewer.CardSide import com.ichi2.anki.reviewer.MappableBinding import com.ichi2.anki.reviewer.MappableBinding.Screen.Reviewer -import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.Companion.upgradeVersionPrefKey +import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.Companion.UPGRADE_VERSION_PREF_KEY import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.UpgradeGesturesToControls import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.CoreMatchers.not @@ -72,7 +72,7 @@ class UpgradeGesturesToControlsTest(private val testData: TestData) : Robolectri upgradeAllGestures() - assertThat(changedKeys, Matchers.containsInAnyOrder(upgradeVersionPrefKey, testData.affectedPreferenceKey, command.preferenceKey)) + assertThat(changedKeys, Matchers.containsInAnyOrder(UPGRADE_VERSION_PREF_KEY, testData.affectedPreferenceKey, command.preferenceKey)) assertThat("legacy preference removed", prefs.contains(testData.affectedPreferenceKey), equalTo(false)) assertThat("new preference added", prefs.contains(command.preferenceKey), equalTo(true)) @@ -101,7 +101,7 @@ class UpgradeGesturesToControlsTest(private val testData: TestData) : Robolectri upgradeAllGestures() - assertThat(changedKeys, Matchers.containsInAnyOrder(upgradeVersionPrefKey, testData.affectedPreferenceKey, command.preferenceKey)) + assertThat(changedKeys, Matchers.containsInAnyOrder(UPGRADE_VERSION_PREF_KEY, testData.affectedPreferenceKey, command.preferenceKey)) assertThat("legacy preference removed", prefs.contains(testData.affectedPreferenceKey), equalTo(false)) assertThat("new preference exists", prefs.contains(command.preferenceKey), equalTo(true)) @@ -139,7 +139,7 @@ class UpgradeGesturesToControlsTest(private val testData: TestData) : Robolectri upgradeAllGestures() - assertThat("Binding gestures should not be changed", changedKeys, Matchers.contains(upgradeVersionPrefKey, testData.affectedPreferenceKey)) + assertThat("Binding gestures should not be changed", changedKeys, Matchers.contains(UPGRADE_VERSION_PREF_KEY, testData.affectedPreferenceKey)) assertThat("legacy preference removed", prefs.contains(testData.affectedPreferenceKey), equalTo(false)) assertThat("new preference still exists", prefs.contains(command.preferenceKey), equalTo(true)) @@ -151,7 +151,7 @@ class UpgradeGesturesToControlsTest(private val testData: TestData) : Robolectri upgradeAllGestures() - assertThat("Binding gestures should not be changed", changedKeys, Matchers.contains(upgradeVersionPrefKey, testData.affectedPreferenceKey)) + assertThat("Binding gestures should not be changed", changedKeys, Matchers.contains(UPGRADE_VERSION_PREF_KEY, testData.affectedPreferenceKey)) assertThat("legacy preference removed", prefs.contains(testData.affectedPreferenceKey), equalTo(false)) } @@ -163,7 +163,7 @@ class UpgradeGesturesToControlsTest(private val testData: TestData) : Robolectri upgradeAllGestures() - assertThat("Binding gestures should not be changed", changedKeys, Matchers.containsInAnyOrder(upgradeVersionPrefKey, testData.affectedPreferenceKey)) + assertThat("Binding gestures should not be changed", changedKeys, Matchers.containsInAnyOrder(UPGRADE_VERSION_PREF_KEY, testData.affectedPreferenceKey)) assertThat("legacy preference removed", prefs.contains(testData.affectedPreferenceKey), equalTo(false)) } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTestNoParam.kt b/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTestNoParam.kt index 0a54e932fc5d..57d44f0e28ef 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTestNoParam.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/servicemodel/UpgradeGesturesToControlsTestNoParam.kt @@ -19,7 +19,7 @@ import android.content.SharedPreferences import androidx.core.content.edit import androidx.test.ext.junit.runners.AndroidJUnit4 import com.ichi2.anki.RobolectricTest -import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.Companion.upgradeVersionPrefKey +import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.Companion.UPGRADE_VERSION_PREF_KEY import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.UpgradeGesturesToControls import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat @@ -61,7 +61,7 @@ class UpgradeGesturesToControlsTestNoParam : RobolectricTest() { upgradeAllGestures() // ensure that no settings were added to the preferences - assertThat(changedKeys, Matchers.contains(upgradeVersionPrefKey)) + assertThat(changedKeys, Matchers.contains(UPGRADE_VERSION_PREF_KEY)) } @Test @@ -78,7 +78,7 @@ class UpgradeGesturesToControlsTestNoParam : RobolectricTest() { upgradeAllGestures() // ensure that no settings were added to the preferences - assertThat(changedKeys, Matchers.contains(upgradeVersionPrefKey, PREF_KEY_VOLUME_DOWN, PREF_KEY_VOLUME_UP)) + assertThat(changedKeys, Matchers.contains(UPGRADE_VERSION_PREF_KEY, PREF_KEY_VOLUME_DOWN, PREF_KEY_VOLUME_UP)) assertThat("Volume gestures are removed", prefs.contains(PREF_KEY_VOLUME_DOWN), equalTo(false)) assertThat("Volume gestures are removed", prefs.contains(PREF_KEY_VOLUME_UP), equalTo(false)) diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/TagsTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/TagsTest.kt index c39dc914a2da..cf81723b6e8e 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/TagsTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/TagsTest.kt @@ -30,19 +30,19 @@ class TagsTest : JvmTest() { @Test fun test_split() { val tags = Tags(col) - val tags_list1 = ArrayList() - tags_list1.add("Todo") - tags_list1.add("todo") - tags_list1.add("Needs revision") + val tagsList1 = ArrayList() + tagsList1.add("Todo") + tagsList1.add("todo") + tagsList1.add("Needs revision") - val tags_list2 = ArrayList() - tags_list2.add("Todo") - tags_list2.add("todo") - tags_list2.add("Needs") - tags_list2.add("Revision") + val tagsList2 = ArrayList() + tagsList2.add("Todo") + tagsList2.add("todo") + tagsList2.add("Needs") + tagsList2.add("Revision") - assertNotEquals(tags_list1, tags.split("Todo todo Needs Revision")) - assertEquals(tags_list2, tags.split("Todo todo Needs Revision")) + assertNotEquals(tagsList1, tags.split("Todo todo Needs Revision")) + assertEquals(tagsList2, tags.split("Todo todo Needs Revision")) assertEquals(0, tags.split("").size) } @@ -50,16 +50,16 @@ class TagsTest : JvmTest() { fun test_in_list() { val tags = Tags(col) - val tags_list = ArrayList() - tags_list.add("Todo") - tags_list.add("Needs revision") - tags_list.add("Once more") - tags_list.add("test1 content") + val tagsList = ArrayList() + tagsList.add("Todo") + tagsList.add("Needs revision") + tagsList.add("Once more") + tagsList.add("test1 content") - assertFalse(tags.inList("Done", tags_list)) - assertTrue(tags.inList("Needs revision", tags_list)) - assertTrue(tags.inList("once More", tags_list)) - assertFalse(tags.inList("test1Content", tags_list)) + assertFalse(tags.inList("Done", tagsList)) + assertTrue(tags.inList("Needs revision", tagsList)) + assertTrue(tags.inList("once More", tagsList)) + assertFalse(tags.inList("test1Content", tagsList)) assertFalse(tags.inList("", ArrayList())) } } diff --git a/AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt b/AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt index 06d0ba95e427..ce90f6b7b8c7 100644 --- a/AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt @@ -51,13 +51,13 @@ open class JvmTest : TestClass { override val col: Collection get() { - if (col_ == null) { - col_ = CollectionManager.getColUnsafe() + if (_col == null) { + _col = CollectionManager.getColUnsafe() } - return col_!! + return _col!! } - private var col_: Collection? = null + private var _col: Collection? = null @Before @CallSuper @@ -90,7 +90,7 @@ open class JvmTest : TestClass { open fun tearDown() { try { // If you don't tear down the database you'll get unexpected IllegalStateExceptions related to connections - col_?.close() + _col?.close() } catch (ex: BackendException) { if ("CollectionNotOpen" == ex.message) { Timber.w(ex, "Collection was already disposed - may have been a problem") @@ -100,7 +100,7 @@ open class JvmTest : TestClass { } finally { TimeManager.reset() } - col_ = null + _col = null Dispatchers.resetMain() runBlocking { CollectionManager.discardBackend() } Timber.uprootAll() diff --git a/AnkiDroid/src/test/java/com/ichi2/utils/UniqueArrayListTest.kt b/AnkiDroid/src/test/java/com/ichi2/utils/UniqueArrayListTest.kt index 0d2ae6ba26a3..957e0643ade6 100644 --- a/AnkiDroid/src/test/java/com/ichi2/utils/UniqueArrayListTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/utils/UniqueArrayListTest.kt @@ -87,12 +87,12 @@ class UniqueArrayListTest { val sorted: ArrayList = ArrayList(longs) sorted.sort() - mockStatic(Collections::class.java).use { MockCollection -> + mockStatic(Collections::class.java).use { mockCollection -> val uniqueList = UniqueArrayList.from(longs) uniqueList.sort() assertListEquals(sorted, uniqueList) - MockCollection.verify({ Collections.sort(any(), any>()) }, never()) + mockCollection.verify({ Collections.sort(any(), any>()) }, never()) } } diff --git a/api/src/main/java/com/ichi2/anki/FlashCardsContract.kt b/api/src/main/java/com/ichi2/anki/FlashCardsContract.kt index 0a24f7923518..362a63f7a15b 100644 --- a/api/src/main/java/com/ichi2/anki/FlashCardsContract.kt +++ b/api/src/main/java/com/ichi2/anki/FlashCardsContract.kt @@ -226,7 +226,7 @@ public object FlashCardsContract { * used for accessing the data of a note using the URI * "content://com.ichi2.anki.flashcards/notes//data */ - @Suppress("ObjectPropertyName") + @Suppress("ConstPropertyName") public const val _ID: String = "_id" // field is part of the default projection available to the clients @@ -361,7 +361,7 @@ public object FlashCardsContract { * used for accessing the data of the model using the URI * `content://com.ichi2.anki.flashcards/models/` */ - @Suppress("ObjectPropertyName") + @Suppress("ConstPropertyName") public const val _ID: String = "_id" public const val NAME: String = "name" public const val FIELD_NAME: String = "field_name" @@ -426,7 +426,7 @@ public object FlashCardsContract { * reliably over subsequent queries. Especially if the number of cards or fields changes, * the _ID will change too. */ - @Suppress("ObjectPropertyName") + @Suppress("ConstPropertyName") public const val _ID: String = "_id" /** diff --git a/api/src/test/java/com/ichi2/anki/api/ApiUtilsTest.kt b/api/src/test/java/com/ichi2/anki/api/ApiUtilsTest.kt index 8dcfa2d6e926..1ba439e34e06 100644 --- a/api/src/test/java/com/ichi2/anki/api/ApiUtilsTest.kt +++ b/api/src/test/java/com/ichi2/anki/api/ApiUtilsTest.kt @@ -23,7 +23,7 @@ internal class ApiUtilsTest { @Test fun joinFieldsShouldJoinWhenListIsValid() { val fieldList = arrayOf("A", "B", "C") - assertEquals("A" + delimiter + "B" + delimiter + "C", Utils.joinFields(fieldList)) + assertEquals("A" + DELIMITER + "B" + DELIMITER + "C", Utils.joinFields(fieldList)) } @Test @@ -33,7 +33,7 @@ internal class ApiUtilsTest { @Test fun splitFieldsShouldSplitRightWhenStringIsValid() { - val fieldList = "A" + delimiter + "B" + delimiter + "C" + val fieldList = "A" + DELIMITER + "B" + DELIMITER + "C" val output = Utils.splitFields(fieldList) assertEquals("A", output[0]) assertEquals("B", output[1]) @@ -72,6 +72,6 @@ internal class ApiUtilsTest { companion object { // We need to keep a copy because a change to Utils.FIELD_SEPARATOR should break the tests - private const val delimiter = "\u001F" + private const val DELIMITER = "\u001F" } }