Skip to content

Commit

Permalink
feat: add new previewer developer option
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Dec 16, 2023
1 parent 988b12f commit 4d3f85e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import com.ichi2.anki.model.CardsOrNotes.*
import com.ichi2.anki.model.SortType
import com.ichi2.anki.pages.CardInfo.Companion.toIntent
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.previewer.PreviewerFragment
import com.ichi2.anki.receiver.SdCardReceiver
import com.ichi2.anki.servicelayer.NoteService.isMarked
import com.ichi2.anki.servicelayer.avgIntervalOfNote
Expand Down Expand Up @@ -1248,7 +1249,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() {
Expand Down Expand Up @@ -2355,3 +2360,9 @@ suspend fun searchForCards(
private fun Sequence<CardId>.toCardCache(col: com.ichi2.libanki.Collection, isInCardMode: CardsOrNotes): Sequence<CardBrowser.CardCache> {
return this.mapIndexed { idx, cid -> CardBrowser.CardCache(cid, col, idx, isInCardMode) }
}

class Previewer2Destination(val currentIndex: Int, val selectedCardIds: LongArray)

@CheckResult
fun Previewer2Destination.toIntent(context: Context) =
PreviewerFragment.getIntent(context, selectedCardIds, currentIndex)
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<string name="pref_trigger_crash_key">trigger_crash_preference</string>
<string name="pref_analytics_debug_key">analytics_debug_preference</string>
<string name="pref_lock_database_key">debug_lock_database</string>
<string name="new_previewer_pref_key">new_previewer</string>
<string name="pref_show_onboarding_key">showOnboarding</string>
<string name="pref_reset_onboarding_key">resetOnboarding</string>
<string name="dev_options_enabled_by_user_key">devOptionsEnabledByUser</string>
Expand Down
4 changes: 4 additions & 0 deletions AnkiDroid/src/main/res/xml/preferences_dev_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
<SwitchPreferenceCompat
android:title="New previewer"
android:key="@string/new_previewer_pref_key"
android:defaultValue="false"/>
<SwitchPreferenceCompat
android:title="@string/show_onboarding"
android:summary="@string/show_onboarding_desc"
Expand Down

0 comments on commit 4d3f85e

Please sign in to comment.