Skip to content

Commit

Permalink
highlight selected card
Browse files Browse the repository at this point in the history
This commit ensures that the selected card should be highlighted on large screens only. By default first card should be highlighted
  • Loading branch information
SanjaySargam committed Aug 14, 2024
1 parent 993e767 commit e9b1a0c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ open class CardBrowser :
} else {
// load up the card selected on the list
saveScrollingState(position)
// set selected position
cardsAdapter.selectedPosition = position
openNoteEditorForCard(clickedCardId)
}
}
Expand Down Expand Up @@ -1857,6 +1859,7 @@ open class CardBrowser :
) : BaseAdapter() {
private var originalTextSize = -1.0f
private val inflater: LayoutInflater
var selectedPosition: Int = 0
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
// Get the main container view if it doesn't already exist, and call bindView
val v: View
Expand Down Expand Up @@ -1884,8 +1887,10 @@ open class CardBrowser :
setFont(column as TextView) // set font for column
column.text = card.getColumnHeaderText(fromKeys[i]) // set text for column
}
// check whether the view is selected
val isHighLight = position == selectedPosition
// set card's background color
val backgroundColor: Int = card.getBackgroundColor(this@CardBrowser)
val backgroundColor: Int = card.getBackgroundColor(this@CardBrowser, isHighLight)
v.setBackgroundColor(backgroundColor)
// setup checkbox to change color in multi-select mode
val checkBox = v.findViewById<CheckBox>(R.id.card_checkbox)
Expand Down Expand Up @@ -2067,12 +2072,14 @@ open class CardBrowser :
* @return index into TypedArray specifying the background color
*/
@ColorInt
fun getBackgroundColor(context: Context): Int {
fun getBackgroundColor(context: Context, isHighlight: Boolean): Int {
val flagColor = Flag.fromCode(card.userFlag()).browserColorRes
if (flagColor != null) {
return context.getColor(flagColor)
}
val colorAttr = if (isMarked(col, card.note(col))) {
val colorAttr = if (isHighlight) {
R.attr.currentDeckBackgroundColor
} else if (isMarked(col, card.note(col))) {
R.attr.markedColor
} else if (card.queue == Consts.QUEUE_TYPE_SUSPENDED) {
R.attr.suspendedColor
Expand Down

0 comments on commit e9b1a0c

Please sign in to comment.