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 Sep 1, 2024
1 parent 06d2403 commit 9cccf86
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 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 @@ -1700,7 +1704,7 @@ open class CardBrowser :
val isDeckEmpty = viewModel.rowCount == 0
// Hide note editor frame if deck is empty and fragmented
noteEditorFrame?.visibility = if (fragmented && !isDeckEmpty) {
currentCardId = viewModel.cards[0].id
currentCardId = viewModel.cards[cardsAdapter.selectedPosition].id
loadNoteEditorFragmentIfFragmented(editNoteLauncher)
View.VISIBLE
} else {
Expand Down Expand Up @@ -2044,6 +2048,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 @@ -2071,8 +2076,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 @@ -2254,12 +2261,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 9cccf86

Please sign in to comment.