aboutsummaryrefslogtreecommitdiff
path: root/fastadapter-databinding
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-10-20 00:09:20 -0700
committerAllan Wang <me@allanwang.ca>2019-10-20 00:09:20 -0700
commit2e13634663cb3c511e4aed556db06a20d8bff6f4 (patch)
treef583a09a7ab9df68fe7e7b9b21000916d7f07c38 /fastadapter-databinding
parentc253ae07a96ba91fa4801039358a2bef52881c53 (diff)
downloadkau-2e13634663cb3c511e4aed556db06a20d8bff6f4.tar.gz
kau-2e13634663cb3c511e4aed556db06a20d8bff6f4.tar.bz2
kau-2e13634663cb3c511e4aed556db06a20d8bff6f4.zip
Generify data binding to view binding
Diffstat (limited to 'fastadapter-databinding')
-rw-r--r--fastadapter-databinding/.gitignore1
-rw-r--r--fastadapter-databinding/build.gradle21
-rw-r--r--fastadapter-databinding/consumer-rules.pro0
-rw-r--r--fastadapter-databinding/proguard-rules.pro21
-rw-r--r--fastadapter-databinding/src/main/AndroidManifest.xml1
-rw-r--r--fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt123
6 files changed, 0 insertions, 167 deletions
diff --git a/fastadapter-databinding/.gitignore b/fastadapter-databinding/.gitignore
deleted file mode 100644
index 796b96d..0000000
--- a/fastadapter-databinding/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/fastadapter-databinding/build.gradle b/fastadapter-databinding/build.gradle
deleted file mode 100644
index aefb22e..0000000
--- a/fastadapter-databinding/build.gradle
+++ /dev/null
@@ -1,21 +0,0 @@
-import kau.Dependencies
-import kau.Versions
-
-ext.kauSubModuleMinSdk = Versions.coreMinSdk
-
-apply from: '../android-lib.gradle'
-
-android {
- dataBinding {
- enabled = true
- }
-}
-
-dependencies {
- implementation project(':core')
-
- api Dependencies.fastAdapter
- api Dependencies.fastAdapter("utils")
-}
-
-apply from: '../artifacts.gradle'
diff --git a/fastadapter-databinding/consumer-rules.pro b/fastadapter-databinding/consumer-rules.pro
deleted file mode 100644
index e69de29..0000000
--- a/fastadapter-databinding/consumer-rules.pro
+++ /dev/null
diff --git a/fastadapter-databinding/proguard-rules.pro b/fastadapter-databinding/proguard-rules.pro
deleted file mode 100644
index f1b4245..0000000
--- a/fastadapter-databinding/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
diff --git a/fastadapter-databinding/src/main/AndroidManifest.xml b/fastadapter-databinding/src/main/AndroidManifest.xml
deleted file mode 100644
index acd1012..0000000
--- a/fastadapter-databinding/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1 +0,0 @@
-<manifest package="ca.allanwang.kau.fastadapter.databinding" />
diff --git a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
deleted file mode 100644
index b2b0f26..0000000
--- a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2019 Allan Wang
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ca.allanwang.fastadapter.databinding
-
-import android.content.Context
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.databinding.DataBindingUtil
-import androidx.databinding.ViewDataBinding
-import androidx.recyclerview.widget.RecyclerView
-import ca.allanwang.kau.logging.KL
-import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.GenericItem
-import com.mikepenz.fastadapter.items.AbstractItem
-import com.mikepenz.fastadapter.listeners.ClickEventHook
-
-interface VhModel {
- fun vh(): GenericItem
-}
-
-abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) :
- AbstractItem<BindingItem.ViewHolder>(),
- BindingLayout<Binding> {
-
- override val type: Int
- get() = layoutRes
-
- override fun createView(ctx: Context, parent: ViewGroup?): View {
- val binding: ViewDataBinding = DataBindingUtil.inflate(
- LayoutInflater.from(ctx),
- layoutRes, parent,
- false
- )
- return binding.root
- }
-
- fun getBinding(holder: ViewHolder): Binding? =
- DataBindingUtil.getBinding<Binding>(holder.itemView)
-
- final override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
- super.bindView(holder, payloads)
- val binding = getBinding(holder) ?: return
- binding.bindView(holder, payloads)
- binding.executePendingBindings()
- }
-
- abstract fun Binding.bindView(holder: ViewHolder, payloads: MutableList<Any>)
-
- final override fun unbindView(holder: ViewHolder) {
- super.unbindView(holder)
- val binding = DataBindingUtil.getBinding<Binding>(holder.itemView) ?: return
- binding.unbindView(holder)
- binding.unbind()
- }
-
- open fun Binding.unbindView(holder: ViewHolder) {}
-
- final override fun getViewHolder(v: View): ViewHolder = ViewHolder(v, layoutRes)
-
- override fun failedToRecycle(holder: ViewHolder): Boolean {
- KL.e { "Failed to recycle" }
- return super.failedToRecycle(holder)
- }
-
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is BindingItem<*>) return false
- return identifier == other.identifier && data == other.data
- }
-
- override fun hashCode(): Int = data.hashCode()
-
- class ViewHolder(itemView: View, internal val layoutRes: Int) :
- RecyclerView.ViewHolder(itemView)
-}
-
-interface BindingLayout<Binding : ViewDataBinding> {
- val layoutRes: Int
-}
-
-abstract class BindingClickEventHook<Binding : ViewDataBinding, Item : BindingItem<Binding>>(val identifier: BindingLayout<Binding>) :
- ClickEventHook<Item>() {
-
- private fun RecyclerView.ViewHolder.binding(): Binding? {
- val holder = this as? BindingItem.ViewHolder ?: return null
- if (holder.layoutRes != identifier.layoutRes) {
- return null
- }
- return DataBindingUtil.getBinding(itemView)
- }
-
- final override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
- viewHolder.binding()?.onBind(viewHolder) ?: super.onBind(viewHolder)
-
- open fun Binding.onBind(viewHolder: RecyclerView.ViewHolder): View? = super.onBind(viewHolder)
-
- final override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
- viewHolder.binding()?.onBindMany(viewHolder) ?: super.onBindMany(viewHolder)
-
- open fun Binding.onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
- super.onBindMany(viewHolder)
-
- final override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<Item>, item: Item) {
- val binding: Binding = DataBindingUtil.findBinding(v) ?: return
- binding.onClick(v, position, fastAdapter, item)
- }
-
- abstract fun Binding.onClick(v: View, position: Int, fastAdapter: FastAdapter<Item>, item: Item)
-}