-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
416 additions
and
6 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/daominh/quickmem/adapter/CardLeanAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.daominh.quickmem.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.daominh.quickmem.data.model.Card | ||
import com.daominh.quickmem.databinding.ItemLearnSetBinding | ||
|
||
class CardLeanAdapter( | ||
private var cardList: List<Card> | ||
) : RecyclerView.Adapter<CardLeanAdapter.ViewHolder>() { | ||
|
||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardLeanAdapter.ViewHolder { | ||
val layoutInflater = LayoutInflater.from(parent.context) | ||
val binding = ItemLearnSetBinding.inflate(layoutInflater, parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: CardLeanAdapter.ViewHolder, position: Int) { | ||
val card = cardList[position] | ||
holder.bind(card) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return cardList.size | ||
} | ||
|
||
fun setCards(cards: List<Card>) { | ||
this.cardList = cards | ||
} | ||
|
||
fun getCards(): List<Card> { | ||
return cardList | ||
} | ||
|
||
class ViewHolder(private val binding: ItemLearnSetBinding) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(card: Card) { | ||
binding.itemFont.text = card.front | ||
binding.itemBack.text = card.back | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/daominh/quickmem/utils/CardDiffCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.daominh.quickmem.utils | ||
|
||
import androidx.recyclerview.widget.DiffUtil | ||
import com.daominh.quickmem.data.model.Card | ||
|
||
class CardDiffCallback( | ||
private val oldList: List<Card>, | ||
private val newList: List<Card> | ||
) : DiffUtil.Callback( | ||
) { | ||
override fun getOldListSize(): Int { | ||
return oldList.size | ||
} | ||
|
||
override fun getNewListSize(): Int { | ||
return newList.size | ||
} | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition].id == newList[newItemPosition].id | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition] == newList[newItemPosition] | ||
} | ||
} |
Oops, something went wrong.