Skip to content

Commit

Permalink
fix: flag color in new reviewer
Browse files Browse the repository at this point in the history
the new reviewer "Flag.NONE" icon had a different color because it wasn't using `drawableReviewerRes`

I added the flag items back to the XML so I could change only the Flag.NONE icon
  • Loading branch information
RobozinhoD authored and david-allison committed Jan 6, 2025
1 parent 66557be commit 1a96697
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
12 changes: 9 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.annotation.CheckResult
import androidx.annotation.MainThread
import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.ThemeUtils
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -1016,9 +1017,14 @@ open class CardBrowser :
}

for ((flag, displayName) in Flag.queryDisplayNames()) {
subMenu
.add(groupId, flag.code, Menu.NONE, displayName)
.setIcon(flag.drawableRes)
val item =
subMenu
.add(groupId, flag.code, Menu.NONE, displayName)
.setIcon(flag.drawableRes)
if (flag == Flag.NONE) {
val color = ThemeUtils.getThemeAttrColor(this@CardBrowser, android.R.attr.colorControlNormal)
item.icon?.mutate()?.setTint(color)
}
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions AnkiDroid/src/main/java/com/ichi2/anki/Flag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ enum class Flag(
* Color for the background of cards with this flag in the card browser.
*/
@ColorRes val browserColorRes: Int?,
/**
* Flag drawn to represents this flagInTheReviewer if it differs from [drawableRes].
* @TODO: Checks whether we can use colorControlNormal everywhere.
*/
@DrawableRes val drawableReviewerRes: Int? = null,
) {
NONE(0, R.id.flag_none, R.drawable.ic_flag_lightgrey, null, R.drawable.ic_flag_transparent),
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,
Expand All @@ -68,11 +63,6 @@ enum class Flag(
),
;

/**
* Flag drawn to represents this flagInTheReviewer.
*/
@DrawableRes fun drawableReviewerRes() = drawableReviewerRes ?: drawableRes

/**
* Retrieves the name associated with the flag. This may be user-defined
*
Expand Down
16 changes: 9 additions & 7 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.annotation.IntDef
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.widget.ThemeUtils
import androidx.appcompat.widget.Toolbar
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -736,9 +737,13 @@ open class Reviewer :
val flagIcon = menu.findItem(R.id.action_flag)
if (flagIcon != null) {
if (currentCard != null) {
flagIcon.setIcon(currentCard!!.userFlag().drawableReviewerRes())
val flag = currentCard!!.userFlag()
flagIcon.setIcon(flag.drawableRes)
if (flag == Flag.NONE && actionButtons.status.flagsIsOverflown()) {
val flagColor = ThemeUtils.getThemeAttrColor(this, android.R.attr.colorControlNormal)
flagIcon.icon?.mutate()?.setTint(flagColor)
}
}
flagIcon.iconAlpha = alpha
}

// Anki Desktop Translations
Expand Down Expand Up @@ -881,11 +886,8 @@ open class Reviewer :
private fun setupFlags(subMenu: SubMenu) {
lifecycleScope.launch {
for ((flag, displayName) in Flag.queryDisplayNames()) {
val menuItem =
subMenu
.add(Menu.NONE, flag.code, Menu.NONE, displayName)
.setIcon(flag.drawableRes)
flagItemIds.add(menuItem.itemId)
subMenu.findItem(flag.id).setTitle(displayName)
flagItemIds.add(flag.id)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class ActionButtonStatus {

fun buryIsDisabled(): Boolean = customButtons[R.id.action_bury] == MENU_DISABLED

fun flagsIsOverflown(): Boolean = customButtons[R.id.action_flag] == SHOW_AS_ACTION_NEVER

companion object {
const val SHOW_AS_ACTION_NEVER = MenuItem.SHOW_AS_ACTION_NEVER
const val SHOW_AS_ACTION_IF_ROOM = MenuItem.SHOW_AS_ACTION_IF_ROOM
Expand Down
33 changes: 32 additions & 1 deletion AnkiDroid/src/main/res/menu/reviewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,38 @@
android:icon="@drawable/ic_flag_transparent"
ankidroid:showAsAction="always" >
<menu>
<!-- flags are dynamically added -->
<item
android:id="@id/flag_none"
android:icon="@drawable/ic_flag_lightgrey"
tools:title="No Flag"/>
<item
android:id="@id/flag_red"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@id/flag_orange"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@id/flag_green"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@id/flag_blue"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@id/flag_pink"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@id/flag_turquoise"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@id/flag_purple"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
<item
Expand Down

0 comments on commit 1a96697

Please sign in to comment.