1
0
mirror of https://github.com/ultrasonic/ultrasonic synced 2025-02-18 04:30:48 +01:00

Don't leak context in model

This commit is contained in:
tzugen 2021-04-21 23:01:59 +02:00
parent 25f072a5d5
commit fe69141e19
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 6 additions and 5 deletions

View File

@ -31,5 +31,5 @@ val appPermanentStorage = module {
single { get<AppDatabase>().serverSettingDao() }
viewModel { ServerSettingsModel(get(), get(), androidContext()) }
viewModel { ServerSettingsModel(get(), get(), get()) }
}

View File

@ -1,9 +1,9 @@
package org.moire.ultrasonic.fragment
import android.content.Context
import android.app.Application
import android.content.SharedPreferences
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.preference.PreferenceManager
import kotlinx.coroutines.CoroutineScope
@ -22,8 +22,8 @@ import timber.log.Timber
class ServerSettingsModel(
private val repository: ServerSettingDao,
private val activeServerProvider: ActiveServerProvider,
private val context: Context
) : ViewModel() {
application: Application
) : AndroidViewModel(application) {
companion object {
private const val PREFERENCES_KEY_SERVER_MIGRATED = "serverMigrated"
@ -54,6 +54,7 @@ class ServerSettingsModel(
if (rowCount == null || rowCount == 0) {
// First time load up the server settings from the Preferences
val dbServerList = mutableListOf<ServerSetting>()
val context = getApplication<Application>().applicationContext
val settings = PreferenceManager.getDefaultSharedPreferences(context)
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)