Skip to content

Commit

Permalink
refactor: inline ViewerCommand::allDefaultBindings
Browse files Browse the repository at this point in the history
Only used in tests
  • Loading branch information
BrayanDSO committed Dec 7, 2024
1 parent f9729e0 commit 48f5fb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ 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 java.util.Arrays
import java.util.stream.Collectors

/** Abstraction: Discuss moving many of these to 'Reviewer' */
enum class ViewerCommand(val resourceId: Int) {
Expand Down Expand Up @@ -88,11 +86,6 @@ enum class ViewerCommand(val resourceId: Int) {
;

companion object {
val allDefaultBindings: List<MappableBinding>
get() = Arrays.stream(entries.toTypedArray())
.flatMap { x: ViewerCommand -> x.defaultValue.stream() }
.collect(Collectors.toList())

fun fromPreferenceKey(key: String) = entries.first { it.preferenceKey == key }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ package com.ichi2.anki.reviewer

import android.view.KeyEvent
import com.ichi2.anki.cardviewer.ViewerCommand
import com.ichi2.anki.cardviewer.ViewerCommand.entries
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.hasItem
import org.hamcrest.Matchers.not
import org.junit.Test
import java.util.Arrays
import java.util.stream.Collectors

class MappableBindingTest {
@Test
Expand All @@ -39,7 +42,9 @@ class MappableBindingTest {
assertThat(allBindings, not(hasItem(keyCode(KeyEvent.KEYCODE_L))))
}

private fun getAllBindings() = ViewerCommand.allDefaultBindings
private fun getAllBindings() = Arrays.stream(entries.toTypedArray())
.flatMap { x: ViewerCommand -> x.defaultValue.stream() }
.collect(Collectors.toList())

@Suppress("SameParameterValue")
private fun keyCode(code: Int) = fromBinding(BindingTest.keyCode(code))
Expand Down

0 comments on commit 48f5fb0

Please sign in to comment.