1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
package ca.allanwang.kau.about
import android.os.Build
import androidx.recyclerview.widget.RecyclerView
import android.text.Html
import android.view.View
import android.widget.TextView
import androidx.cardview.widget.CardView
import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
import ca.allanwang.kau.iitems.KauIItem
import ca.allanwang.kau.utils.gone
import ca.allanwang.kau.utils.startLink
import ca.allanwang.kau.utils.visible
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.IItem
/**
* Created by Allan Wang on 2017-06-27.
*/
class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewHolder>(
R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library
), ThemableIItem by ThemableIItemDelegate() {
companion object {
fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fastAdapter.withSelectable(false)
.withOnClickListener { v, _, item, _ ->
if (item !is LibraryIItem)
false
else
with(item.lib) {
v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite)
true
}
}
}
}
override fun isSelectable(): Boolean = false
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
with(holder) {
name.text = lib.libraryName
creator.text = lib.author
@Suppress("DEPRECATION")
description.text = when {
lib.libraryDescription.isBlank() -> lib.libraryDescription
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> Html.fromHtml(lib.libraryDescription, Html.FROM_HTML_MODE_LEGACY)
else -> Html.fromHtml(lib.libraryDescription)
}
bottomDivider.gone()
if (lib.libraryVersion?.isNotBlank() == true) {
bottomDivider.visible()
version.visible().text = lib.libraryVersion
}
if (lib.license?.licenseName?.isNotBlank() == true) {
bottomDivider.visible()
license.visible().text = lib.license?.licenseName
}
bindTextColor(name, creator)
bindTextColorSecondary(description)
bindAccentColor(license, version)
bindDividerColor(divider, bottomDivider)
bindBackgroundRipple(card)
}
}
override fun unbindView(holder: ViewHolder) {
super.unbindView(holder)
with(holder) {
name.text = null
creator.text = null
description.text = null
bottomDivider.gone()
version.gone().text = null
license.gone().text = null
}
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val card: CardView = v.findViewById(R.id.lib_item_card)
val name: TextView = v.findViewById(R.id.lib_item_name)
val creator: TextView = v.findViewById(R.id.lib_item_author)
val description: TextView = v.findViewById(R.id.lib_item_description)
val version: TextView = v.findViewById(R.id.lib_item_version)
val license: TextView = v.findViewById(R.id.lib_item_license)
val divider: View = v.findViewById(R.id.lib_item_top_divider)
val bottomDivider: View = v.findViewById(R.id.lib_item_bottom_divider)
}
}
|