mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
Remove DefaultSharedPreferences
since we now have @DefaultPreferences which provide a singleton.
Some fun has been moved to injectable classes due to this change. Not compiling, still work to do, but I prefer to split into 2 separate commits.
This commit is contained in:
parent
0324927b04
commit
5736c8f648
13 changed files with 183 additions and 195 deletions
|
@ -53,7 +53,7 @@ import im.vector.app.core.resources.BuildMeta
|
|||
import im.vector.app.features.analytics.VectorAnalytics
|
||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||
import im.vector.app.features.configuration.VectorConfiguration
|
||||
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
||||
import im.vector.app.features.disclaimer.DisclaimerDialog
|
||||
import im.vector.app.features.invite.InvitesAcceptor
|
||||
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||
|
@ -110,6 +110,7 @@ class VectorApplication :
|
|||
@Inject lateinit var buildMeta: BuildMeta
|
||||
@Inject lateinit var leakDetector: LeakDetector
|
||||
@Inject lateinit var vectorLocale: VectorLocale
|
||||
@Inject lateinit var disclaimerDialog: DisclaimerDialog
|
||||
|
||||
// font thread handler
|
||||
private var fontThreadHandler: Handler? = null
|
||||
|
@ -172,7 +173,7 @@ class VectorApplication :
|
|||
val sessionImported = legacySessionImporter.process()
|
||||
if (!sessionImported) {
|
||||
// Do not display the name change popup
|
||||
doNotShowDisclaimerDialog(this)
|
||||
disclaimerDialog.doNotShowDisclaimerDialog()
|
||||
}
|
||||
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.di
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.preference.PreferenceManager
|
||||
|
||||
object DefaultSharedPreferences {
|
||||
|
||||
@Volatile private var INSTANCE: SharedPreferences? = null
|
||||
|
||||
fun getInstance(context: Context): SharedPreferences =
|
||||
INSTANCE ?: synchronized(this) {
|
||||
INSTANCE ?: PreferenceManager.getDefaultSharedPreferences(context.applicationContext).also { INSTANCE = it }
|
||||
}
|
||||
}
|
|
@ -17,16 +17,17 @@
|
|||
package im.vector.app.core.pushers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import javax.inject.Inject
|
||||
|
||||
class UnifiedPushStore @Inject constructor(
|
||||
val context: Context,
|
||||
val fcmHelper: FcmHelper
|
||||
val fcmHelper: FcmHelper,
|
||||
@DefaultPreferences
|
||||
private val defaultPrefs: SharedPreferences,
|
||||
) {
|
||||
private val defaultPrefs = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
/**
|
||||
* Retrieves the UnifiedPush Endpoint.
|
||||
*
|
||||
|
|
|
@ -23,7 +23,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||
import androidx.core.content.edit
|
||||
import androidx.core.view.isVisible
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.databinding.ViewKeysBackupBannerBinding
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
|
@ -17,103 +17,109 @@
|
|||
package im.vector.app.core.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.media.Ringtone
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import androidx.core.content.edit
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* This file manages the sound ringtone for calls.
|
||||
* It allows you to use the default Riot Ringtone, or the standard ringtone or set a different one from the available choices
|
||||
* This class manages the sound ringtone for calls.
|
||||
* It allows you to use the default Element Ringtone, or the standard ringtone or set a different one from the available choices
|
||||
* in Android.
|
||||
*/
|
||||
class RingtoneUtils @Inject constructor(
|
||||
@DefaultPreferences
|
||||
private val sharedPreferences: SharedPreferences,
|
||||
private val context: Context,
|
||||
) {
|
||||
/**
|
||||
* Returns a Uri object that points to a specific Ringtone.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the Uri for the current system
|
||||
* ringtone for calls.
|
||||
*
|
||||
* @return the [Uri] of the currently set [Ringtone]
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtoneUri(): Uri? {
|
||||
val callRingtone: String? = sharedPreferences
|
||||
.getString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, null)
|
||||
|
||||
/**
|
||||
* Returns a Uri object that points to a specific Ringtone.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the Uri for the current system
|
||||
* ringtone for calls.
|
||||
*
|
||||
* @return the [Uri] of the currently set [Ringtone]
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtoneUri(context: Context): Uri? {
|
||||
val callRingtone: String? = DefaultSharedPreferences.getInstance(context)
|
||||
.getString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, null)
|
||||
callRingtone?.let {
|
||||
return Uri.parse(it)
|
||||
}
|
||||
|
||||
callRingtone?.let {
|
||||
return Uri.parse(it)
|
||||
return try {
|
||||
// Use current system notification sound for incoming calls per default (note that it can return null)
|
||||
RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
|
||||
} catch (e: SecurityException) {
|
||||
// Ignore for now
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return try {
|
||||
// Use current system notification sound for incoming calls per default (note that it can return null)
|
||||
RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
|
||||
} catch (e: SecurityException) {
|
||||
// Ignore for now
|
||||
null
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a Ringtone object that can then be played.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the current system ringtone
|
||||
* for calls.
|
||||
*
|
||||
* @return the currently set [Ringtone]
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtone(): Ringtone? {
|
||||
getCallRingtoneUri()?.let {
|
||||
// Note that it can also return null
|
||||
return RingtoneManager.getRingtone(context, it)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Ringtone object that can then be played.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the current system ringtone
|
||||
* for calls.
|
||||
*
|
||||
* @return the currently set [Ringtone]
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtone(context: Context): Ringtone? {
|
||||
getCallRingtoneUri(context)?.let {
|
||||
// Note that it can also return null
|
||||
return RingtoneManager.getRingtone(context, it)
|
||||
return null
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
/**
|
||||
* Returns a String with the name of the current Ringtone.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the name of the current system
|
||||
* ringtone for calls.
|
||||
*
|
||||
* @return the name of the currently set [Ringtone], or null
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtoneName(): String? {
|
||||
return getCallRingtone()?.getTitle(context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String with the name of the current Ringtone.
|
||||
*
|
||||
* If no Ringtone was explicitly set using Riot, it will return the name of the current system
|
||||
* ringtone for calls.
|
||||
*
|
||||
* @return the name of the currently set [Ringtone], or null
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun getCallRingtoneName(context: Context): String? {
|
||||
return getCallRingtone(context)?.getTitle(context)
|
||||
}
|
||||
/**
|
||||
* Sets the selected ringtone for riot calls.
|
||||
*
|
||||
* @param ringtoneUri
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun setCallRingtoneUri(ringtoneUri: Uri) {
|
||||
sharedPreferences
|
||||
.edit {
|
||||
putString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, ringtoneUri.toString())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected ringtone for riot calls.
|
||||
*
|
||||
* @param context Android context
|
||||
* @param ringtoneUri
|
||||
* @see Ringtone
|
||||
*/
|
||||
fun setCallRingtoneUri(context: Context, ringtoneUri: Uri) {
|
||||
DefaultSharedPreferences.getInstance(context)
|
||||
.edit {
|
||||
putString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, ringtoneUri.toString())
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set using Riot default ringtone.
|
||||
*/
|
||||
fun useRiotDefaultRingtone(): Boolean {
|
||||
return sharedPreferences.getBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set using Riot default ringtone.
|
||||
*/
|
||||
fun useRiotDefaultRingtone(context: Context): Boolean {
|
||||
return DefaultSharedPreferences.getInstance(context).getBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask if default Riot ringtone has to be used.
|
||||
*/
|
||||
fun setUseRiotDefaultRingtone(context: Context, useRiotDefault: Boolean) {
|
||||
DefaultSharedPreferences.getInstance(context)
|
||||
.edit {
|
||||
putBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault)
|
||||
}
|
||||
/**
|
||||
* Ask if default Riot ringtone has to be used.
|
||||
*/
|
||||
fun setUseRiotDefaultRingtone(useRiotDefault: Boolean) {
|
||||
sharedPreferences
|
||||
.edit {
|
||||
putBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,44 +17,46 @@
|
|||
package im.vector.app.features.disclaimer
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.core.utils.openUrlInChromeCustomTab
|
||||
import im.vector.app.features.settings.VectorSettingsUrls
|
||||
import javax.inject.Inject
|
||||
|
||||
// Increase this value to show again the disclaimer dialog after an upgrade of the application
|
||||
private const val CURRENT_DISCLAIMER_VALUE = 2
|
||||
|
||||
const val SHARED_PREF_KEY = "LAST_DISCLAIMER_VERSION_VALUE"
|
||||
|
||||
fun showDisclaimerDialog(activity: Activity) {
|
||||
val sharedPrefs = DefaultSharedPreferences.getInstance(activity)
|
||||
class DisclaimerDialog @Inject constructor(
|
||||
@DefaultPreferences
|
||||
private val sharedPrefs: SharedPreferences,
|
||||
) {
|
||||
fun showDisclaimerDialog(activity: Activity) {
|
||||
if (sharedPrefs.getInt(SHARED_PREF_KEY, 0) < CURRENT_DISCLAIMER_VALUE) {
|
||||
sharedPrefs.edit {
|
||||
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
|
||||
}
|
||||
|
||||
if (sharedPrefs.getInt(SHARED_PREF_KEY, 0) < CURRENT_DISCLAIMER_VALUE) {
|
||||
val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_disclaimer_content, null)
|
||||
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setView(dialogLayout)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.disclaimer_negative_button, null)
|
||||
.setPositiveButton(R.string.disclaimer_positive_button) { _, _ ->
|
||||
openUrlInChromeCustomTab(activity, null, VectorSettingsUrls.DISCLAIMER_URL)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun doNotShowDisclaimerDialog() {
|
||||
sharedPrefs.edit {
|
||||
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
|
||||
}
|
||||
|
||||
val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_disclaimer_content, null)
|
||||
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setView(dialogLayout)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.disclaimer_negative_button, null)
|
||||
.setPositiveButton(R.string.disclaimer_positive_button) { _, _ ->
|
||||
openUrlInChromeCustomTab(activity, null, VectorSettingsUrls.DISCLAIMER_URL)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun doNotShowDisclaimerDialog(context: Context) {
|
||||
val sharedPrefs = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
sharedPrefs.edit {
|
||||
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ import im.vector.app.features.analytics.accountdata.AnalyticsAccountDataViewMode
|
|||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import im.vector.app.features.analytics.plan.ViewRoom
|
||||
import im.vector.app.features.crypto.recover.SetupMode
|
||||
import im.vector.app.features.disclaimer.showDisclaimerDialog
|
||||
import im.vector.app.features.disclaimer.DisclaimerDialog
|
||||
import im.vector.app.features.home.room.list.actions.RoomListSharedAction
|
||||
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||
import im.vector.app.features.home.room.list.home.layout.HomeLayoutSettingBottomDialogFragment
|
||||
|
@ -141,6 +141,7 @@ class HomeActivity :
|
|||
@Inject lateinit var unifiedPushHelper: UnifiedPushHelper
|
||||
@Inject lateinit var fcmHelper: FcmHelper
|
||||
@Inject lateinit var nightlyProxy: NightlyProxy
|
||||
@Inject lateinit var disclaimerDialog: DisclaimerDialog
|
||||
|
||||
private var isNewAppLayoutEnabled: Boolean = false // delete once old app layout is removed
|
||||
|
||||
|
@ -570,7 +571,7 @@ class HomeActivity :
|
|||
.setNegativeButton(R.string.no) { _, _ -> bugReporter.deleteCrashFile() }
|
||||
.show()
|
||||
} else {
|
||||
showDisclaimerDialog(this)
|
||||
disclaimerDialog.showDisclaimerDialog(this)
|
||||
}
|
||||
|
||||
// Force remote backup state update to update the banner if needed
|
||||
|
|
|
@ -17,28 +17,36 @@
|
|||
package im.vector.app.features.homeserver
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Object to store and retrieve home and identity server urls.
|
||||
*/
|
||||
object ServerUrlsRepository {
|
||||
class ServerUrlsRepository @Inject constructor(
|
||||
@DefaultPreferences
|
||||
private val sharedPreferences: SharedPreferences,
|
||||
private val stringProvider: StringProvider,
|
||||
) {
|
||||
companion object {
|
||||
// Keys used to store default servers urls from the referrer
|
||||
private const val DEFAULT_REFERRER_HOME_SERVER_URL_PREF = "default_referrer_home_server_url"
|
||||
private const val DEFAULT_REFERRER_IDENTITY_SERVER_URL_PREF = "default_referrer_identity_server_url"
|
||||
|
||||
// Keys used to store default servers urls from the referrer
|
||||
private const val DEFAULT_REFERRER_HOME_SERVER_URL_PREF = "default_referrer_home_server_url"
|
||||
private const val DEFAULT_REFERRER_IDENTITY_SERVER_URL_PREF = "default_referrer_identity_server_url"
|
||||
|
||||
// Keys used to store current homeserver url and identity url
|
||||
const val HOME_SERVER_URL_PREF = "home_server_url"
|
||||
const val IDENTITY_SERVER_URL_PREF = "identity_server_url"
|
||||
// Keys used to store current homeserver url and identity url
|
||||
const val HOME_SERVER_URL_PREF = "home_server_url"
|
||||
const val IDENTITY_SERVER_URL_PREF = "identity_server_url"
|
||||
}
|
||||
|
||||
/**
|
||||
* Save home and identity sever urls received by the Referrer receiver.
|
||||
*/
|
||||
fun setDefaultUrlsFromReferrer(context: Context, homeServerUrl: String, identityServerUrl: String) {
|
||||
DefaultSharedPreferences.getInstance(context)
|
||||
fun setDefaultUrlsFromReferrer(homeServerUrl: String, identityServerUrl: String) {
|
||||
sharedPreferences
|
||||
.edit {
|
||||
if (homeServerUrl.isNotEmpty()) {
|
||||
putString(DEFAULT_REFERRER_HOME_SERVER_URL_PREF, homeServerUrl)
|
||||
|
@ -53,8 +61,8 @@ object ServerUrlsRepository {
|
|||
/**
|
||||
* Save home and identity sever urls entered by the user. May be custom or default value.
|
||||
*/
|
||||
fun saveServerUrls(context: Context, homeServerUrl: String, identityServerUrl: String) {
|
||||
DefaultSharedPreferences.getInstance(context)
|
||||
fun saveServerUrls(homeServerUrl: String, identityServerUrl: String) {
|
||||
sharedPreferences
|
||||
.edit {
|
||||
putString(HOME_SERVER_URL_PREF, homeServerUrl)
|
||||
putString(IDENTITY_SERVER_URL_PREF, identityServerUrl)
|
||||
|
@ -64,14 +72,12 @@ object ServerUrlsRepository {
|
|||
/**
|
||||
* Return last used homeserver url, or the default one from referrer or the default one from resources.
|
||||
*/
|
||||
fun getLastHomeServerUrl(context: Context): String {
|
||||
val prefs = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
return prefs.getString(
|
||||
fun getLastHomeServerUrl(): String {
|
||||
return sharedPreferences.getString(
|
||||
HOME_SERVER_URL_PREF,
|
||||
prefs.getString(
|
||||
sharedPreferences.getString(
|
||||
DEFAULT_REFERRER_HOME_SERVER_URL_PREF,
|
||||
getDefaultHomeServerUrl(context)
|
||||
getDefaultHomeServerUrl()
|
||||
)!!
|
||||
)!!
|
||||
}
|
||||
|
@ -79,10 +85,10 @@ object ServerUrlsRepository {
|
|||
/**
|
||||
* Return true if url is the default homeserver url form resources.
|
||||
*/
|
||||
fun isDefaultHomeServerUrl(context: Context, url: String) = url == getDefaultHomeServerUrl(context)
|
||||
fun isDefaultHomeServerUrl(context: Context, url: String) = url == getDefaultHomeServerUrl()
|
||||
|
||||
/**
|
||||
* Return default homeserver url from resources.
|
||||
*/
|
||||
fun getDefaultHomeServerUrl(context: Context): String = context.getString(R.string.matrix_org_server_url)
|
||||
fun getDefaultHomeServerUrl() = stringProvider.getString(R.string.matrix_org_server_url)
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
package im.vector.app.features.rageshake
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import androidx.core.content.edit
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.core.resources.VersionCodeProvider
|
||||
import im.vector.app.features.version.VersionProvider
|
||||
import org.matrix.android.sdk.api.Matrix
|
||||
|
@ -31,10 +31,11 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class VectorUncaughtExceptionHandler @Inject constructor(
|
||||
context: Context,
|
||||
@DefaultPreferences
|
||||
private val preferences: SharedPreferences,
|
||||
private val bugReporter: BugReporter,
|
||||
private val versionProvider: VersionProvider,
|
||||
private val versionCodeProvider: VersionCodeProvider
|
||||
private val versionCodeProvider: VersionCodeProvider,
|
||||
) : Thread.UncaughtExceptionHandler {
|
||||
|
||||
// key to save the crash status
|
||||
|
@ -44,8 +45,6 @@ class VectorUncaughtExceptionHandler @Inject constructor(
|
|||
|
||||
private var previousHandler: Thread.UncaughtExceptionHandler? = null
|
||||
|
||||
private val preferences = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
/**
|
||||
* Activate this handler.
|
||||
*/
|
||||
|
|
|
@ -17,10 +17,11 @@
|
|||
package im.vector.app.features.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import androidx.core.content.edit
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.core.resources.BuildMeta
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -37,6 +38,8 @@ import javax.inject.Singleton
|
|||
class VectorLocale @Inject constructor(
|
||||
private val context: Context,
|
||||
private val buildMeta: BuildMeta,
|
||||
@DefaultPreferences
|
||||
private val preferences: SharedPreferences,
|
||||
) {
|
||||
companion object {
|
||||
const val APPLICATION_LOCALE_COUNTRY_KEY = "APPLICATION_LOCALE_COUNTRY_KEY"
|
||||
|
@ -63,8 +66,6 @@ class VectorLocale @Inject constructor(
|
|||
* Init this singleton.
|
||||
*/
|
||||
fun init() {
|
||||
val preferences = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
if (preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) {
|
||||
applicationLocale = Locale(
|
||||
preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, "")!!,
|
||||
|
@ -90,7 +91,7 @@ class VectorLocale @Inject constructor(
|
|||
fun saveApplicationLocale(locale: Locale) {
|
||||
applicationLocale = locale
|
||||
|
||||
DefaultSharedPreferences.getInstance(context).edit {
|
||||
preferences.edit {
|
||||
val language = locale.language
|
||||
if (language.isEmpty()) {
|
||||
remove(APPLICATION_LOCALE_LANGUAGE_KEY)
|
||||
|
|
|
@ -24,8 +24,9 @@ import androidx.annotation.BoolRes
|
|||
import androidx.core.content.edit
|
||||
import com.squareup.seismic.ShakeDetector
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import im.vector.app.core.di.DefaultPreferences
|
||||
import im.vector.app.core.resources.BuildMeta
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.time.Clock
|
||||
import im.vector.app.features.VectorFeatures
|
||||
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
||||
|
@ -41,6 +42,9 @@ class VectorPreferences @Inject constructor(
|
|||
private val clock: Clock,
|
||||
private val buildMeta: BuildMeta,
|
||||
private val vectorFeatures: VectorFeatures,
|
||||
@DefaultPreferences
|
||||
private val defaultPrefs: SharedPreferences,
|
||||
private val stringProvider: StringProvider,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
@ -289,8 +293,6 @@ class VectorPreferences @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private val defaultPrefs = DefaultSharedPreferences.getInstance(context)
|
||||
|
||||
/**
|
||||
* Allow subscribing and unsubscribing to configuration changes. This is
|
||||
* particularly useful when you need to be notified of a configuration change
|
||||
|
@ -716,10 +718,10 @@ class VectorPreferences @Inject constructor(
|
|||
*/
|
||||
fun getSelectedMediasSavingPeriodString(): String {
|
||||
return when (getSelectedMediasSavingPeriod()) {
|
||||
MEDIA_SAVING_3_DAYS -> context.getString(R.string.media_saving_period_3_days)
|
||||
MEDIA_SAVING_1_WEEK -> context.getString(R.string.media_saving_period_1_week)
|
||||
MEDIA_SAVING_1_MONTH -> context.getString(R.string.media_saving_period_1_month)
|
||||
MEDIA_SAVING_FOREVER -> context.getString(R.string.media_saving_period_forever)
|
||||
MEDIA_SAVING_3_DAYS -> stringProvider.getString(R.string.media_saving_period_3_days)
|
||||
MEDIA_SAVING_1_WEEK -> stringProvider.getString(R.string.media_saving_period_1_week)
|
||||
MEDIA_SAVING_1_MONTH -> stringProvider.getString(R.string.media_saving_period_1_month)
|
||||
MEDIA_SAVING_FOREVER -> stringProvider.getString(R.string.media_saving_period_forever)
|
||||
else -> "?"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,17 +23,19 @@ import android.net.Uri
|
|||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.SwitchPreference
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.registerStartForActivityResult
|
||||
import im.vector.app.core.preference.VectorPreference
|
||||
import im.vector.app.core.utils.getCallRingtoneName
|
||||
import im.vector.app.core.utils.getCallRingtoneUri
|
||||
import im.vector.app.core.utils.setCallRingtoneUri
|
||||
import im.vector.app.core.utils.setUseRiotDefaultRingtone
|
||||
import im.vector.app.core.utils.RingtoneUtils
|
||||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
||||
|
||||
@Inject lateinit var ringtoneUtils: RingtoneUtils
|
||||
|
||||
override var titleRes = R.string.preference_voice_and_video
|
||||
override val preferenceXmlRes = R.xml.vector_settings_voice_video
|
||||
|
||||
|
@ -52,12 +54,12 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||
override fun bindPref() {
|
||||
// Incoming call sounds
|
||||
mUseRiotCallRingtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
activity?.let { setUseRiotDefaultRingtone(it, mUseRiotCallRingtonePreference.isChecked) }
|
||||
ringtoneUtils.setUseRiotDefaultRingtone(mUseRiotCallRingtonePreference.isChecked)
|
||||
false
|
||||
}
|
||||
|
||||
mCallRingtonePreference.let {
|
||||
activity?.let { activity -> it.summary = getCallRingtoneName(activity) }
|
||||
it.summary = ringtoneUtils.getCallRingtoneName()
|
||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
displayRingtonePicker()
|
||||
false
|
||||
|
@ -68,10 +70,9 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||
private val ringtoneStartForActivityResult = registerStartForActivityResult { activityResult ->
|
||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||
val callRingtoneUri: Uri? = activityResult.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
|
||||
val thisActivity = activity
|
||||
if (callRingtoneUri != null && thisActivity != null) {
|
||||
setCallRingtoneUri(thisActivity, callRingtoneUri)
|
||||
mCallRingtonePreference.summary = getCallRingtoneName(thisActivity)
|
||||
if (callRingtoneUri != null) {
|
||||
ringtoneUtils.setCallRingtoneUri(callRingtoneUri)
|
||||
mCallRingtonePreference.summary = ringtoneUtils.getCallRingtoneName()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE)
|
||||
activity?.let { putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getCallRingtoneUri(it)) }
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUtils.getCallRingtoneUri())
|
||||
}
|
||||
ringtoneStartForActivityResult.launch(intent)
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ import androidx.annotation.ColorInt
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.DefaultSharedPreferences
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
|
@ -84,7 +84,7 @@ object ThemeUtils {
|
|||
fun getApplicationTheme(context: Context): String {
|
||||
val currentTheme = this.currentTheme.get()
|
||||
return if (currentTheme == null) {
|
||||
val prefs = DefaultSharedPreferences.getInstance(context)
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||
var themeFromPref = prefs.getString(APPLICATION_THEME_KEY, DEFAULT_THEME) ?: DEFAULT_THEME
|
||||
if (themeFromPref == "status") {
|
||||
// Migrate to the default theme
|
||||
|
|
Loading…
Reference in a new issue