migrate adapters to viewbinding

This commit is contained in:
fatih ergin 2023-08-17 00:21:18 +03:00
parent ee2422b3c3
commit 1972063ca6
3 changed files with 26 additions and 29 deletions

View File

@ -19,12 +19,12 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.databinding.ItemClipInActivityBinding
import com.simplemobiletools.keyboard.dialogs.AddOrEditClipDialog
import com.simplemobiletools.keyboard.extensions.clipsDB
import com.simplemobiletools.keyboard.helpers.ClipsHelper
import com.simplemobiletools.keyboard.models.Clip
import kotlinx.android.synthetic.main.item_clip_in_activity.view.*
import java.util.*
import java.util.Collections
class ClipsActivityAdapter(
activity: BaseSimpleActivity, var items: ArrayList<Clip>, recyclerView: MyRecyclerView, val listener: RefreshRecyclerViewListener, itemClick: (Any) -> Unit
@ -98,7 +98,7 @@ class ClipsActivityAdapter(
wasClipMoved = false
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_clip_in_activity, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(ItemClipInActivityBinding.inflate(layoutInflater, parent, false).root)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = items[position]
@ -154,15 +154,15 @@ class ClipsActivityAdapter(
}
val isSelected = selectedKeys.contains(clip.id!!.toInt())
view.apply {
setupViewBackground(activity)
clip_value.text = clip.value
clip_value.setTextColor(textColor)
clip_drag_handle.applyColorFilter(textColor)
ItemClipInActivityBinding.bind(view).apply {
root.setupViewBackground(activity)
clipValue.text = clip.value
clipValue.setTextColor(textColor)
clipDragHandle.applyColorFilter(textColor)
clip_drag_handle.beVisibleIf(selectedKeys.isNotEmpty())
clip_holder.isSelected = isSelected
clip_drag_handle.setOnTouchListener { v, event ->
clipDragHandle.beVisibleIf(selectedKeys.isNotEmpty())
clipHolder.isSelected = isSelected
clipDragHandle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder)
}

View File

@ -12,6 +12,8 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.databinding.ItemClipOnKeyboardBinding
import com.simplemobiletools.keyboard.databinding.ItemSectionLabelBinding
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.extensions.getCurrentClip
import com.simplemobiletools.keyboard.extensions.getStrokeColor
@ -22,8 +24,6 @@ import com.simplemobiletools.keyboard.interfaces.RefreshClipsListener
import com.simplemobiletools.keyboard.models.Clip
import com.simplemobiletools.keyboard.models.ClipsSectionLabel
import com.simplemobiletools.keyboard.models.ListItem
import kotlinx.android.synthetic.main.item_clip_on_keyboard.view.*
import kotlinx.android.synthetic.main.item_section_label.view.*
class ClipsKeyboardAdapter(
val context: Context, var items: ArrayList<ListItem>, val refreshClipsListener: RefreshClipsListener,
@ -36,13 +36,12 @@ class ClipsKeyboardAdapter(
private var backgroundColor = context.getProperBackgroundColor()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutId = when (viewType) {
ITEM_SECTION_LABEL -> R.layout.item_section_label
else -> R.layout.item_clip_on_keyboard
val binding = when (viewType) {
ITEM_SECTION_LABEL -> ItemSectionLabelBinding.inflate(layoutInflater, parent, false)
else -> ItemClipOnKeyboardBinding.inflate(layoutInflater, parent, false)
}
val view = layoutInflater.inflate(layoutId, parent, false)
return ViewHolder(view)
return ViewHolder(binding.root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -65,13 +64,13 @@ class ClipsKeyboardAdapter(
}
private fun setupClip(view: View, clip: Clip) {
view.apply {
val rippleBg = clip_holder.background as RippleDrawable
ItemClipOnKeyboardBinding.bind(view).apply {
val rippleBg = clipHolder.background as RippleDrawable
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(context.getStrokeColor())
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(backgroundColor)
clip_value.apply {
clipValue.apply {
text = clip.value
removeUnderlines()
setTextColor(textColor)
@ -81,13 +80,13 @@ class ClipsKeyboardAdapter(
@SuppressLint("UseCompatLoadingForDrawables")
private fun setupSection(view: View, sectionLabel: ClipsSectionLabel) {
view.apply {
clips_section_label.apply {
ItemSectionLabelBinding.bind(view).apply {
clipsSectionLabel.apply {
text = sectionLabel.value
setTextColor(textColor)
}
clips_section_icon.apply {
clipsSectionIcon.apply {
applyColorFilter(textColor)
if (sectionLabel.isCurrent) {

View File

@ -6,15 +6,13 @@ import android.view.View
import android.view.ViewGroup
import androidx.emoji2.text.EmojiCompat
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.keyboard.R
import kotlinx.android.synthetic.main.item_emoji.view.*
import com.simplemobiletools.keyboard.databinding.ItemEmojiBinding
class EmojisAdapter(val context: Context, var items: List<String>, val itemClick: (emoji: String) -> Unit) : RecyclerView.Adapter<EmojisAdapter.ViewHolder>() {
private val layoutInflater = LayoutInflater.from(context)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EmojisAdapter.ViewHolder {
val layoutId = R.layout.item_emoji
val view = layoutInflater.inflate(layoutId, parent, false)
val view = ItemEmojiBinding.inflate(layoutInflater, parent, false).root
return ViewHolder(view)
}
@ -29,7 +27,7 @@ class EmojisAdapter(val context: Context, var items: List<String>, val itemClick
private fun setupEmoji(view: View, emoji: String) {
val processed = EmojiCompat.get().process(emoji)
view.emoji_value.text = processed
ItemEmojiBinding.bind(view).emojiValue.text = processed
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {