OXYGENHUB
# 0414607973cb oxygenhub-android / app / src / main / java / io / oxygenhub / android / OxygenHubApp.kt
1.2 KiB · last changed The hub's API and device sign-in, the token in the Keystore (refs #2) 11 days ago source blame history raw
1
package io.oxygenhub.android
2
3
import android.app.Application
4
import android.os.Build
5
import io.oxygenhub.android.api.DeviceAuth
6
import io.oxygenhub.android.api.HubClient
7
import io.oxygenhub.android.api.HubDeviceAuth
8
import io.oxygenhub.android.api.hubHttpClient
9
import io.oxygenhub.android.auth.KeystoreSessionStore
10
import io.oxygenhub.android.auth.SessionManager
11
import okhttp3.OkHttpClient
12
13
/** The hub the app signs in to unless told otherwise. */
14
const val DEFAULT_HUB = "https://oxygenhub.io"
15
16
/** The app's shared objects, made once. A small hand-made container: no DI framework yet. */
17
class AppContainer(app: Application) {
18
    val http: OkHttpClient = hubHttpClient()
19
20
    val sessions = SessionManager(KeystoreSessionStore(app)) { session, onUnauthorized ->
21
        HubClient(session.hub, session.token, http, onUnauthorized)
22
    }
23
24
    fun deviceAuth(hub: String): DeviceAuth = HubDeviceAuth(hub, http)
25
26
    /** What the app calls itself on the hub's /device page and token list. */
27
    val clientName: String = "OxygenHub for Android on ${Build.MODEL}".take(80)
28
}
29
30
class OxygenHubApp : Application() {
31
    lateinit var container: AppContainer
32
        private set
33
34
    override fun onCreate() {
35
        super.onCreate()
36
        container = AppContainer(this)
37
    }
38
}