From 114d8acfb74c451f95c5716757ad5076c6ae6e3b Mon Sep 17 00:00:00 2001
From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com>
Date: Mon, 11 Dec 2023 21:10:03 -0300
Subject: [PATCH] add dev option to use the new previewer
the pending issue to solve before releasing to the public is handling audio
since right now there are a bunch of TTS work in progress, I'll defer audio handling to later
---
AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt | 6 +++++-
AnkiDroid/src/main/java/com/ichi2/anki/Previewer.kt | 10 ++++++++++
.../java/com/ichi2/anki/previewer/PreviewerActivity.kt | 4 ++--
AnkiDroid/src/main/res/values/preferences.xml | 1 +
AnkiDroid/src/main/res/xml/preferences_dev_options.xml | 4 ++++
5 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
index d2d658a46b0b..1d5ebc73d8a4 100644
--- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
@@ -1256,7 +1256,11 @@ open class CardBrowser :
}
private fun getPreviewIntent(index: Int, selectedCardIds: LongArray): Intent {
- return PreviewDestination(index, selectedCardIds).toIntent(this)
+ return if (sharedPrefs().getBoolean("new_previewer", false)) {
+ Previewer2Destination(index, selectedCardIds).toIntent(this)
+ } else {
+ PreviewDestination(index, selectedCardIds).toIntent(this)
+ }
}
private fun rescheduleSelectedCards() {
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Previewer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Previewer.kt
index 3c866ccdad47..ec480c577be8 100644
--- a/AnkiDroid/src/main/java/com/ichi2/anki/Previewer.kt
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/Previewer.kt
@@ -32,6 +32,7 @@ import androidx.annotation.VisibleForTesting
import com.ichi2.anki.cardviewer.Gesture
import com.ichi2.anki.cardviewer.PreviewLayout
import com.ichi2.anki.cardviewer.ViewerCommand
+import com.ichi2.anki.previewer.PreviewerActivity
import com.ichi2.libanki.Collection
import timber.log.Timber
@@ -282,7 +283,16 @@ class Previewer : AbstractFlashcardViewer() {
putExtra("index", index)
putExtra("cardList", cardList)
}
+
+ @CheckResult
+ fun Previewer2Destination.toIntent(context: Context) =
+ Intent(context, PreviewerActivity::class.java).apply {
+ putExtra(PreviewerActivity.CURRENT_INDEX_EXTRA, currentIndex)
+ putExtra(PreviewerActivity.CARD_IDS_EXTRA, selectedCardIds)
+ }
}
}
class PreviewDestination(val index: Int, val cardList: LongArray)
+
+class Previewer2Destination(val currentIndex: Int, val selectedCardIds: LongArray)
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerActivity.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerActivity.kt
index 0aca9852100d..f2c4f7cb780d 100644
--- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerActivity.kt
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerActivity.kt
@@ -218,8 +218,8 @@ class PreviewerActivity : AnkiActivity() {
}
companion object {
- private const val CURRENT_INDEX_EXTRA = "currentIndex"
- private const val CARD_IDS_EXTRA = "cardIds"
+ const val CURRENT_INDEX_EXTRA = "currentIndex"
+ const val CARD_IDS_EXTRA = "cardIds"
fun getIntent(context: Context, selectedCardIds: LongArray, currentIndex: Int): Intent {
return Intent(context, PreviewerActivity::class.java).apply {
diff --git a/AnkiDroid/src/main/res/values/preferences.xml b/AnkiDroid/src/main/res/values/preferences.xml
index cbfa3bafc575..236df9f75ef8 100644
--- a/AnkiDroid/src/main/res/values/preferences.xml
+++ b/AnkiDroid/src/main/res/values/preferences.xml
@@ -157,6 +157,7 @@
trigger_crash_preference
analytics_debug_preference
debug_lock_database
+ new_previewer
showOnboarding
resetOnboarding
devOptionsEnabledByUser
diff --git a/AnkiDroid/src/main/res/xml/preferences_dev_options.xml b/AnkiDroid/src/main/res/xml/preferences_dev_options.xml
index 28433fbeb93b..ce2449a3300e 100644
--- a/AnkiDroid/src/main/res/xml/preferences_dev_options.xml
+++ b/AnkiDroid/src/main/res/xml/preferences_dev_options.xml
@@ -44,6 +44,10 @@
android:title="Lock Database"
android:summary="Touch here to lock the database (all threads block in-process, exception if using second process)"
android:key="@string/pref_lock_database_key"/>
+