diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt index 83fef3b6b90f..8674ace86acc 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt @@ -17,6 +17,7 @@ package com.ichi2.anki import androidx.annotation.ColorRes import androidx.annotation.DrawableRes +import androidx.annotation.IdRes import com.ichi2.anki.CollectionManager.TR import com.ichi2.anki.CollectionManager.withCol import com.ichi2.anki.utils.ext.getStringOrNull @@ -26,15 +27,20 @@ import com.ichi2.libanki.Collection import org.json.JSONObject import timber.log.Timber -enum class Flag(val code: Int, @DrawableRes val drawableRes: Int, @ColorRes val browserColorRes: Int?) { - NONE(0, R.drawable.ic_flag_transparent, null), - RED(1, R.drawable.ic_flag_red, R.color.flag_red), - ORANGE(2, R.drawable.ic_flag_orange, R.color.flag_orange), - GREEN(3, R.drawable.ic_flag_green, R.color.flag_green), - BLUE(4, R.drawable.ic_flag_blue, R.color.flag_blue), - PINK(5, R.drawable.ic_flag_pink, R.color.flag_pink), - TURQUOISE(6, R.drawable.ic_flag_turquoise, R.color.flag_turquoise), - PURPLE(7, R.drawable.ic_flag_purple, R.color.flag_purple); +enum class Flag( + val code: Int, + @IdRes val id: Int, + @DrawableRes val drawableRes: Int, + @ColorRes val browserColorRes: Int? +) { + NONE(0, R.id.flag_none, R.drawable.ic_flag_transparent, null), + RED(1, R.id.flag_red, R.drawable.ic_flag_red, R.color.flag_red), + ORANGE(2, R.id.flag_orange, R.drawable.ic_flag_orange, R.color.flag_orange), + GREEN(3, R.id.flag_green, R.drawable.ic_flag_green, R.color.flag_green), + BLUE(4, R.id.flag_blue, R.drawable.ic_flag_blue, R.color.flag_blue), + PINK(5, R.id.flag_pink, R.drawable.ic_flag_pink, R.color.flag_pink), + TURQUOISE(6, R.id.flag_turquoise, R.drawable.ic_flag_turquoise, R.color.flag_turquoise), + PURPLE(7, R.id.flag_purple, R.drawable.ic_flag_purple, R.color.flag_purple); /** * Retrieves the name associated with the flag. This may be user-defined diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerFragment.kt index b5567e279e06..8f8826419edd 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerFragment.kt @@ -50,7 +50,6 @@ import com.ichi2.annotations.NeedsTest import com.ichi2.utils.performClickIfEnabled import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import timber.log.Timber class PreviewerFragment : CardViewerFragment(R.layout.previewer), @@ -194,23 +193,25 @@ class PreviewerFragment : val submenu = menu.findItem(R.id.action_flag).subMenu lifecycleScope.launch { for ((flag, name) in Flag.queryDisplayNames()) { - submenu?.add(Menu.NONE, flag.ordinal, Menu.NONE, name) + submenu?.add(Menu.NONE, flag.id, Menu.NONE, name) ?.setIcon(flag.drawableRes) } } } override fun onMenuItemClick(item: MenuItem): Boolean { - Flag.entries.find { it.ordinal == item.itemId }?.let { flag -> - Timber.i("PreviewerFragment:: onMenuItemClick Flag - ${flag.name} clicked") - viewModel.setFlag(flag) - return true - } - when (item.itemId) { R.id.action_edit -> editCard() R.id.action_mark -> viewModel.toggleMark() R.id.action_back_side_only -> viewModel.toggleBackSideOnly() + R.id.flag_none -> viewModel.setFlag(Flag.NONE) + R.id.flag_red -> viewModel.setFlag(Flag.RED) + R.id.flag_orange -> viewModel.setFlag(Flag.ORANGE) + R.id.flag_green -> viewModel.setFlag(Flag.GREEN) + R.id.flag_blue -> viewModel.setFlag(Flag.BLUE) + R.id.flag_pink -> viewModel.setFlag(Flag.PINK) + R.id.flag_turquoise -> viewModel.setFlag(Flag.TURQUOISE) + R.id.flag_purple -> viewModel.setFlag(Flag.PURPLE) } return true } diff --git a/AnkiDroid/src/main/res/values/ids.xml b/AnkiDroid/src/main/res/values/ids.xml new file mode 100644 index 000000000000..e599a2daa65c --- /dev/null +++ b/AnkiDroid/src/main/res/values/ids.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + \ No newline at end of file