Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

6 changes: 3 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ModelFieldEditor :
fieldNameInput?.let { fieldNameInput ->
fieldNameInput.isSingleLine = true
AlertDialog.Builder(this).show {
customView(view = fieldNameInput, paddingLeft = 64, paddingRight = 64, paddingTop = 32)
customView(view = fieldNameInput, paddingStart = 64, paddingEnd = 64, paddingTop = 32)
title(R.string.model_field_editor_add)
positiveButton(R.string.dialog_ok) {
// Name is valid, now field is added
Expand Down Expand Up @@ -303,7 +303,7 @@ class ModelFieldEditor :
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, paddingStart = 64, paddingEnd = 64, paddingTop = 32)
title(R.string.model_field_editor_rename)
positiveButton(R.string.rename) {
if (uniqueName(fieldNameInput) == null) {
Expand Down Expand Up @@ -347,7 +347,7 @@ class ModelFieldEditor :
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, paddingStart = 64, paddingEnd = 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()
Expand Down
34 changes: 19 additions & 15 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ import com.ichi2.anki.reviewer.AnswerButtons.Companion.getBackgroundColors
import com.ichi2.anki.reviewer.AnswerButtons.Companion.getTextColors
import com.ichi2.anki.reviewer.AnswerTimer
import com.ichi2.anki.reviewer.AutomaticAnswerAction
import com.ichi2.anki.reviewer.Binding
import com.ichi2.anki.reviewer.BindingProcessor
import com.ichi2.anki.reviewer.CardMarker
import com.ichi2.anki.reviewer.CardSide
import com.ichi2.anki.reviewer.FullScreenMode
import com.ichi2.anki.reviewer.FullScreenMode.Companion.fromPreference
import com.ichi2.anki.reviewer.FullScreenMode.Companion.isFullScreenReview
import com.ichi2.anki.reviewer.PeripheralKeymap
import com.ichi2.anki.reviewer.ReviewerBinding
import com.ichi2.anki.reviewer.ReviewerUi
import com.ichi2.anki.reviewer.ScreenKeyMap
import com.ichi2.anki.scheduling.ForgetCardsDialog
import com.ichi2.anki.scheduling.SetDueDateDialog
import com.ichi2.anki.scheduling.registerOnForgetHandler
Expand Down Expand Up @@ -133,7 +137,8 @@ import kotlin.coroutines.resume
@NeedsTest("#14709: Timebox shouldn't appear instantly when the Reviewer is opened")
open class Reviewer :
AbstractFlashcardViewer(),
ReviewerUi {
ReviewerUi,
BindingProcessor<ReviewerBinding, ViewerCommand> {
private var queueState: CurrentQueueState? = null
private val customSchedulingKey = TimeManager.time.intTimeMS().toString()
private var hasDrawerSwipeConflicts = false
Expand Down Expand Up @@ -197,7 +202,7 @@ open class Reviewer :
private lateinit var toolbar: Toolbar

@VisibleForTesting
protected val processor = PeripheralKeymap(this, this)
protected open lateinit var processor: ScreenKeyMap<ReviewerBinding, ViewerCommand>

private val addNoteLauncher =
registerForActivityResult(
Expand All @@ -222,6 +227,7 @@ open class Reviewer :
textBarReview = findViewById(R.id.review_number)
toolbar = findViewById(R.id.toolbar)
micToolBarLayer = findViewById(R.id.mic_tool_bar_layer)
processor = ScreenKeyMap(sharedPrefs(), ViewerCommand.entries, this)
if (sharedPrefs().getString("answerButtonPosition", "bottom") == "bottom" && !navBarNeedsScrim) {
setNavigationBarColor(R.attr.showAnswerColor)
}
Expand Down Expand Up @@ -912,22 +918,12 @@ open class Reviewer :
if (answerFieldIsFocused()) {
return super.onKeyDown(keyCode, event)
}
if (processor.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event)) {
if (processor.onKeyDown(event) || super.onKeyDown(keyCode, event)) {
return true
}
return false
}

override fun onKeyUp(
keyCode: Int,
event: KeyEvent,
): Boolean =
if (processor.onKeyUp(keyCode, event)) {
true
} else {
super.onKeyUp(keyCode, event)
}

override fun onGenericMotionEvent(event: MotionEvent?): Boolean {
if (motionEventHandler.onGenericMotionEvent(event)) {
return true
Expand Down Expand Up @@ -983,7 +979,6 @@ open class Reviewer :
val preferences = super.restorePreferences()
prefHideDueCount = preferences.getBoolean("hideDueCount", false)
prefShowETA = preferences.getBoolean("showETA", false)
processor.setup()
prefFullscreenReview = isFullScreenReview(preferences)
actionButtons.setup(preferences)
return preferences
Expand Down Expand Up @@ -1671,4 +1666,13 @@ open class Reviewer :
/** Default (500ms) time for action snackbars, such as undo, bury and suspend */
const val ACTION_SNACKBAR_TIME = 500
}

override fun processAction(
action: ViewerCommand,
binding: ReviewerBinding,
): Boolean {
if (binding.side != CardSide.BOTH && CardSide.fromAnswer(isDisplayingAnswer) != binding.side) return false
val gesture = (binding.binding as? Binding.GestureInput)?.gesture
return executeCommand(action, gesture)
}
}
15 changes: 15 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/analytics/UsageAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,21 @@ object UsageAnalytics {
"binding_USER_ACTION_7",
"binding_USER_ACTION_8",
"binding_USER_ACTION_9",
// ******************************** Controls - Previewer *******************************
"previewer_NEXT",
"previewer_BACK",
"previewer_MARK",
"previewer_EDIT",
"previewer_REPLAY_AUDIO",
"previewer_BACKSIDE_ONLY",
"previewer_TOGGLE_FLAG_RED",
"previewer_TOGGLE_FLAG_ORANGE",
"previewer_TOGGLE_FLAG_GREEN",
"previewer_TOGGLE_FLAG_BLUE",
"previewer_TOGGLE_FLAG_PINK",
"previewer_TOGGLE_FLAG_TURQUOISE",
"previewer_TOGGLE_FLAG_PURPLE",
"previewer_UNSET_FLAG",
// ******************************** Accessibility ******************************************
"cardZoom",
"imageZoom",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.ichi2.anki.cardviewer
import android.content.SharedPreferences
import com.ichi2.anki.reviewer.Binding
import com.ichi2.anki.reviewer.GestureMapper
import com.ichi2.anki.reviewer.MappableBinding

class GestureProcessor(
private val processor: ViewerCommand.CommandProcessor?,
Expand Down Expand Up @@ -58,7 +57,7 @@ class GestureProcessor(

val associatedCommands = HashMap<Gesture, ViewerCommand>()
for (command in ViewerCommand.entries) {
for (mappableBinding in MappableBinding.fromPreference(preferences, command)) {
for (mappableBinding in command.getBindings(preferences)) {
if (mappableBinding.binding is Binding.GestureInput) {
associatedCommands[mappableBinding.binding.gesture] = command
}
Expand Down
46 changes: 25 additions & 21 deletions AnkiDroid/src/main/java/com/ichi2/anki/cardviewer/ViewerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.ichi2.anki.cardviewer

import android.content.SharedPreferences
import android.view.KeyEvent
import androidx.annotation.LayoutRes
import androidx.core.content.edit
import com.ichi2.anki.R
import com.ichi2.anki.reviewer.Binding.Companion.keyCode
Expand All @@ -26,14 +27,21 @@ import com.ichi2.anki.reviewer.Binding.ModifierKeys.Companion.ctrl
import com.ichi2.anki.reviewer.Binding.ModifierKeys.Companion.shift
import com.ichi2.anki.reviewer.CardSide
import com.ichi2.anki.reviewer.MappableBinding
import com.ichi2.anki.reviewer.MappableBinding.Companion.fromPreference
import com.ichi2.anki.reviewer.MappableBinding.Companion.toPreferenceString
import com.ichi2.anki.reviewer.MappableBinding.Screen
import com.ichi2.anki.reviewer.ReviewerBinding

interface ScreenAction<B : MappableBinding> {
@get:LayoutRes
val titleRes: Int
val preferenceKey: String

fun getBindings(prefs: SharedPreferences): List<B>
}

/** Abstraction: Discuss moving many of these to 'Reviewer' */
enum class ViewerCommand(
val resourceId: Int,
) {
) : ScreenAction<ReviewerBinding> {
SHOW_ANSWER(R.string.show_answer),
FLIP_OR_ANSWER_EASE1(R.string.answer_again),
FLIP_OR_ANSWER_EASE2(R.string.answer_hard),
Expand Down Expand Up @@ -91,7 +99,7 @@ enum class ViewerCommand(
fun fromPreferenceKey(key: String) = entries.first { it.preferenceKey == key }
}

val preferenceKey: String
override val preferenceKey: String
get() = "binding_$name"

fun addBinding(
Expand Down Expand Up @@ -128,26 +136,22 @@ enum class ViewerCommand(
binding: MappableBinding,
performAdd: (MutableList<MappableBinding>, MappableBinding) -> Boolean,
) {
val bindings: MutableList<MappableBinding> = fromPreference(preferences, this)
val bindings: MutableList<MappableBinding> = this.getBindings(preferences).toMutableList()
performAdd(bindings, binding)
val newValue: String = bindings.toPreferenceString()
preferences.edit { putString(preferenceKey, newValue) }
}

override fun getBindings(prefs: SharedPreferences): List<ReviewerBinding> {
val prefValue = prefs.getString(preferenceKey, null) ?: return defaultValue
return ReviewerBinding.fromPreferenceString(prefValue)
}

override val titleRes: Int get() = resourceId

// If we use the serialised format, then this adds additional coupling to the properties.
val defaultValue: List<MappableBinding>
val defaultValue: List<ReviewerBinding>
get() {
// all of the default commands are currently for the Reviewer
fun keyCode(
keycode: Int,
side: CardSide,
modifierKeys: ModifierKeys = ModifierKeys.none(),
) = keyCode(keycode, Screen.Reviewer(side), modifierKeys)

fun unicode(
c: Char,
side: CardSide,
) = unicode(c, Screen.Reviewer(side))
return when (this) {
FLIP_OR_ANSWER_EASE1 ->
listOf(
Expand Down Expand Up @@ -256,14 +260,14 @@ enum class ViewerCommand(

private fun keyCode(
keycode: Int,
screen: Screen,
side: CardSide,
keys: ModifierKeys = ModifierKeys.none(),
): MappableBinding = MappableBinding(keyCode(keys, keycode), screen)
): ReviewerBinding = ReviewerBinding(keyCode(keys, keycode), side)

private fun unicode(
c: Char,
screen: Screen,
): MappableBinding = MappableBinding(unicode(c), screen)
side: CardSide,
): ReviewerBinding = ReviewerBinding(unicode(c), side)

fun interface CommandProcessor {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class CustomStudyDialog(
val dialog =
AlertDialog
.Builder(requireActivity())
.customView(view = v, paddingLeft = 64, paddingRight = 64, paddingTop = 32, paddingBottom = 32)
.customView(view = v, paddingStart = 64, paddingEnd = 64, paddingTop = 32, paddingBottom = 32)
.positiveButton(R.string.dialog_ok) {
// Get the value selected by user
val n =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AddNewNotesType(
AlertDialog
.Builder(activity)
.apply {
customView(dialogView, paddingLeft = 32, paddingRight = 32, paddingTop = 64, paddingBottom = 64)
customView(dialogView, paddingStart = 32, paddingEnd = 32, paddingTop = 64, paddingBottom = 64)
positiveButton(R.string.dialog_ok) { _ ->
val newName =
dialogView.findViewById<EditText>(R.id.notetype_new_name).text.toString()
Expand Down
Loading
Loading