-
Notifications
You must be signed in to change notification settings - Fork 39
/
BluetoothScannerInjectionModule.kt
79 lines (62 loc) · 3.42 KB
/
BluetoothScannerInjectionModule.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
package com.ruuvi.station.bluetooth.di
import android.app.PendingIntent
import android.content.Context
import com.ruuvi.station.R
import com.ruuvi.station.app.preferences.Preferences
import com.ruuvi.station.bluetooth.BluetoothInteractor
import com.ruuvi.station.bluetooth.BluetoothLibrary
import com.ruuvi.station.bluetooth.DefaultOnTagFoundListener
import com.ruuvi.station.bluetooth.IRuuviTagScanner
import com.ruuvi.station.bluetooth.domain.BluetoothGattInteractor
import com.ruuvi.station.bluetooth.domain.BluetoothStateReceiver
import com.ruuvi.station.bluetooth.domain.LocationInteractor
import com.ruuvi.station.bluetooth.util.ScannerSettings
import com.ruuvi.station.startup.ui.StartupActivity
import com.ruuvi.station.util.BackgroundScanModes
import com.ruuvi.station.util.TimeUtils
import com.ruuvi.station.util.test.FakeScanResultsSender
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.kodein.di.Kodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.singleton
@ExperimentalCoroutinesApi
object BluetoothScannerInjectionModule {
val module = Kodein.Module(BluetoothScannerInjectionModule.javaClass.name) {
bind<BluetoothInteractor>() with singleton {
BluetoothLibrary.getBluetoothInteractor(instance(), instance(), instance())
}
bind<BluetoothGattInteractor>() with singleton { BluetoothGattInteractor(instance(), instance(), instance(), instance(), instance()) }
bind<BluetoothStateReceiver>() with singleton { BluetoothStateReceiver(instance(), instance()) }
bind<IRuuviTagScanner.OnTagFoundListener>() with singleton { instance<DefaultOnTagFoundListener>() }
bind<DefaultOnTagFoundListener>() with singleton {
DefaultOnTagFoundListener(instance(), instance(), instance(), instance(), instance(), instance())
}
bind<FakeScanResultsSender>() with singleton { FakeScanResultsSender(instance()) }
bind<LocationInteractor>() with singleton { LocationInteractor(instance()) }
bind<ScannerSettings>() with singleton {
object : ScannerSettings {
var context = instance<Context>()
var prefs = instance<Preferences>()
override fun allowBackgroundScan(): Boolean {
return prefs.backgroundScanMode != BackgroundScanModes.DISABLED
}
override fun getBackgroundScanIntervalMilliseconds(): Long {
return prefs.backgroundScanInterval * 1000L
}
override fun getNotificationIconId() = R.drawable.ic_ruuvi_bgscan_icon
override fun getNotificationTitle(): String {
val scanInterval = prefs.backgroundScanInterval
val stringMessage = context.getString(R.string.background_notification_scanning_every)
return "$stringMessage ${TimeUtils.convertSecondsToTextTemp(context, scanInterval)}"
}
override fun getNotificationText() = context.getString(R.string.background_notification_message)
override fun getNotificationPendingIntent(): PendingIntent? {
val resultIntent = StartupActivity.createIntentForNotification(context)
return PendingIntent
.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)
}
}
}
}
}