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:
parent
25f072a5d5
commit
fe69141e19
@ -31,5 +31,5 @@ val appPermanentStorage = module {
|
||||
|
||||
single { get<AppDatabase>().serverSettingDao() }
|
||||
|
||||
viewModel { ServerSettingsModel(get(), get(), androidContext()) }
|
||||
viewModel { ServerSettingsModel(get(), get(), get()) }
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user