Bimba.git

ref: a72c45eb44dfc2a63f8d9df2541e4308adb43e62

app/src/main/java/ml/adamsprogs/bimba/MessageReceiver.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
package ml.adamsprogs.bimba

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class MessageReceiver: BroadcastReceiver() {
    val onTimetableDownloadListeners: HashSet<OnTimetableDownloadListener> = HashSet()

    override fun onReceive(context: Context?, intent: Intent?) {
        val result = intent?.getStringExtra("result")
        for (listener in onTimetableDownloadListeners) {
            listener.onTimetableDownload(result)
        }
    }

    fun addOnTimetableDownloadListener(listener: OnTimetableDownloadListener) {
        onTimetableDownloadListeners.add(listener)
    }

    fun removeOnTimetableDownloadListener(listener: OnTimetableDownloadListener) {
        onTimetableDownloadListeners.remove(listener)
    }

    interface OnTimetableDownloadListener {
        fun onTimetableDownload(result: String?)
    }
}