init
This commit is contained in:
46
app/src/main/java/com/watcher/mobile/WatcherApplication.kt
Normal file
46
app/src/main/java/com/watcher/mobile/WatcherApplication.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user