From 97fdad7004e43241eaa87cfafb16df8f5af2e77c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 17 Jun 2019 23:50:32 -0700 Subject: Fix extra dependency errors --- .../ca/allanwang/kau/adapters/AdapterUtils.kt | 44 ----- .../kau/adapters/FastItemThemedAdapter.kt | 201 --------------------- .../kau/adapters/RepeatedClickListener.kt | 70 ------- .../kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 140 -------------- .../kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt | 59 ------ .../kotlin/ca/allanwang/kau/iitems/KauIItem.kt | 42 ----- 6 files changed, 556 deletions(-) delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt delete mode 100644 adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt (limited to 'adapter') diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt deleted file mode 100644 index 17fd09f..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2018 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.kau.adapters - -import com.mikepenz.fastadapter.FastAdapter -import com.mikepenz.fastadapter.IAdapter -import com.mikepenz.fastadapter.IAdapterExtension -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.select.SelectExtension - -/** - * Created by Allan Wang on 2017-11-08. - */ - -/** - * Add kotlin's generic syntax to better support out types - */ -fun > fastAdapter(vararg adapter: IAdapter) = - FastAdapter.with>(adapter.toList())!! - -inline fun , Item : IItem<*, *>> FastAdapter.getExtension(): T? = - getExtension(T::class.java) - -/** - * Returns selection size, or -1 if selection is disabled - */ -inline val > IAdapter.selectionSize: Int - get() = fastAdapter.getExtension, Item>()?.selections?.size ?: -1 - -inline val > IAdapter.selectedItems: Set - get() = fastAdapter.getExtension, Item>()?.selectedItems ?: emptySet() diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt deleted file mode 100644 index 152982f..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2018 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.kau.adapters - -import android.content.res.ColorStateList -import android.os.Build -import android.view.View -import android.widget.ImageView -import android.widget.TextView -import androidx.annotation.RequiresApi -import ca.allanwang.kau.ui.createSimpleRippleDrawable -import ca.allanwang.kau.utils.adjustAlpha -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter - -/** - * Created by Allan Wang on 2017-06-29. - * - * Adapter with a set of colors that will be added to all subsequent items - * Changing a color while the adapter is not empty will reload all items - * - * This adapter overrides every method where an item is added - * If that item extends [ThemableIItem], then the colors will be set - */ -class FastItemThemedAdapter>( - textColor: Int? = null, - backgroundColor: Int? = null, - accentColor: Int? = null -) : FastItemAdapter() { - constructor(colors: ThemableIItemColors) : this(colors.textColor, colors.backgroundColor, colors.accentColor) - - var textColor: Int? = textColor - set(value) { - if (field == value) return - field = value - themeChanged() - } - var backgroundColor: Int? = backgroundColor - set(value) { - if (field == value) return - field = value - themeChanged() - } - var accentColor: Int? = accentColor - set(value) { - if (field == value) return - field = value - themeChanged() - } - - fun setColors(colors: ThemableIItemColors) { - this.textColor = colors.textColor - this.backgroundColor = colors.backgroundColor - this.accentColor = colors.accentColor - } - - fun themeChanged() { - if (adapterItemCount == 0) return - injectTheme(adapterItems) - notifyAdapterDataSetChanged() - } - - override fun add(position: Int, items: List): FastItemAdapter { - injectTheme(items) - return super.add(position, items) - } - - override fun add(position: Int, item: Item): FastItemAdapter { - injectTheme(item) - return super.add(position, item) - } - - override fun add(item: Item): FastItemAdapter { - injectTheme(item) - return super.add(item) - } - - override fun add(items: List?): FastItemAdapter { - injectTheme(items) - return super.add(items) - } - - override fun set(items: List?): FastItemAdapter { - injectTheme(items) - return super.set(items) - } - - override fun set(position: Int, item: Item): FastItemAdapter { - injectTheme(item) - return super.set(position, item) - } - - override fun setNewList(items: List?, retainFilter: Boolean): FastItemAdapter { - injectTheme(items) - return super.setNewList(items, retainFilter) - } - - override fun setNewList(items: List?): FastItemAdapter { - injectTheme(items) - return super.setNewList(items) - } - - private fun injectTheme(items: Collection?>?) { - items?.forEach { injectTheme(it) } - } - - protected fun injectTheme(item: IItem<*, *>?) { - if (item is ThemableIItem && item.themeEnabled) { - item.textColor = textColor - item.backgroundColor = backgroundColor - item.accentColor = accentColor - } - } -} - -interface ThemableIItemColors { - var textColor: Int? - var backgroundColor: Int? - var accentColor: Int? -} - -class ThemableIItemColorsDelegate : ThemableIItemColors { - override var textColor: Int? = null - override var backgroundColor: Int? = null - override var accentColor: Int? = null -} - -/** - * Interface that needs to be implemented by every iitem - * Holds the color values and has helper methods to inject the colors - */ -interface ThemableIItem : ThemableIItemColors { - var themeEnabled: Boolean - fun bindTextColor(vararg views: TextView?) - fun bindTextColorSecondary(vararg views: TextView?) - fun bindDividerColor(vararg views: View?) - fun bindAccentColor(vararg views: TextView?) - fun bindBackgroundColor(vararg views: View?) - fun bindBackgroundRipple(vararg views: View?) - fun bindIconColor(vararg views: ImageView?) -} - -/** - * The delegate for [ThemableIItem] - */ -class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIItemColorsDelegate() { - override var themeEnabled: Boolean = true - - override fun bindTextColor(vararg views: TextView?) { - val color = textColor ?: return - views.forEach { it?.setTextColor(color) } - } - - override fun bindTextColorSecondary(vararg views: TextView?) { - val color = textColor?.adjustAlpha(0.8f) ?: return - views.forEach { it?.setTextColor(color) } - } - - override fun bindAccentColor(vararg views: TextView?) { - val color = accentColor ?: textColor ?: return - views.forEach { it?.setTextColor(color) } - } - - override fun bindDividerColor(vararg views: View?) { - val color = (textColor ?: accentColor)?.adjustAlpha(0.1f) ?: return - views.forEach { it?.setBackgroundColor(color) } - } - - override fun bindBackgroundColor(vararg views: View?) { - val color = backgroundColor ?: return - views.forEach { it?.setBackgroundColor(color) } - } - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - override fun bindBackgroundRipple(vararg views: View?) { - val background = backgroundColor ?: return - val foreground = accentColor ?: textColor ?: backgroundColor - ?: return //default to normal background - val ripple = createSimpleRippleDrawable(foreground, background) - views.forEach { it?.background = ripple } - } - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - override fun bindIconColor(vararg views: ImageView?) { - val color = accentColor ?: textColor ?: return - views.forEach { it?.drawable?.setTintList(ColorStateList.valueOf(color)) } - } -} diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt deleted file mode 100644 index 40b4774..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 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.kau.adapters - -import android.view.View -import androidx.annotation.IntRange -import com.mikepenz.fastadapter.FastAdapter -import com.mikepenz.fastadapter.IAdapter -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.listeners.OnClickListener - -/** - * Created by Allan Wang on 26/12/17. - */ -fun > FastAdapter.withOnRepeatedClickListener( - count: Int, - duration: Long, - event: OnClickListener -) = - withOnClickListener(RepeatedClickListener(count, duration, event)) - -/** - * Registers and skips each click until the designated [count] clicks are triggered, - * each within [duration] from each other. - * Only then will the [event] be fired, and everything will be reset. - */ -private class RepeatedClickListener>( - @IntRange(from = 1) val count: Int, - @IntRange(from = 1) val duration: Long, - val event: OnClickListener -) : OnClickListener { - - init { - if (count <= 0) - throw IllegalArgumentException("RepeatedClickListener's count must be > 1") - if (duration <= 0) - throw IllegalArgumentException("RepeatedClickListener's duration must be > 1L") - } - - private var chain = 0 - private var time = -1L - - override fun onClick(v: View?, adapter: IAdapter, item: Item, position: Int): Boolean { - val now = System.currentTimeMillis() - if (time - now < duration) - chain++ - else - chain = 1 - time = now - if (chain == count) { - chain = 0 - event.onClick(v, adapter, item, position) - return true - } - return false - } -} diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt deleted file mode 100644 index 6e33833..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2018 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.kau.iitems - -import android.graphics.Color -import android.graphics.drawable.Drawable -import android.view.View -import android.widget.Button -import android.widget.ImageView -import android.widget.LinearLayout -import android.widget.TextView -import androidx.cardview.widget.CardView -import androidx.recyclerview.widget.RecyclerView -import ca.allanwang.kau.adapter.R -import ca.allanwang.kau.adapters.ThemableIItem -import ca.allanwang.kau.adapters.ThemableIItemDelegate -import ca.allanwang.kau.utils.INVALID_ID -import ca.allanwang.kau.utils.drawable -import ca.allanwang.kau.utils.gone -import ca.allanwang.kau.utils.string -import ca.allanwang.kau.utils.toDrawable -import ca.allanwang.kau.utils.visible -import com.mikepenz.fastadapter.FastAdapter -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.listeners.ClickEventHook -import com.mikepenz.iconics.typeface.IIcon - -/** - * Created by Allan Wang on 2017-06-28. - * - * Simple generic card item with an icon, title, description and button - * The icon and button are hidden by default unless values are given - */ -class CardIItem( - val builder: Config.() -> Unit = {} -) : KauIItem( - R.layout.kau_iitem_card, ::ViewHolder, R.id.kau_item_card -), ThemableIItem by ThemableIItemDelegate() { - - companion object { - fun bindClickEvents(fastAdapter: FastAdapter>) { - fastAdapter.withEventHook(object : ClickEventHook>() { - override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List? { - return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null - } - - override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*, *>) { - if (item !is CardIItem) return - with(item.configs) { - when (v.id) { - R.id.kau_card_container -> cardClick?.invoke() - R.id.kau_card_button -> buttonClick?.invoke() - else -> { - } - } - } - } - }) - } - } - - val configs = Config().apply { builder() } - - class Config { - var title: String? = null - var titleRes: Int = INVALID_ID - var desc: String? = null - var descRes: Int = INVALID_ID - var button: String? = null - var buttonRes: Int = INVALID_ID - var buttonClick: (() -> Unit)? = null - var cardClick: (() -> Unit)? = null - var image: Drawable? = null - var imageIIcon: IIcon? = null - var imageIIconColor: Int = Color.WHITE - var imageRes: Int = INVALID_ID - } - - override fun bindView(holder: ViewHolder, payloads: MutableList) { - super.bindView(holder, payloads) - with(holder.itemView.context) context@{ - with(configs) { - holder.title.text = string(titleRes, title) - val descText = string(descRes, desc) - if (descText != null) holder.description.visible().text = descText - val buttonText = string(buttonRes, button) - if (buttonText != null) { - holder.bottomRow.visible() - holder.button.text = buttonText - } - val icon = drawable(imageRes) { - imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) - ?: image - } - if (icon != null) holder.icon.visible().setImageDrawable(icon) - } - with(holder) { - bindTextColor(title) - bindTextColorSecondary(description) - bindAccentColor(button) - if (configs.imageIIcon != null) bindIconColor(icon) - bindBackgroundRipple(card) - } - } - } - - override fun unbindView(holder: ViewHolder) { - super.unbindView(holder) - with(holder) { - icon.gone().setImageDrawable(null) - title.text = null - description.gone().text = null - bottomRow.gone() - button.setOnClickListener(null) - card.setOnClickListener(null) - } - } - - class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val card: CardView = v.findViewById(R.id.kau_card_container) - val icon: ImageView = v.findViewById(R.id.kau_card_image) - val title: TextView = v.findViewById(R.id.kau_card_title) - val description: TextView = v.findViewById(R.id.kau_card_description) - val bottomRow: LinearLayout = v.findViewById(R.id.kau_card_bottom_row) - val button: Button = v.findViewById(R.id.kau_card_button) - } -} diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt deleted file mode 100644 index 2c488b1..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018 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.kau.iitems - -import android.view.View -import android.widget.TextView -import androidx.cardview.widget.CardView -import androidx.recyclerview.widget.RecyclerView -import ca.allanwang.kau.adapter.R -import ca.allanwang.kau.adapters.ThemableIItem -import ca.allanwang.kau.adapters.ThemableIItemDelegate -import ca.allanwang.kau.utils.INVALID_ID -import ca.allanwang.kau.utils.string - -/** - * Created by Allan Wang on 2017-06-28. - * - * Simple Header with lots of padding on the top - * Contains only one text view - */ -class HeaderIItem( - text: String? = null, - var textRes: Int = INVALID_ID -) : KauIItem( - R.layout.kau_iitem_header, { ViewHolder(it) }, R.id.kau_item_header_big_margin_top -), ThemableIItem by ThemableIItemDelegate() { - - var text: String = text ?: "Header Placeholder" - - override fun bindView(holder: ViewHolder, payloads: MutableList) { - super.bindView(holder, payloads) - holder.text.text = holder.itemView.context.string(textRes, text) - bindTextColor(holder.text) - bindBackgroundColor(holder.container) - } - - override fun unbindView(holder: ViewHolder) { - super.unbindView(holder) - holder.text.text = null - } - - class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val text: TextView = v.findViewById(R.id.kau_header_text) - val container: CardView = v.findViewById(R.id.kau_header_container) - } -} diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt deleted file mode 100644 index c66dc01..0000000 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2018 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.kau.iitems - -import android.annotation.SuppressLint -import android.view.View -import androidx.annotation.LayoutRes -import androidx.recyclerview.widget.RecyclerView -import com.mikepenz.fastadapter.IClickable -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.items.AbstractItem - -/** - * Created by Allan Wang on 2017-07-03. - * - * Kotlin implementation of the [AbstractItem] to make things shorter - * If only one iitem type extends the given [layoutRes], you may use it as the type and not worry about another id - */ -open class KauIItem( - @param:LayoutRes private val layoutRes: Int, - private val viewHolder: (v: View) -> VH, - private val type: Int = layoutRes -) : AbstractItem() where Item : IItem<*, *>, Item : IClickable<*> { - @SuppressLint("ResourceType") - final override fun getType(): Int = type - - final override fun getViewHolder(v: View): VH = viewHolder(v) - final override fun getLayoutRes(): Int = layoutRes -} -- cgit v1.2.3