mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-06-09 12:02:11 +03:00
Don't leak context in model
This commit is contained in:
parent
25f072a5d5
commit
fe69141e19
@ -31,5 +31,5 @@ val appPermanentStorage = module {
|
|||||||
|
|
||||||
single { get<AppDatabase>().serverSettingDao() }
|
single { get<AppDatabase>().serverSettingDao() }
|
||||||
|
|
||||||
viewModel { ServerSettingsModel(get(), get(), androidContext()) }
|
viewModel { ServerSettingsModel(get(), get(), get()) }
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package org.moire.ultrasonic.fragment
|
package org.moire.ultrasonic.fragment
|
||||||
|
|
||||||
import android.content.Context
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -22,8 +22,8 @@ import timber.log.Timber
|
|||||||
class ServerSettingsModel(
|
class ServerSettingsModel(
|
||||||
private val repository: ServerSettingDao,
|
private val repository: ServerSettingDao,
|
||||||
private val activeServerProvider: ActiveServerProvider,
|
private val activeServerProvider: ActiveServerProvider,
|
||||||
private val context: Context
|
application: Application
|
||||||
) : ViewModel() {
|
) : AndroidViewModel(application) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PREFERENCES_KEY_SERVER_MIGRATED = "serverMigrated"
|
private const val PREFERENCES_KEY_SERVER_MIGRATED = "serverMigrated"
|
||||||
@ -54,6 +54,7 @@ class ServerSettingsModel(
|
|||||||
if (rowCount == null || rowCount == 0) {
|
if (rowCount == null || rowCount == 0) {
|
||||||
// First time load up the server settings from the Preferences
|
// First time load up the server settings from the Preferences
|
||||||
val dbServerList = mutableListOf<ServerSetting>()
|
val dbServerList = mutableListOf<ServerSetting>()
|
||||||
|
val context = getApplication<Application>().applicationContext
|
||||||
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user