-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EtherSampleMainActivity.kt
executable file
·68 lines (55 loc) · 1.98 KB
/
EtherSampleMainActivity.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
package sample.ether
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import arch.ether.Ether
import arch.ether.IProducer
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.activity_main.*
import sample.ether.city.Austin
import sample.ether.city.CityDataTrigger
import sample.ether.city.Dallas
import sample.ether.school.SchoolDataPublisher
import sample.ether.school.initSchoolSubscriber
import sample.ether.weather.WeatherDataPublisher
import sample.ether.weather.initWeatherSubscriber
/**
* Sample activity that shows how events trigger data and that results in changes to the UI
*/
class EtherSampleMainActivity : AppCompatActivity() {
private val publishers = mutableListOf<IProducer>()
private val subscribers = mutableListOf<Disposable>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initPublishers()
initSubscribers()
initTriggers()
}
/**
* Initialize the publishers. Could be defined and injected
*/
private fun initPublishers() {
publishers.add(SchoolDataPublisher())
publishers.add(WeatherDataPublisher())
}
/**
* Initialize the subscribers, Could be defined and injected
*/
private fun initSubscribers() {
subscribers.add(initWeatherSubscriber(maxTemp, minTemp))
subscribers.add(initSchoolSubscriber(schoolCount, studentCount))
subscribers.add(initLoggerSubscriber())
}
/**
* Sets up the triggers to [Ether]
*/
private fun initTriggers() {
austin.setOnClickListener { Ether.publisherOf(CityDataTrigger::class.java).publish(Austin) }
dallas.setOnClickListener { Ether.publisherOf(CityDataTrigger::class.java).publish(Dallas) }
}
override fun onDestroy() {
publishers.forEach { it.destroy() }
subscribers.forEach { it.dispose() }
super.onDestroy()
}
}