Skip to content

Commit

Permalink
Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaishnav Anil committed Aug 26, 2023
1 parent e3c46e2 commit bc4c9bb
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions app/src/main/java/io/github/vshnv/adapt/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ package io.github.vshnv.adapt

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import androidx.viewbinding.ViewBinding
import io.github.vshnv.adapt.databinding.ActivityMainBinding
import io.github.vshnv.adapt.databinding.LayoutTextItemBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MainActivity : AppCompatActivity() {

Expand All @@ -25,26 +18,23 @@ class MainActivity : AppCompatActivity() {
val view = binding.root
setContentView(view)
adapter = adapt {
create {
defineViewTypes { data, position ->
if (data.toInt() % 5 == 0 || data.toInt() % 15 == 0) {
2
} else 1
}
create(1) {
ViewSource.BindingViewSource(LayoutTextItemBinding.inflate(layoutInflater), ViewBinding::getRoot)
}.bind { model, layoutTextItemBinding ->
layoutTextItemBinding.tvTest.text = model
layoutTextItemBinding.tvTest.text = model + " TYPE_1"
}
}
binding.rvTest.adapter = adapter
GlobalScope.launch {
val list = mutableListOf<Int>()
for (i in (1..1000)) {
delay(1000)
list.add(i)
if (i % 9 == 0) {
list.shuffle()
}
withContext(Dispatchers.Main) {
adapter.submitData(list.map { it.toString() })
}
create(2) {
ViewSource.BindingViewSource(LayoutTextItemBinding.inflate(layoutInflater), ViewBinding::getRoot)
}.bind { model, layoutTextItemBinding ->
layoutTextItemBinding.tvTest.text = model + " TYPE_2"
}
}
binding.rvTest.adapter = adapter
}

override fun onResume() {
Expand Down

0 comments on commit bc4c9bb

Please sign in to comment.