Fix settings not persisted

This commit is contained in:
Mygod
2018-04-21 14:30:00 -07:00
parent 5c3b2363f5
commit 7f81b3ae33
4 changed files with 30 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ import android.widget.Toast
class App : Application() {
companion object {
const val ACTION_CLEAN_ROUTINGS = "be.mygod.vpnhotspot.CLEAN_ROUTINGS"
private const val KEY_DNS = "service.dns"
@SuppressLint("StaticFieldLeak")
lateinit var app: App
@@ -27,6 +28,8 @@ class App : Application() {
deviceContext = createDeviceProtectedStorageContext()
deviceContext.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this))
} else deviceContext = this
// workaround for support lib PreferenceDataStore bug
dns = dns
ServiceNotification.updateNotificationChannels()
}
@@ -40,5 +43,9 @@ class App : Application() {
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceContext) }
val connectivity by lazy { getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
var dns: String
get() = pref.getString(KEY_DNS, "8.8.8.8")
set(value) = pref.edit().putString(KEY_DNS, value).apply()
fun toast(@StringRes resId: Int) = handler.post { Toast.makeText(this, resId, Toast.LENGTH_SHORT).show() }
}