Skip to content

Commit

Permalink
Replace AbstractFlashcardViewer references in api module with copy of…
Browse files Browse the repository at this point in the history
… Ease constants

Addresses issue #17021
  • Loading branch information
benwicks authored and lukstbit committed Oct 3, 2024
1 parent 57a1e86 commit f6338a3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
3 changes: 3 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Ease.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.ichi2.anki

/**
* [value] should be kept in sync with the [com.ichi2.anki.api.Ease] enum.
*/
enum class Ease(val value: Int) {
AGAIN(1),
HARD(2),
Expand Down
31 changes: 31 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/anki/EaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Ben Wicks <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ichi2.anki

import org.junit.Assert.assertEquals
import org.junit.Test

class EaseTest {
@Test
fun `Ease enum values match api module`() {
assertEquals(Ease.AGAIN.value, com.ichi2.anki.api.Ease.EASE_1.value)
assertEquals(Ease.HARD.value, com.ichi2.anki.api.Ease.EASE_2.value)
assertEquals(Ease.GOOD.value, com.ichi2.anki.api.Ease.EASE_3.value)
assertEquals(Ease.EASY.value, com.ichi2.anki.api.Ease.EASE_4.value)
assertEquals(Ease.entries.size, com.ichi2.anki.api.Ease.entries.size)
}
}
15 changes: 8 additions & 7 deletions api/src/main/java/com/ichi2/anki/FlashCardsContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.ichi2.anki

import android.net.Uri
import com.ichi2.anki.api.BuildConfig
import com.ichi2.anki.api.Ease

/**
* The contract between AnkiDroid and applications. Contains definitions for the supported URIs and
Expand Down Expand Up @@ -688,10 +689,10 @@ public object FlashCardsContract {
* JSONArray | MEDIA_FILES | read-only | The media files, like images and sound files, contained in the cards.
* --------------------------------------------------------------------------------------------------------------------
* String | EASE | write-only | The ease of the card. Used when answering the card. One of:
* | | | com.ichi2.anki.AbstractFlashcardViewer.EASE_1
* | | | com.ichi2.anki.AbstractFlashcardViewer.EASE_2
* | | | com.ichi2.anki.AbstractFlashcardViewer.EASE_3
* | | | com.ichi2.anki.AbstractFlashcardViewer.EASE_4
* | | | com.ichi2.anki.api.Ease.EASE_1.value
* | | | com.ichi2.anki.api.Ease.EASE_2.value
* | | | com.ichi2.anki.api.Ease.EASE_3.value
* | | | com.ichi2.anki.api.Ease.EASE_4.value
* --------------------------------------------------------------------------------------------------------------------
* String | TIME_TAKEN | write_only | The it took to answer the card (in milliseconds). Used when answering the card.
* --------------------------------------------------------------------------------------------------------------------
Expand All @@ -710,7 +711,7 @@ public object FlashCardsContract {
* ContentValues values = new ContentValues();
* long noteId = 123456789; //<-- insert real note id here
* int cardOrd = 0; //<-- insert real card ord here
* int ease = AbstractFlashcardViewer.EASE_3; //<-- insert real ease here
* int ease = Ease.EASE_3.value; //<-- insert real ease here
* long timeTaken = System.currentTimeMillis() - cardStartTime; //<-- insert real time taken here
*
* values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
Expand Down Expand Up @@ -772,9 +773,9 @@ public object FlashCardsContract {
*/
public const val MEDIA_FILES: String = "media_files"

/*
/**
* Ease of an answer. Is not set when requesting the scheduled cards.
* Can take values of AbstractFlashcardViewer e.g. EASE_1
* Can take values from the [Ease] enum e.g. [Ease.EASE_1.value].
*/
public const val EASE: String = "answer_ease"

Expand Down
24 changes: 24 additions & 0 deletions api/src/main/java/com/ichi2/anki/api/Ease.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Ben Wicks <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ichi2.anki.api

public enum class Ease(public val value: Int) {
EASE_1(1),
EASE_2(2),
EASE_3(3),
EASE_4(4);
}

0 comments on commit f6338a3

Please sign in to comment.