47 lines
1.3 KiB
Kotlin
47 lines
1.3 KiB
Kotlin
package com.watcher.mobile
|
|
|
|
import android.app.Application
|
|
import com.watcher.mobile.network.RetrofitClient
|
|
import com.watcher.mobile.utils.PreferencesManager
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.flow.first
|
|
import kotlinx.coroutines.launch
|
|
|
|
/**
|
|
* Application Class für globale Initialisierung
|
|
*/
|
|
class WatcherApplication : Application() {
|
|
|
|
lateinit var preferencesManager: PreferencesManager
|
|
private set
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
|
|
// Preferences Manager initialisieren
|
|
preferencesManager = PreferencesManager(this)
|
|
|
|
// Retrofit mit gespeicherten Einstellungen initialisieren
|
|
initializeRetrofitClient()
|
|
}
|
|
|
|
private fun initializeRetrofitClient() {
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
val apiUrl = preferencesManager.apiBaseUrl.first()
|
|
val apiKey = preferencesManager.apiKey.first()
|
|
|
|
if (!apiUrl.isNullOrEmpty()) {
|
|
RetrofitClient.initialize(apiUrl, apiKey)
|
|
} else {
|
|
// Default URL aus BuildConfig verwenden
|
|
RetrofitClient.initialize(BuildConfig.API_BASE_URL, null)
|
|
}
|
|
}
|
|
}
|
|
|
|
companion object {
|
|
const val TAG = "WatcherApp"
|
|
}
|
|
}
|