From 72cb215331c55bba7df3e4a87252ef81e9d99ef4 Mon Sep 17 00:00:00 2001 From: SanjaySargam Date: Wed, 24 Jul 2024 22:55:58 +0530 Subject: [PATCH] highlight selected card This commit ensures that the selected card should be highlighted on large screens only. By default first card should be highlighted --- .../src/main/java/com/ichi2/anki/CardBrowser.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt index 6da837849c35..0fdb204244a2 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt @@ -651,6 +651,8 @@ open class CardBrowser : // load up the card selected on the list val clickedCardId = viewModel.queryCardIdAtPosition(position) saveScrollingState(position) + // set selected position + cardsAdapter.selectedPosition = position openNoteEditorForCard(clickedCardId) } } @@ -1851,6 +1853,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 @@ -1878,8 +1881,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(R.id.card_checkbox) @@ -2061,12 +2066,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