Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flag color in new reviewer #17724

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
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 @@ -49,6 +49,7 @@ import androidx.annotation.ColorInt
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 anki.collection.OpChanges
Expand Down Expand Up @@ -1077,9 +1078,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 @@ -48,6 +48,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 @@ -734,9 +735,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 @@ -879,11 +884,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
Loading