adding clip sections at the keyboard

This commit is contained in:
tibbi 2022-01-29 09:41:37 +01:00
parent 8372368cc9
commit c8680b21ab
2 changed files with 39 additions and 4 deletions

View File

@ -5,15 +5,20 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.simplemobiletools.commons.extensions.removeUnderlines
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.ITEM_CLIP
import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL
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.*
import java.util.*
class ClipsKeyboardAdapter(val context: Context, var clips: ArrayList<ListItem>, val itemClick: (clip: Clip) -> Unit) :
class ClipsKeyboardAdapter(val context: Context, var items: ArrayList<ListItem>, val itemClick: (clip: Clip) -> Unit) :
RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolderr>() {
private val layoutInflater = LayoutInflater.from(context)
@ -21,20 +26,33 @@ class ClipsKeyboardAdapter(val context: Context, var clips: ArrayList<ListItem>,
private var textColor = baseConfig.textColor
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderr {
val view = layoutInflater.inflate(R.layout.item_clip_on_keyboard, parent, false)
val layoutId = when (viewType) {
ITEM_SECTION_LABEL -> R.layout.item_section_label
else -> R.layout.item_clip_on_keyboard
}
val view = layoutInflater.inflate(layoutId, parent, false)
return ViewHolderr(view)
}
override fun onBindViewHolder(holder: ViewHolderr, position: Int) {
val item = clips[position]
val item = items[position]
holder.bindView(item) { itemView ->
when (item) {
is Clip -> setupClip(itemView, item)
is ClipsSectionLabel -> setupSection(itemView, item)
}
(itemView.layoutParams as StaggeredGridLayoutManager.LayoutParams).isFullSpan = item is ClipsSectionLabel
}
}
override fun getItemCount() = clips.size
override fun getItemCount() = items.size
override fun getItemViewType(position: Int) = when {
items[position] is ClipsSectionLabel -> ITEM_SECTION_LABEL
else -> ITEM_CLIP
}
private fun setupClip(view: View, clip: Clip) {
view.clip_value.apply {
@ -44,6 +62,13 @@ class ClipsKeyboardAdapter(val context: Context, var clips: ArrayList<ListItem>,
}
}
private fun setupSection(view: View, label: ClipsSectionLabel) {
view.clips_section_label.apply {
text = label.value
setTextColor(textColor)
}
}
open inner class ViewHolderr(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(any: Any, callback: (itemView: View) -> Unit): View {
return itemView.apply {

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clips_section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.8"
android:padding="@dimen/medium_margin"
android:textSize="@dimen/normal_text_size"
tools:text="@string/clipboard_current" />