Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
D00mch committed Apr 7, 2020
1 parent 9c9aeff commit a7ddb2c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import kotlinx.android.extensions.LayoutContainer
/**
* @author dumchev on 04.11.17.
*/
abstract class KDelegateAdapter<T>
: BaseDelegateAdapter<KDelegateAdapter.KViewHolder, T>() {
abstract class KDelegateAdapter<T> : BaseDelegateAdapter<KDelegateAdapter.KViewHolder, T>() {

open fun onCreated(view: View) = Unit

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.livermor.delegateadapter.delegate.diff.DiffUtilCompositeAdapter
import com.livermor.dumchev.delegateadapters.base.adapter.CheckDelegateAdapter
import com.livermor.dumchev.delegateadapters.base.adapter.CompositeDelegateAdapter
import com.livermor.dumchev.delegateadapters.base.adapter.GenerateItemsDelegateAdapter
import com.livermor.dumchev.delegateadapters.base.adapter.TextDelegateAdapter
import kotlinx.android.synthetic.main.activity_base_example.*
Expand All @@ -17,6 +18,7 @@ class KotlinBaseExampleActivity : AppCompatActivity() {
.add(GenerateItemsDelegateAdapter { generateNewData() })
.add(TextDelegateAdapter())
.add(CheckDelegateAdapter())
.add(CompositeDelegateAdapter(View.OnClickListener { generateNewData() }))
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.livermor.delegateadapter.delegate.diff.DiffUtilItem;
import com.livermor.dumchev.delegateadapters.R;
import com.livermor.dumchev.delegateadapters.base.model.CheckItem;
import com.livermor.dumchev.delegateadapters.base.model.CompositeModel;
import com.livermor.dumchev.delegateadapters.base.model.ImageItem;
import com.livermor.dumchev.delegateadapters.base.model.TextItem;

Expand All @@ -22,13 +23,18 @@ static List<DiffUtilItem> prepareData() {
Random random = new Random();
for (int i = 0; i < SIZE; i++) {
DiffUtilItem item;
int type = random.nextInt(3);
int type = random.nextInt(4);
if (type == 0) {
item = new TextItem("Title " + i, "Description " + i);
} else if (type == 1) {
item = new ImageItem("Title " + i, R.mipmap.ic_launcher_round);
} else {
} else if (type == 2) {
item = new CheckItem("You still love this lib", true);
} else {
item = new CompositeModel(
new ImageItem("Title " + i, R.mipmap.ic_launcher_round),
new TextItem("Title " + i, "Description " + i)
);
}
objects.add(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.example.dumchev.delegateadapters.base.adapter
package com.livermor.dumchev.delegateadapters.base.adapter

import android.view.View
import com.example.delegateadapter.delegate.KDelegateAdapter
import com.example.dumchev.delegateadapters.R
import com.example.dumchev.delegateadapters.base.model.CompositeModel
import com.livermor.delegateadapter.delegate.KDelegateAdapter
import com.livermor.dumchev.delegateadapters.R
import com.livermor.dumchev.delegateadapters.base.model.CompositeModel

/**
* @author dumchev on 11/12/2018.
*/
class CompositeDelegateAdapter(clicks: View.OnClickListener) : KDelegateAdapter<CompositeModel>() {

val textDelegateAdapter by lazy { TxtDelegateAdapter() }
val imageDelegateAdapter by lazy { ImageDelegateAdapter(clicks) }
private val textDelegateAdapter by lazy { TxtDelegateAdapter() }
private val imageDelegateAdapter by lazy { ImageDelegateAdapter(clicks) }

override fun onBind(item: CompositeModel, viewHolder: KViewHolder) {
textDelegateAdapter.onBind(item.textViewModel, viewHolder)
imageDelegateAdapter.onBind(item.imageViewModel, viewHolder)
override fun KViewHolder.onBind(item: CompositeModel) {
with(textDelegateAdapter) { onBind(item.textViewModel) }
with(imageDelegateAdapter) { onBind(item.imageViewModel) }
}

override fun getLayoutId(): Int = R.layout.composite_item

override fun isForViewType(items: MutableList<*>, position: Int): Boolean {
return items[position] is CompositeModel
}
override fun isForViewType(item: Any): Boolean = item is CompositeModel
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.example.dumchev.delegateadapters.base.model
package com.livermor.dumchev.delegateadapters.base.model

import com.example.delegateadapter.delegate.diff.IComparableItem
import com.livermor.delegateadapter.delegate.diff.KDiffUtilItem

/**
* @author dumchev on 11/12/2018.
*/
data class CompositeModel(
val imageViewModel: ImageViewModel,
val textViewModel: TextViewModel
) : IComparableItem {
val imageViewModel: ImageItem,
val textViewModel: TextItem
) : KDiffUtilItem {

override fun id(): Any = "" + imageViewModel.id() + textViewModel.id()
override val id: Any = "" + imageViewModel.id() + textViewModel.id()
override fun content(): Any = this
}

0 comments on commit a7ddb2c

Please sign in to comment.