Skip to content

Commit

Permalink
add PaysLoad in bindData
Browse files Browse the repository at this point in the history
  • Loading branch information
werbhelius committed Oct 15, 2017
1 parent 5850853 commit 30651b6
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.werb.moretype"
minSdkVersion 16
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/werb/moretype/TitleViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TitleViewHolder(containerView: View) : MoreViewHolder<MainCard>(containerV
private val title = containerView.title
private val desc = containerView.desc

override fun bindData(data: MainCard) {
override fun bindData(data: MainCard, payloads: List<Any>) {
title.text = data.cardTitle
desc.text = data.cardDesc
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/werb/moretype/anim/AnimViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import kotlinx.android.synthetic.main.item_view_anim.*
*/
class AnimViewHolder(containerView: View) : MoreViewHolder<AnimType>(containerView) {

override fun bindData(data: AnimType) {
override fun bindData(data: AnimType, payloads: List<Any>) {
title.text = data.title
type.text = data.type
icon.setImageURI(data.typeIcon)
thumb.setImageURI(data.thumb)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.item_view_click_one.*
*/
class ItemClickOneViewHolder(containerView: View) : MoreViewHolder<ItemClick>(containerView) {

override fun bindData(data: ItemClick) {
override fun bindData(data: ItemClick, payloads: List<Any>) {
title.text = data.title
icon.setImageURI(data.url)
/* click in viewType */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.item_view_click_two.*
*/
class ItemClickTwoViewHolder(containerView: View) : MoreViewHolder<ItemClick>(containerView) {

override fun bindData(data: ItemClick) {
override fun bindData(data: ItemClick, payloads: List<Any>) {
title.text = data.title
icon.setImageURI(data.url)
itemView.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.item_view_complete.*
*/
class CompleteViewHolder(containerView: View) : MoreViewHolder<Complete>(containerView) {

override fun bindData(data: Complete) {
override fun bindData(data: Complete, payloads: List<Any>) {
icon.setImageURI(data.icon)
name.text = data.name
desc.text = data.desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.werb.moretype.R
*/
class FootViewHolder(containerView: View) : MoreViewHolder<Footer>(containerView) {

override fun bindData(data: Footer) {
override fun bindData(data: Footer, payloads: List<Any>) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.item_view_horizontal_item.*
*/
class HorizontalItemViewHolder(containerView: View) : MoreViewHolder<SingleText>(containerView) {

override fun bindData(data: SingleText) {
override fun bindData(data: SingleText, payloads: List<Any>) {
icon.setImageURI(data.url)
title.text = data.title
desc.text = data.desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HorizontalViewHolder(containerView: View) : MoreViewHolder<HorizontalData>
}
}

override fun bindData(data: HorizontalData) {
override fun bindData(data: HorizontalData, payloads: List<Any>) {
icon.setImageURI(data.url)
title.text = data.title
adapter.removeAllData()
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/werb/moretype/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.werb.moretype.main

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.werb.library.MoreAdapter
import com.werb.library.action.MoreClickListener
import com.werb.library.link.RegisterItem
import com.werb.moretype.R
import com.werb.moretype.data.DataServer
import com.werb.moretype.single.SingleRegisterActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
Expand All @@ -21,12 +19,25 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

adapter.apply {
register(RegisterItem(R.layout.item_view_main, MainCardViewHolder::class.java))
register(RegisterItem(R.layout.item_view_main, MainCardViewHolder::class.java, playLoadClick))
attachTo(more_list)
}

adapter.loadData(DataServer.getMainCardData())

}

private val playLoadClick = object : MoreClickListener() {
override fun onItemClick(view: View, position: Int) {
if (view.id == R.id.card_playLoad) {
val payLoad = view.tag as Boolean
if (payLoad) {
adapter.notifyItemChanged(position, PayLoadOne(true))
} else {
adapter.notifyItemChanged(position, PayLoadOne(false))
}
}
}
}

}
28 changes: 25 additions & 3 deletions app/src/main/java/com/werb/moretype/main/MainCardViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,31 @@ import kotlinx.android.synthetic.main.item_view_main.*
*/
class MainCardViewHolder(containerView: View) : MoreViewHolder<MainCard>(containerView), LayoutContainer {

override fun bindData(data: MainCard) {
card_title.text = data.cardTitle
card_desc.text = data.cardDesc
override fun bindData(data: MainCard, payloads: List<Any>) {

card_playLoad.tag = false

// user payloads we can update any view we want
if (payloads.isNotEmpty()) {
payloads.forEach {
if (it is PayLoadOne) {
if (it.load) {
card_title.text = "PayLoadOne any view you want"
card_desc.text = "Payloads will be empty"

} else {
card_title.text = data.cardTitle
card_desc.text = data.cardDesc
card_playLoad.tag = true
}
}
}
} else {
card_title.text = data.cardTitle
card_desc.text = data.cardDesc
}

addOnClickListener(card_playLoad)

main_card_layout.setOnClickListener {
when (layoutPosition) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/werb/moretype/main/PayLoadOne.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.werb.moretype.main

/** Created by wanbo <werbhelius@gmail.com> on 2017/10/15. */

data class PayLoadOne(val load: Boolean)
2 changes: 1 addition & 1 deletion app/src/main/java/com/werb/moretype/me/MeInfoViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.android.synthetic.main.item_view_about_me_info.*
*/
class MeInfoViewHolder(containerView: View) : MoreViewHolder<MeInfo>(containerView) {

override fun bindData(data: MeInfo) {
override fun bindData(data: MeInfo, payloads: List<Any>) {
val context = containerView.context
name.text = data.name
desc.text = data.desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.item_view_about_me_message.*
*/
class MeMessageViewHolder(containerView: View) : MoreViewHolder<MeMessage>(containerView) {

override fun bindData(data: MeMessage) {
override fun bindData(data: MeMessage, payloads: List<Any>) {
message.text = data.message
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.android.synthetic.main.item_view_about_me_thx.*
*/
class MeThanksViewHolder(containerView: View) : MoreViewHolder<MeThanks>(containerView) {

override fun bindData(data: MeThanks) {
override fun bindData(data: MeThanks, payloads: List<Any>) {
name.text = data.name
desc.text = data.desc
icon.setImageURI(data.url)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/werb/moretype/me/MeTitleViewType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.item_view_about_me_title.*
*/
class MeTitleViewType(containerView: View) : MoreViewHolder<String>(containerView) {

override fun bindData(data: String) {
override fun bindData(data: String, payloads: List<Any>) {
title.text = data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import kotlinx.android.synthetic.main.item_view_multi_message_in.*
/**
* Created by wanbo on 2017/7/14.
*/
class MessageInViewType(containerView: View) : MoreViewHolder<Message>(containerView) {
class MessageInViewHolder(containerView: View) : MoreViewHolder<Message>(containerView) {

override fun bindData(data: Message) {
override fun bindData(data: Message, payloads: List<Any>) {
message_icon.setImageURI(data.icon)
if (data.showTime) {
message_time.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import kotlinx.android.synthetic.main.item_view_multi_message_out.*
/**
* Created by wanbo on 2017/7/14.
*/
class MessageOutViewType(containerView: View) : MoreViewHolder<Message>(containerView) {
class MessageOutViewHolder(containerView: View) : MoreViewHolder<Message>(containerView) {

override fun bindData(data: Message) {
override fun bindData(data: Message, payloads: List<Any>) {

if (data.showTime) {
message_time.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class MultiRegisterActivity : AppCompatActivity() {
multiRegister(object : MultiLink<Message>() {
override fun link(data: Message): RegisterItem {
return if (data.me){
RegisterItem(R.layout.item_view_multi_message_out, MessageOutViewType::class.java)
RegisterItem(R.layout.item_view_multi_message_out, MessageOutViewHolder::class.java)
}else {
RegisterItem(R.layout.item_view_multi_message_in, MessageInViewType::class.java)
RegisterItem(R.layout.item_view_multi_message_in, MessageInViewHolder::class.java)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SingleRegisterActivity : AppCompatActivity() {
/* register viewType and attach to recyclerView */
adapter.apply {
register(RegisterItem(R.layout.item_view_single_type_one, SingleTypeOneViewHolder::class.java))
register(RegisterItem(R.layout.item_view_single_type_two, SingleTypeTwoViewType::class.java))
register(RegisterItem(R.layout.item_view_single_type_two, SingleTypeTwoViewHolder::class.java))
register(RegisterItem(R.layout.item_view_title, TitleViewHolder::class.java))
attachTo(single_register_list)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.item_view_single_type_one.*
*/
class SingleTypeOneViewHolder(containerView: View) : MoreViewHolder<SingleText>(containerView) {

override fun bindData(data: SingleText) {
override fun bindData(data: SingleText, payloads: List<Any>) {
title.text = data.title
desc.text = data.desc
icon.setImageURI(data.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import kotlinx.android.synthetic.main.item_view_single_type_two.*
/**
* Created by wanbo on 2017/7/14.
*/
class SingleTypeTwoViewType(containerView: View) : MoreViewHolder<SingleImage>(containerView) {
class SingleTypeTwoViewHolder(containerView: View) : MoreViewHolder<SingleImage>(containerView) {

override fun bindData(data: SingleImage) {
override fun bindData(data: SingleImage, payloads: List<Any>) {
title.text = data.title
icon.setImageURI(data.url)
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/item_view_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
android:textColor="@color/colorTextGary"
tools:text="Register one2one ViewType"/>

<android.support.v7.widget.AppCompatTextView
android:id="@+id/card_playLoad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginRight="12dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="@color/colorTextGary"
android:text="playLoad"/>

</RelativeLayout>

</android.support.v7.widget.CardView>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.novoda:bintray-release:0.5.0'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
buildToolsVersion '26.0.2'


defaultConfig {
Expand Down
7 changes: 7 additions & 0 deletions library/src/main/java/com/werb/library/MoreAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ class MoreAdapter : Adapter<MoreViewHolder<Any>>(), MoreLink, AnimExtension, Dat
val any = list[position]
holder.clickListener = bindClickListener(holder)
holder.bindData(any)
}

override fun onBindViewHolder(holder: MoreViewHolder<Any>, position: Int, payloads: MutableList<Any>?) {
payloads?.let {
val any = list[position]
holder.clickListener = bindClickListener(holder)
holder.bindData(any, payloads)
} ?: onBindViewHolder(holder, position)
}

@Suppress("UNCHECKED_CAST")
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/werb/library/MoreViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class MoreViewHolder<T : Any>(override val containerView: View) : ViewH
}

/** [bindData] bind data with T */
abstract fun bindData(data: T)
abstract fun bindData(data: T, payloads: List<Any> = arrayListOf())

/** [unBindData] unbind and release resources*/
open fun unBindData() {}
Expand Down

0 comments on commit 30651b6

Please sign in to comment.