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 29, 2024
1 parent b361b98 commit 028d962
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ open class CardBrowser :
cardsListView.setOnItemClickListener { _: AdapterView<*>?, view: View?, position: Int, _: Long ->
launchCatchingTask {
val clickedCardId = viewModel.queryCardIdAtPosition(position)
// set selected position
cardsAdapter.selectedPosition = position
if (viewModel.isInMultiSelectMode) {
// click on whole cell triggers select
val cb = view!!.findViewById<CheckBox>(R.id.card_checkbox)
Expand All @@ -682,6 +684,8 @@ open class CardBrowser :
cardsListView.setOnItemLongClickListener { _: AdapterView<*>?, view: View?, position: Int, _: Long ->
launchCatchingTask {
currentCardId = viewModel.queryCardIdAtPosition(position)
// set selected position
cardsAdapter.selectedPosition = position
if (viewModel.isInMultiSelectMode) {
viewModel.selectRowsBetweenPositions(lastSelectedPosition, position)
} else {
Expand Down Expand Up @@ -2030,6 +2034,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 @@ -2057,8 +2062,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 @@ -2240,12 +2247,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 028d962

Please sign in to comment.