split clips adapter shown on keyboard and activity

This commit is contained in:
tibbi 2022-01-27 22:50:18 +01:00
parent 565a149d6d
commit 54a9f7b286
4 changed files with 74 additions and 2 deletions

View file

@ -0,0 +1,54 @@
package com.simplemobiletools.keyboard.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.extensions.removeUnderlines
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.models.Clip
import kotlinx.android.synthetic.main.item_clip_on_keyboard.view.*
import java.util.*
class ClipsKeyboardAdapter(val context: Context, var clips: ArrayList<Clip>, val itemClick: (clip: Clip) -> Unit) :
RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolderr>() {
private val layoutInflater = LayoutInflater.from(context)
private val baseConfig = context.config
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)
return ViewHolderr(view)
}
override fun onBindViewHolder(holder: ViewHolderr, position: Int) {
val item = clips[position]
holder.bindView(item) { itemView ->
setupView(itemView, item)
}
}
override fun getItemCount() = clips.size
private fun setupView(view: View, clip: Clip) {
view.clip_value.apply {
text = clip.value
removeUnderlines()
setTextColor(textColor)
}
}
open inner class ViewHolderr(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(clip: Clip, callback: (itemView: View) -> Unit): View {
return itemView.apply {
callback(this)
setOnClickListener {
itemClick.invoke(clip)
}
}
}
}
}

View file

@ -30,7 +30,7 @@ import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.activities.ManageClipboardItemsActivity
import com.simplemobiletools.keyboard.activities.SettingsActivity
import com.simplemobiletools.keyboard.adapters.ClipsAdapter
import com.simplemobiletools.keyboard.adapters.ClipsKeyboardAdapter
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.*
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_DELETE
@ -1334,7 +1334,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
clips_list.beVisibleIf(clips.isNotEmpty())
}
val adapter = ClipsAdapter(context, clips) { clip ->
val adapter = ClipsKeyboardAdapter(context, clips) { clip ->
mOnKeyboardActionListener!!.onText(clip.value)
vibrateIfNeeded()
}

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clip_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/clipboard_background">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/clip_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:textSize="@dimen/normal_text_size"
tools:text="Hello, how are you?" />
</RelativeLayout>