Move from java/ to kotlin/ directory

Android 12 dynamic color usage on login screen
This commit is contained in:
2021-08-31 02:18:29 +03:00
parent 2453e534ae
commit 1209c37e24
135 changed files with 140 additions and 57 deletions
@@ -0,0 +1,132 @@
package com.meloda.fast.base.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
@Suppress("UNCHECKED_CAST", "unused", "MemberVisibilityCanBePrivate", "CanBeParameter")
abstract class BaseAdapter<Item : BaseItem, VH : BaseHolder>(
var context: Context,
values: ArrayList<Item>,
diffUtil: DiffUtil.ItemCallback<Item>
) : ListAdapter<Item, VH>(diffUtil) {
val cleanValues = arrayListOf<Item>()
val values = arrayListOf<Item>()
init {
addAll(values)
}
protected var inflater: LayoutInflater = LayoutInflater.from(context)
var itemClickListener: OnItemClickListener? = null
var itemLongClickListener: OnItemLongClickListener? = null
open fun destroy() {
itemClickListener = null
itemLongClickListener = null
}
override fun getItem(position: Int): Item {
return values[position]
}
fun add(position: Int, item: Item) {
values.add(position, item)
cleanValues.add(position, item)
}
fun add(item: Item) {
values += item
cleanValues.add(item)
}
fun addAll(items: List<Item>) {
values += items
cleanValues.addAll(items)
}
fun addAll(position: Int, items: List<Item>) {
values.addAll(position, items)
cleanValues.addAll(position, items)
}
fun removeAll(items: List<Item>) {
values.removeAll(items)
cleanValues.removeAll(items)
}
fun removeAt(index: Int) {
values.removeAt(index)
cleanValues.removeAt(index)
}
fun remove(item: Item) {
values.remove(item)
cleanValues.remove(item)
}
fun clear() {
values.clear()
cleanValues.clear()
}
operator fun get(position: Int): Item {
return values[position]
}
operator fun set(position: Int, item: Item) {
values[position] = item
cleanValues[position] = item
}
open fun notifyChanges(oldList: List<Item>, newList: List<Item>) {}
fun isEmpty() = values.isEmpty()
fun isNotEmpty() = values.isNotEmpty()
fun view(resId: Int, viewGroup: ViewGroup, attachToRoot: Boolean = false): View {
return inflater.inflate(resId, viewGroup, attachToRoot)
}
fun updateValues(arrayList: ArrayList<Item>) {
values.clear()
values += arrayList
}
fun updateValues(list: List<Item>) = updateValues(ArrayList(list))
override fun onBindViewHolder(holder: VH, position: Int) {
onBindItemViewHolder(holder, position)
}
protected fun initListeners(itemView: View, position: Int) {
if (itemView is AdapterView<*>) return
itemView.setOnClickListener {
itemClickListener?.onItemClick(position)
}
itemView.setOnLongClickListener {
itemLongClickListener?.onItemLongClick(position)
return@setOnLongClickListener itemClickListener == null
}
}
override fun getItemCount(): Int {
return values.size
}
val size get() = itemCount
private fun onBindItemViewHolder(holder: VH, position: Int) {
initListeners(holder.itemView, position)
holder.bind(position)
}
}
@@ -0,0 +1,3 @@
package com.meloda.fast.base.adapter
abstract class BaseItem
@@ -0,0 +1,35 @@
package com.meloda.fast.base.adapter
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isInvisible
import androidx.recyclerview.widget.RecyclerView
import com.meloda.fast.util.AndroidUtils
import kotlin.math.roundToInt
class EmptyHeaderAdapter(
var context: Context
) : RecyclerView.Adapter<EmptyHeaderAdapter.Holder>() {
inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = Holder(generateHeaderView())
override fun onBindViewHolder(holder: Holder, position: Int) {
}
override fun getItemCount() = 1
private fun generateHeaderView() = View(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
AndroidUtils.px(56).roundToInt()
)
isClickable = false
isEnabled = false
isFocusable = false
isInvisible = true
}
}
@@ -0,0 +1,15 @@
package com.meloda.fast.base.adapter
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
abstract class BaseHolder(v: View) : RecyclerView.ViewHolder(v) {
open fun bind(position: Int) {}
open fun bind(position: Int, payloads: MutableList<Any>?) {}
}
abstract class BindingHolder<B : ViewBinding>(protected val binding: B) : BaseHolder(binding.root)
@@ -0,0 +1,9 @@
package com.meloda.fast.base.adapter
interface OnItemClickListener {
fun onItemClick(position: Int)
}
interface OnItemLongClickListener {
fun onItemLongClick(position: Int)
}