/
MainActivity.kt
47 lines (39 loc) · 1.32 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
package dev.programadorthi.android
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import dev.programadorthi.state.core.androidValueManager
class MainActivity : AppCompatActivity() {
private val model: MainViewModel by viewModels()
private var year by androidValueManager(2024)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
/*setContent {
MaterialTheme {
App()
}
}*/
setContentView(R.layout.activity_main)
val textView = findViewById<TextView>(R.id.nameText)
val decrementButton = findViewById<Button>(R.id.decrementButton)
val incrementButton = findViewById<Button>(R.id.incrementButton)
val update = {
textView.text = model.name + " - " + year
decrementButton.text = "Decrement ${model.age}"
incrementButton.text = "Increment ${model.age}"
}
update()
decrementButton.setOnClickListener {
year--
model.decrement()
update()
}
incrementButton.setOnClickListener {
year++
model.increment()
update()
}
}
}