Skip to content

Commit

Permalink
Ankidroid use flag names like anki
Browse files Browse the repository at this point in the history
  • Loading branch information
Giyutomioka-SS authored and lukstbit committed May 19, 2024
1 parent 8aeb8a6 commit ebbd10d
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 42 deletions.
24 changes: 24 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ open class CardBrowser :
// restore drawer click listener and icon
restoreDrawerIcon()
menuInflater.inflate(R.menu.card_browser, menu)
setFlagTitles(menu)
saveSearchItem = menu.findItem(R.id.action_save_search)
saveSearchItem?.isVisible = false // the searchview's query always starts empty.
mySearchesItem = menu.findItem(R.id.action_list_my_searches)
Expand Down Expand Up @@ -788,6 +789,7 @@ open class CardBrowser :
} else {
// multi-select mode
menuInflater.inflate(R.menu.card_browser_multiselect, menu)
setMultiSelectFlagTitles(menu)
showBackIcon()
increaseHorizontalPaddingOfOverflowMenuIcons(menu)
}
Expand Down Expand Up @@ -821,6 +823,28 @@ open class CardBrowser :
}
}

private fun setFlagTitles(menu: Menu) {
menu.findItem(R.id.action_select_flag_zero).title = Flag.NONE.displayName()
menu.findItem(R.id.action_select_flag_one).title = Flag.RED.displayName()
menu.findItem(R.id.action_select_flag_two).title = Flag.ORANGE.displayName()
menu.findItem(R.id.action_select_flag_three).title = Flag.GREEN.displayName()
menu.findItem(R.id.action_select_flag_four).title = Flag.BLUE.displayName()
menu.findItem(R.id.action_select_flag_five).title = Flag.PINK.displayName()
menu.findItem(R.id.action_select_flag_six).title = Flag.TURQUOISE.displayName()
menu.findItem(R.id.action_select_flag_seven).title = Flag.PURPLE.displayName()
}

private fun setMultiSelectFlagTitles(menu: Menu) {
menu.findItem(R.id.action_flag_zero).title = Flag.NONE.displayName()
menu.findItem(R.id.action_flag_one).title = Flag.RED.displayName()
menu.findItem(R.id.action_flag_two).title = Flag.ORANGE.displayName()
menu.findItem(R.id.action_flag_three).title = Flag.GREEN.displayName()
menu.findItem(R.id.action_flag_four).title = Flag.BLUE.displayName()
menu.findItem(R.id.action_flag_five).title = Flag.PINK.displayName()
menu.findItem(R.id.action_flag_six).title = Flag.TURQUOISE.displayName()
menu.findItem(R.id.action_flag_seven).title = Flag.PURPLE.displayName()
}

private fun updatePreviewMenuItem() {
previewItem?.isVisible = viewModel.rowCount > 0
}
Expand Down
12 changes: 12 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.ichi2.anki

import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.libanki.Card
import com.ichi2.libanki.CardId
import com.ichi2.libanki.Collection
Expand All @@ -31,6 +32,17 @@ enum class Flag(val code: Int, @DrawableRes val drawableRes: Int, @ColorRes val
TURQUOISE(6, R.drawable.ic_flag_turquoise, R.color.flag_turquoise),
PURPLE(7, R.drawable.ic_flag_purple, R.color.flag_purple);

fun displayName(): String = when (this) {
NONE -> TR.browsingNoFlag()
RED -> TR.actionsFlagRed()
ORANGE -> TR.actionsFlagOrange()
GREEN -> TR.actionsFlagGreen()
BLUE -> TR.actionsFlagBlue()
PINK -> TR.actionsFlagPink()
TURQUOISE -> TR.actionsFlagTurquoise()
PURPLE -> TR.actionsFlagPurple()
}

companion object {
fun fromCode(code: Int): Flag {
return entries.first { it.code == code }
Expand Down
13 changes: 13 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import anki.frontend.SetSchedulingStatesRequest
import com.google.android.material.color.MaterialColors
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anim.ActivityTransitionAnimation.getInverseTransition
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.Whiteboard.Companion.createInstance
import com.ichi2.anki.Whiteboard.OnPaintColorChangeListener
Expand Down Expand Up @@ -692,6 +693,7 @@ open class Reviewer :
Timber.d("onCreateOptionsMenu()")
// NOTE: This is called every time a new question is shown via invalidate options menu
menuInflater.inflate(R.menu.reviewer, menu)
setFlagTitles(menu)
displayIcons(menu)
actionButtons.setCustomButtonsStatus(menu)
val alpha = Themes.ALPHA_ICON_ENABLED_LIGHT
Expand Down Expand Up @@ -848,6 +850,17 @@ open class Reviewer :
return super.onCreateOptionsMenu(menu)
}

private fun setFlagTitles(menu: Menu) {
menu.findItem(R.id.action_flag_zero).title = Flag.NONE.displayName()
menu.findItem(R.id.action_flag_one).title = Flag.RED.displayName()
menu.findItem(R.id.action_flag_two).title = Flag.ORANGE.displayName()
menu.findItem(R.id.action_flag_three).title = Flag.GREEN.displayName()
menu.findItem(R.id.action_flag_four).title = Flag.BLUE.displayName()
menu.findItem(R.id.action_flag_five).title = Flag.PINK.displayName()
menu.findItem(R.id.action_flag_six).title = Flag.TURQUOISE.displayName()
menu.findItem(R.id.action_flag_seven).title = Flag.PURPLE.displayName()
}

@SuppressLint("RestrictedApi")
private fun displayIcons(menu: Menu) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PreviewerFragment :
}
/* ************************************* Menu items ************************************* */
val menu = view.findViewById<Toolbar>(R.id.toolbar).menu
setFlagTitles(menu)

lifecycleScope.launch {
viewModel.backSideOnly
Expand Down Expand Up @@ -204,6 +205,17 @@ class PreviewerFragment :
return true
}

private fun setFlagTitles(menu: Menu) {
menu.findItem(R.id.action_flag_zero).title = Flag.NONE.displayName()
menu.findItem(R.id.action_flag_one).title = Flag.RED.displayName()
menu.findItem(R.id.action_flag_two).title = Flag.ORANGE.displayName()
menu.findItem(R.id.action_flag_three).title = Flag.GREEN.displayName()
menu.findItem(R.id.action_flag_four).title = Flag.BLUE.displayName()
menu.findItem(R.id.action_flag_five).title = Flag.PINK.displayName()
menu.findItem(R.id.action_flag_six).title = Flag.TURQUOISE.displayName()
menu.findItem(R.id.action_flag_seven).title = Flag.PURPLE.displayName()
}

private fun setBackSideOnlyButtonIcon(menu: Menu, isBackSideOnly: Boolean) {
menu.findItem(R.id.action_back_side_only).apply {
if (isBackSideOnly) {
Expand Down
19 changes: 10 additions & 9 deletions AnkiDroid/src/main/res/menu/card_browser.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ankidroid="http://schemas.android.com/apk/res-auto" >
xmlns:ankidroid="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<item
android:id="@+id/action_add_note_from_card_browser"
Expand Down Expand Up @@ -40,34 +41,34 @@
<menu>
<item
android:id="@+id/action_select_flag_zero"
android:title="@string/menu_flag_card_zero"/>
tools:title="No Flag"/>
<item
android:id="@+id/action_select_flag_one"
android:title="@string/menu_flag_card_one"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@+id/action_select_flag_two"
android:title="@string/menu_flag_card_two"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@+id/action_select_flag_three"
android:title="@string/menu_flag_card_three"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@+id/action_select_flag_four"
android:title="@string/menu_flag_card_four"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@+id/action_select_flag_five"
android:title="@string/menu_flag_card_five"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@+id/action_select_flag_six"
android:title="@string/menu_flag_card_six"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@+id/action_select_flag_seven"
android:title="@string/menu_flag_card_seven"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
Expand Down
16 changes: 8 additions & 8 deletions AnkiDroid/src/main/res/menu/card_browser_multiselect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@
<menu>
<item
android:id="@+id/action_flag_zero"
android:title="@string/menu_flag_card_zero"/>
tools:title="No Flag"/>
<item
android:id="@+id/action_flag_one"
android:title="@string/menu_flag_card_one"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@+id/action_flag_two"
android:title="@string/menu_flag_card_two"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@+id/action_flag_three"
android:title="@string/menu_flag_card_three"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@+id/action_flag_four"
android:title="@string/menu_flag_card_four"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@+id/action_flag_five"
android:title="@string/menu_flag_card_five"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@+id/action_flag_six"
android:title="@string/menu_flag_card_six"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@+id/action_flag_seven"
android:title="@string/menu_flag_card_seven"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
Expand Down
19 changes: 10 additions & 9 deletions AnkiDroid/src/main/res/menu/previewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_back_side_only"
android:icon="@drawable/ic_card_question"
Expand All @@ -29,34 +30,34 @@
<menu>
<item
android:id="@+id/action_flag_zero"
android:title="@string/menu_flag_card_zero"/>
tools:title="No Flag"/>
<item
android:id="@+id/action_flag_one"
android:title="@string/menu_flag_card_one"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@+id/action_flag_two"
android:title="@string/menu_flag_card_two"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@+id/action_flag_three"
android:title="@string/menu_flag_card_three"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@+id/action_flag_four"
android:title="@string/menu_flag_card_four"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@+id/action_flag_five"
android:title="@string/menu_flag_card_five"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@+id/action_flag_six"
android:title="@string/menu_flag_card_six"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@+id/action_flag_seven"
android:title="@string/menu_flag_card_seven"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
Expand Down
16 changes: 8 additions & 8 deletions AnkiDroid/src/main/res/menu/reviewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,34 @@
<menu>
<item
android:id="@+id/action_flag_zero"
android:title="@string/menu_flag_card_zero"/>
tools:title="No Flag"/>
<item
android:id="@+id/action_flag_one"
android:title="@string/menu_flag_card_one"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@+id/action_flag_two"
android:title="@string/menu_flag_card_two"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@+id/action_flag_three"
android:title="@string/menu_flag_card_three"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@+id/action_flag_four"
android:title="@string/menu_flag_card_four"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@+id/action_flag_five"
android:title="@string/menu_flag_card_five"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@+id/action_flag_six"
android:title="@string/menu_flag_card_six"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@+id/action_flag_seven"
android:title="@string/menu_flag_card_seven"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
Expand Down
8 changes: 0 additions & 8 deletions AnkiDroid/src/main/res/values/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@
<string name="menu_delete_note">Delete note</string>
<string name="menu_flag">Flag</string>
<string name="menu_flag_card">Flag card</string>
<string name="menu_flag_card_zero">No flag</string>
<string name="menu_flag_card_one">Red flag</string>
<string name="menu_flag_card_two">Orange flag</string>
<string name="menu_flag_card_three">Green flag</string>
<string name="menu_flag_card_four">Blue flag</string>
<string name="menu_flag_card_five">Pink flag</string>
<string name="menu_flag_card_six">Turquoise flag</string>
<string name="menu_flag_card_seven">Purple flag</string>
<string name="menu_edit_tags">Edit tags</string>
<string name="delete_note_message">Really delete this note and all its cards?\n%s</string>
<string name="menu_search">Lookup in %1$s</string>
Expand Down

0 comments on commit ebbd10d

Please sign in to comment.