-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainActivity.kt
84 lines (71 loc) · 2.93 KB
/
MainActivity.kt
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
package com.worldsnas.sliderlibrary
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.epoxy.EpoxyRecyclerView
import com.google.android.material.snackbar.Snackbar
import com.worldsnas.slider.slider
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
lateinit var list: EpoxyRecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
list = findViewById(R.id.list)
val banners = listOf("https://unsplash.com/photos/hud8Oa4D5Gs/download?force=true",
"https://unsplash.com/photos/0r1gjbBrGeM/download?force=true",
"https://unsplash.com/photos/FOUxD6zodR4/download?force=true",
"https://unsplash.com/photos/M19_crm09Zw/download?force=true",
"https://unsplash.com/photos/F-JUGSYNjZU/download?force=true",
"https://unsplash.com/photos/N2X20_MlF20/download?force=true",
"https://unsplash.com/photos/OeGImGbmxls/download?force=true",
"https://unsplash.com/photos/-g7axSVst6Y/download?force=true",
"https://unsplash.com/photos/KZC7BJo0Cl0/download?force=true",
"https://unsplash.com/photos/tzzj8LCLujU/download?force=true"
)
list.layoutManager = LinearLayoutManager(this)
list.withModels {
slider {
id("slider")
cycleDelay(3_000)
indicatorVisible(true)
indicatorSelectedDotColor(Color.YELLOW)
indicatorDotColor(Color.BLACK)
models(
banners.mapIndexed { index, s ->
BannerViewModel_().apply {
id(index.toLong())
bindImage(s)
listener {
showImageUrl(it)
}
}
}
)
infinite(true)
copier { oldModel ->
oldModel as BannerViewModel_
BannerViewModel_().apply {
id(oldModel.id())
bindImage(banners[oldModel.id().toInt()])
listener { imageUrl ->
showImageUrl(imageUrl)
}
}
}
}
}
}
private fun showImageUrl(imageUrl: String?) {
Toast.makeText(
this@MainActivity,
imageUrl,
Toast.LENGTH_SHORT
).show()
}
}