-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathTimeTrackerApp.kt
More file actions
73 lines (64 loc) · 1.95 KB
/
TimeTrackerApp.kt
File metadata and controls
73 lines (64 loc) · 1.95 KB
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
package com.example.util.simpletimetracker
import android.app.Application
import android.os.StrictMode
import androidx.emoji2.bundled.BundledEmojiCompatConfig
import androidx.emoji2.text.EmojiCompat
import com.example.util.simpletimetracker.api.WebApiAdapter
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import timber.log.Timber
import timber.log.Timber.DebugTree
import javax.inject.Inject
@HiltAndroidApp
class TimeTrackerApp : Application() {
@Inject
lateinit var webApiAdapter: WebApiAdapter
private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
override fun onCreate() {
super.onCreate()
initLog()
initLibraries()
initStrictMode()
startWebApi()
}
private fun initLog() {
if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
}
}
private fun initLibraries() {
val config = BundledEmojiCompatConfig(applicationContext)
.setReplaceAll(true)
EmojiCompat.init(config)
}
private fun initStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDialog()
.build(),
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build(),
)
}
}
private fun startWebApi() {
applicationScope.launch {
try {
webApiAdapter.start()
Timber.d("Web API started on port 8080")
} catch (e: Exception) {
Timber.e(e, "Failed to start Web API")
}
}
}
}