Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
package com.ichi2.widget

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.databinding.WidgetItemDeckConfigBinding
import com.ichi2.anki.libanki.DeckId
import com.ichi2.anki.model.SelectableDeck
import com.ichi2.anki.utils.ext.findViewById
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -48,11 +44,8 @@ class WidgetConfigScreenAdapter(
val deckIds: List<Long> get() = decks.map { it.deckId }

class DeckViewHolder(
itemView: View,
) : RecyclerView.ViewHolder(itemView) {
val deckNameTextView: TextView = findViewById(R.id.deck_name)
val removeButton: ImageButton = findViewById(R.id.action_button_remove_deck)
}
val binding: WidgetItemDeckConfigBinding,
) : RecyclerView.ViewHolder(binding.root)

/** Creates and inflates the view for each item in the RecyclerView
* @param parent the parent ViewGroup
Expand All @@ -62,11 +55,8 @@ class WidgetConfigScreenAdapter(
parent: ViewGroup,
viewType: Int,
): DeckViewHolder {
val view =
LayoutInflater
.from(parent.context)
.inflate(R.layout.widget_item_deck_config, parent, false)
return DeckViewHolder(view)
val layoutInflater = LayoutInflater.from(parent.context)
return DeckViewHolder(WidgetItemDeckConfigBinding.inflate(layoutInflater, parent, false))
}

override fun onBindViewHolder(
Expand All @@ -80,10 +70,10 @@ class WidgetConfigScreenAdapter(
withContext(Dispatchers.IO) {
withCol { decks.getLegacy(deck.deckId)!!.name }
}
holder.deckNameTextView.text = deckName
holder.binding.deckNameTextView.text = deckName
}

holder.removeButton.setOnClickListener {
holder.binding.removeDeckButton.setOnClickListener {
onDeleteDeck(deck, position)
}
}
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/res/layout/widget_item_deck_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:theme="@style/Theme.Material3.DynamicColors.DayNight">

<TextView
android:id="@+id/deck_name"
android:id="@+id/deck_name_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand All @@ -18,7 +18,7 @@
android:textSize="18sp" />

<ImageButton
android:id="@+id/action_button_remove_deck"
android:id="@+id/remove_deck_button"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
Expand Down