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
@ -53,7 +53,7 @@ import im.vector.app.core.resources.BuildMeta
|
|||||||
import im.vector.app.features.analytics.VectorAnalytics
|
import im.vector.app.features.analytics.VectorAnalytics
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.configuration.VectorConfiguration
|
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.invite.InvitesAcceptor
|
||||||
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
||||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||||
@ -110,6 +110,7 @@ class VectorApplication :
|
|||||||
@Inject lateinit var buildMeta: BuildMeta
|
@Inject lateinit var buildMeta: BuildMeta
|
||||||
@Inject lateinit var leakDetector: LeakDetector
|
@Inject lateinit var leakDetector: LeakDetector
|
||||||
@Inject lateinit var vectorLocale: VectorLocale
|
@Inject lateinit var vectorLocale: VectorLocale
|
||||||
|
@Inject lateinit var disclaimerDialog: DisclaimerDialog
|
||||||
|
|
||||||
// font thread handler
|
// font thread handler
|
||||||
private var fontThreadHandler: Handler? = null
|
private var fontThreadHandler: Handler? = null
|
||||||
@ -172,7 +173,7 @@ class VectorApplication :
|
|||||||
val sessionImported = legacySessionImporter.process()
|
val sessionImported = legacySessionImporter.process()
|
||||||
if (!sessionImported) {
|
if (!sessionImported) {
|
||||||
// Do not display the name change popup
|
// Do not display the name change popup
|
||||||
doNotShowDisclaimerDialog(this)
|
disclaimerDialog.doNotShowDisclaimerDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
|
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
|
package im.vector.app.core.pushers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
import im.vector.app.core.di.DefaultPreferences
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class UnifiedPushStore @Inject constructor(
|
class UnifiedPushStore @Inject constructor(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
val fcmHelper: FcmHelper
|
val fcmHelper: FcmHelper,
|
||||||
|
@DefaultPreferences
|
||||||
|
private val defaultPrefs: SharedPreferences,
|
||||||
) {
|
) {
|
||||||
private val defaultPrefs = DefaultSharedPreferences.getInstance(context)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the UnifiedPush Endpoint.
|
* Retrieves the UnifiedPush Endpoint.
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
|
||||||
import im.vector.app.databinding.ViewKeysBackupBannerBinding
|
import im.vector.app.databinding.ViewKeysBackupBannerBinding
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ -17,103 +17,109 @@
|
|||||||
package im.vector.app.core.utils
|
package im.vector.app.core.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.media.Ringtone
|
import android.media.Ringtone
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.core.content.edit
|
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 im.vector.app.features.settings.VectorPreferences
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file manages the sound ringtone for calls.
|
* This class 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
|
* It allows you to use the default Element Ringtone, or the standard ringtone or set a different one from the available choices
|
||||||
* in Android.
|
* 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)
|
||||||
|
|
||||||
/**
|
callRingtone?.let {
|
||||||
* Returns a Uri object that points to a specific Ringtone.
|
return Uri.parse(it)
|
||||||
*
|
}
|
||||||
* 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 try {
|
||||||
return Uri.parse(it)
|
// 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)
|
* Returns a Ringtone object that can then be played.
|
||||||
RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
|
*
|
||||||
} catch (e: SecurityException) {
|
* If no Ringtone was explicitly set using Riot, it will return the current system ringtone
|
||||||
// Ignore for now
|
* for calls.
|
||||||
null
|
*
|
||||||
}
|
* @return the currently set [Ringtone]
|
||||||
}
|
* @see Ringtone
|
||||||
|
*/
|
||||||
|
fun getCallRingtone(): Ringtone? {
|
||||||
|
getCallRingtoneUri()?.let {
|
||||||
|
// Note that it can also return null
|
||||||
|
return RingtoneManager.getRingtone(context, it)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return 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(context: Context): Ringtone? {
|
|
||||||
getCallRingtoneUri(context)?.let {
|
|
||||||
// Note that it can also return null
|
|
||||||
return RingtoneManager.getRingtone(context, it)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* Sets the selected ringtone for riot calls.
|
||||||
*
|
*
|
||||||
* If no Ringtone was explicitly set using Riot, it will return the name of the current system
|
* @param ringtoneUri
|
||||||
* ringtone for calls.
|
* @see Ringtone
|
||||||
*
|
*/
|
||||||
* @return the name of the currently set [Ringtone], or null
|
fun setCallRingtoneUri(ringtoneUri: Uri) {
|
||||||
* @see Ringtone
|
sharedPreferences
|
||||||
*/
|
.edit {
|
||||||
fun getCallRingtoneName(context: Context): String? {
|
putString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, ringtoneUri.toString())
|
||||||
return getCallRingtone(context)?.getTitle(context)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the selected ringtone for riot calls.
|
* Set using Riot default ringtone.
|
||||||
*
|
*/
|
||||||
* @param context Android context
|
fun useRiotDefaultRingtone(): Boolean {
|
||||||
* @param ringtoneUri
|
return sharedPreferences.getBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true)
|
||||||
* @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.
|
* Ask if default Riot ringtone has to be used.
|
||||||
*/
|
*/
|
||||||
fun useRiotDefaultRingtone(context: Context): Boolean {
|
fun setUseRiotDefaultRingtone(useRiotDefault: Boolean) {
|
||||||
return DefaultSharedPreferences.getInstance(context).getBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true)
|
sharedPreferences
|
||||||
}
|
.edit {
|
||||||
|
putBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault)
|
||||||
/**
|
}
|
||||||
* 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,44 +17,46 @@
|
|||||||
package im.vector.app.features.disclaimer
|
package im.vector.app.features.disclaimer
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.SharedPreferences
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import im.vector.app.R
|
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.core.utils.openUrlInChromeCustomTab
|
||||||
import im.vector.app.features.settings.VectorSettingsUrls
|
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
|
// Increase this value to show again the disclaimer dialog after an upgrade of the application
|
||||||
private const val CURRENT_DISCLAIMER_VALUE = 2
|
private const val CURRENT_DISCLAIMER_VALUE = 2
|
||||||
|
|
||||||
const val SHARED_PREF_KEY = "LAST_DISCLAIMER_VERSION_VALUE"
|
const val SHARED_PREF_KEY = "LAST_DISCLAIMER_VERSION_VALUE"
|
||||||
|
|
||||||
fun showDisclaimerDialog(activity: Activity) {
|
class DisclaimerDialog @Inject constructor(
|
||||||
val sharedPrefs = DefaultSharedPreferences.getInstance(activity)
|
@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 {
|
sharedPrefs.edit {
|
||||||
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
|
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.MobileScreen
|
||||||
import im.vector.app.features.analytics.plan.ViewRoom
|
import im.vector.app.features.analytics.plan.ViewRoom
|
||||||
import im.vector.app.features.crypto.recover.SetupMode
|
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.RoomListSharedAction
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||||
import im.vector.app.features.home.room.list.home.layout.HomeLayoutSettingBottomDialogFragment
|
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 unifiedPushHelper: UnifiedPushHelper
|
||||||
@Inject lateinit var fcmHelper: FcmHelper
|
@Inject lateinit var fcmHelper: FcmHelper
|
||||||
@Inject lateinit var nightlyProxy: NightlyProxy
|
@Inject lateinit var nightlyProxy: NightlyProxy
|
||||||
|
@Inject lateinit var disclaimerDialog: DisclaimerDialog
|
||||||
|
|
||||||
private var isNewAppLayoutEnabled: Boolean = false // delete once old app layout is removed
|
private var isNewAppLayoutEnabled: Boolean = false // delete once old app layout is removed
|
||||||
|
|
||||||
@ -570,7 +571,7 @@ class HomeActivity :
|
|||||||
.setNegativeButton(R.string.no) { _, _ -> bugReporter.deleteCrashFile() }
|
.setNegativeButton(R.string.no) { _, _ -> bugReporter.deleteCrashFile() }
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
showDisclaimerDialog(this)
|
disclaimerDialog.showDisclaimerDialog(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force remote backup state update to update the banner if needed
|
// Force remote backup state update to update the banner if needed
|
||||||
|
@ -17,28 +17,36 @@
|
|||||||
package im.vector.app.features.homeserver
|
package im.vector.app.features.homeserver
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import im.vector.app.R
|
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 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
|
// Keys used to store current homeserver url and identity url
|
||||||
private const val DEFAULT_REFERRER_HOME_SERVER_URL_PREF = "default_referrer_home_server_url"
|
const val HOME_SERVER_URL_PREF = "home_server_url"
|
||||||
private const val DEFAULT_REFERRER_IDENTITY_SERVER_URL_PREF = "default_referrer_identity_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.
|
* Save home and identity sever urls received by the Referrer receiver.
|
||||||
*/
|
*/
|
||||||
fun setDefaultUrlsFromReferrer(context: Context, homeServerUrl: String, identityServerUrl: String) {
|
fun setDefaultUrlsFromReferrer(homeServerUrl: String, identityServerUrl: String) {
|
||||||
DefaultSharedPreferences.getInstance(context)
|
sharedPreferences
|
||||||
.edit {
|
.edit {
|
||||||
if (homeServerUrl.isNotEmpty()) {
|
if (homeServerUrl.isNotEmpty()) {
|
||||||
putString(DEFAULT_REFERRER_HOME_SERVER_URL_PREF, homeServerUrl)
|
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.
|
* Save home and identity sever urls entered by the user. May be custom or default value.
|
||||||
*/
|
*/
|
||||||
fun saveServerUrls(context: Context, homeServerUrl: String, identityServerUrl: String) {
|
fun saveServerUrls(homeServerUrl: String, identityServerUrl: String) {
|
||||||
DefaultSharedPreferences.getInstance(context)
|
sharedPreferences
|
||||||
.edit {
|
.edit {
|
||||||
putString(HOME_SERVER_URL_PREF, homeServerUrl)
|
putString(HOME_SERVER_URL_PREF, homeServerUrl)
|
||||||
putString(IDENTITY_SERVER_URL_PREF, identityServerUrl)
|
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.
|
* Return last used homeserver url, or the default one from referrer or the default one from resources.
|
||||||
*/
|
*/
|
||||||
fun getLastHomeServerUrl(context: Context): String {
|
fun getLastHomeServerUrl(): String {
|
||||||
val prefs = DefaultSharedPreferences.getInstance(context)
|
return sharedPreferences.getString(
|
||||||
|
|
||||||
return prefs.getString(
|
|
||||||
HOME_SERVER_URL_PREF,
|
HOME_SERVER_URL_PREF,
|
||||||
prefs.getString(
|
sharedPreferences.getString(
|
||||||
DEFAULT_REFERRER_HOME_SERVER_URL_PREF,
|
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.
|
* 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.
|
* 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
|
package im.vector.app.features.rageshake
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.edit
|
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.core.resources.VersionCodeProvider
|
||||||
import im.vector.app.features.version.VersionProvider
|
import im.vector.app.features.version.VersionProvider
|
||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
@ -31,10 +31,11 @@ import javax.inject.Singleton
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class VectorUncaughtExceptionHandler @Inject constructor(
|
class VectorUncaughtExceptionHandler @Inject constructor(
|
||||||
context: Context,
|
@DefaultPreferences
|
||||||
|
private val preferences: SharedPreferences,
|
||||||
private val bugReporter: BugReporter,
|
private val bugReporter: BugReporter,
|
||||||
private val versionProvider: VersionProvider,
|
private val versionProvider: VersionProvider,
|
||||||
private val versionCodeProvider: VersionCodeProvider
|
private val versionCodeProvider: VersionCodeProvider,
|
||||||
) : Thread.UncaughtExceptionHandler {
|
) : Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
// key to save the crash status
|
// key to save the crash status
|
||||||
@ -44,8 +45,6 @@ class VectorUncaughtExceptionHandler @Inject constructor(
|
|||||||
|
|
||||||
private var previousHandler: Thread.UncaughtExceptionHandler? = null
|
private var previousHandler: Thread.UncaughtExceptionHandler? = null
|
||||||
|
|
||||||
private val preferences = DefaultSharedPreferences.getInstance(context)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activate this handler.
|
* Activate this handler.
|
||||||
*/
|
*/
|
||||||
|
@ -17,10 +17,11 @@
|
|||||||
package im.vector.app.features.settings
|
package im.vector.app.features.settings
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import im.vector.app.R
|
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.BuildMeta
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -37,6 +38,8 @@ import javax.inject.Singleton
|
|||||||
class VectorLocale @Inject constructor(
|
class VectorLocale @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val buildMeta: BuildMeta,
|
private val buildMeta: BuildMeta,
|
||||||
|
@DefaultPreferences
|
||||||
|
private val preferences: SharedPreferences,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val APPLICATION_LOCALE_COUNTRY_KEY = "APPLICATION_LOCALE_COUNTRY_KEY"
|
const val APPLICATION_LOCALE_COUNTRY_KEY = "APPLICATION_LOCALE_COUNTRY_KEY"
|
||||||
@ -63,8 +66,6 @@ class VectorLocale @Inject constructor(
|
|||||||
* Init this singleton.
|
* Init this singleton.
|
||||||
*/
|
*/
|
||||||
fun init() {
|
fun init() {
|
||||||
val preferences = DefaultSharedPreferences.getInstance(context)
|
|
||||||
|
|
||||||
if (preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) {
|
if (preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) {
|
||||||
applicationLocale = Locale(
|
applicationLocale = Locale(
|
||||||
preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, "")!!,
|
preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, "")!!,
|
||||||
@ -90,7 +91,7 @@ class VectorLocale @Inject constructor(
|
|||||||
fun saveApplicationLocale(locale: Locale) {
|
fun saveApplicationLocale(locale: Locale) {
|
||||||
applicationLocale = locale
|
applicationLocale = locale
|
||||||
|
|
||||||
DefaultSharedPreferences.getInstance(context).edit {
|
preferences.edit {
|
||||||
val language = locale.language
|
val language = locale.language
|
||||||
if (language.isEmpty()) {
|
if (language.isEmpty()) {
|
||||||
remove(APPLICATION_LOCALE_LANGUAGE_KEY)
|
remove(APPLICATION_LOCALE_LANGUAGE_KEY)
|
||||||
|
@ -24,8 +24,9 @@ import androidx.annotation.BoolRes
|
|||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.squareup.seismic.ShakeDetector
|
import com.squareup.seismic.ShakeDetector
|
||||||
import im.vector.app.R
|
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.BuildMeta
|
||||||
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.time.Clock
|
import im.vector.app.core.time.Clock
|
||||||
import im.vector.app.features.VectorFeatures
|
import im.vector.app.features.VectorFeatures
|
||||||
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
||||||
@ -41,6 +42,9 @@ class VectorPreferences @Inject constructor(
|
|||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
private val buildMeta: BuildMeta,
|
private val buildMeta: BuildMeta,
|
||||||
private val vectorFeatures: VectorFeatures,
|
private val vectorFeatures: VectorFeatures,
|
||||||
|
@DefaultPreferences
|
||||||
|
private val defaultPrefs: SharedPreferences,
|
||||||
|
private val stringProvider: StringProvider,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
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
|
* Allow subscribing and unsubscribing to configuration changes. This is
|
||||||
* particularly useful when you need to be notified of a configuration change
|
* particularly useful when you need to be notified of a configuration change
|
||||||
@ -716,10 +718,10 @@ class VectorPreferences @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
fun getSelectedMediasSavingPeriodString(): String {
|
fun getSelectedMediasSavingPeriodString(): String {
|
||||||
return when (getSelectedMediasSavingPeriod()) {
|
return when (getSelectedMediasSavingPeriod()) {
|
||||||
MEDIA_SAVING_3_DAYS -> context.getString(R.string.media_saving_period_3_days)
|
MEDIA_SAVING_3_DAYS -> stringProvider.getString(R.string.media_saving_period_3_days)
|
||||||
MEDIA_SAVING_1_WEEK -> context.getString(R.string.media_saving_period_1_week)
|
MEDIA_SAVING_1_WEEK -> stringProvider.getString(R.string.media_saving_period_1_week)
|
||||||
MEDIA_SAVING_1_MONTH -> context.getString(R.string.media_saving_period_1_month)
|
MEDIA_SAVING_1_MONTH -> stringProvider.getString(R.string.media_saving_period_1_month)
|
||||||
MEDIA_SAVING_FOREVER -> context.getString(R.string.media_saving_period_forever)
|
MEDIA_SAVING_FOREVER -> stringProvider.getString(R.string.media_saving_period_forever)
|
||||||
else -> "?"
|
else -> "?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,19 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.SwitchPreference
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.registerStartForActivityResult
|
import im.vector.app.core.extensions.registerStartForActivityResult
|
||||||
import im.vector.app.core.preference.VectorPreference
|
import im.vector.app.core.preference.VectorPreference
|
||||||
import im.vector.app.core.utils.getCallRingtoneName
|
import im.vector.app.core.utils.RingtoneUtils
|
||||||
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.features.analytics.plan.MobileScreen
|
import im.vector.app.features.analytics.plan.MobileScreen
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
||||||
|
|
||||||
|
@Inject lateinit var ringtoneUtils: RingtoneUtils
|
||||||
|
|
||||||
override var titleRes = R.string.preference_voice_and_video
|
override var titleRes = R.string.preference_voice_and_video
|
||||||
override val preferenceXmlRes = R.xml.vector_settings_voice_video
|
override val preferenceXmlRes = R.xml.vector_settings_voice_video
|
||||||
|
|
||||||
@ -52,12 +54,12 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||||||
override fun bindPref() {
|
override fun bindPref() {
|
||||||
// Incoming call sounds
|
// Incoming call sounds
|
||||||
mUseRiotCallRingtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
mUseRiotCallRingtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
activity?.let { setUseRiotDefaultRingtone(it, mUseRiotCallRingtonePreference.isChecked) }
|
ringtoneUtils.setUseRiotDefaultRingtone(mUseRiotCallRingtonePreference.isChecked)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
mCallRingtonePreference.let {
|
mCallRingtonePreference.let {
|
||||||
activity?.let { activity -> it.summary = getCallRingtoneName(activity) }
|
it.summary = ringtoneUtils.getCallRingtoneName()
|
||||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
displayRingtonePicker()
|
displayRingtonePicker()
|
||||||
false
|
false
|
||||||
@ -68,10 +70,9 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||||||
private val ringtoneStartForActivityResult = registerStartForActivityResult { activityResult ->
|
private val ringtoneStartForActivityResult = registerStartForActivityResult { activityResult ->
|
||||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||||
val callRingtoneUri: Uri? = activityResult.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
|
val callRingtoneUri: Uri? = activityResult.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
|
||||||
val thisActivity = activity
|
if (callRingtoneUri != null) {
|
||||||
if (callRingtoneUri != null && thisActivity != null) {
|
ringtoneUtils.setCallRingtoneUri(callRingtoneUri)
|
||||||
setCallRingtoneUri(thisActivity, callRingtoneUri)
|
mCallRingtonePreference.summary = ringtoneUtils.getCallRingtoneName()
|
||||||
mCallRingtonePreference.summary = getCallRingtoneName(thisActivity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
|
|||||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
||||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
||||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE)
|
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)
|
ringtoneStartForActivityResult.launch(intent)
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ import androidx.annotation.ColorInt
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.graphics.drawable.DrawableCompat
|
import androidx.core.graphics.drawable.DrawableCompat
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ object ThemeUtils {
|
|||||||
fun getApplicationTheme(context: Context): String {
|
fun getApplicationTheme(context: Context): String {
|
||||||
val currentTheme = this.currentTheme.get()
|
val currentTheme = this.currentTheme.get()
|
||||||
return if (currentTheme == null) {
|
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
|
var themeFromPref = prefs.getString(APPLICATION_THEME_KEY, DEFAULT_THEME) ?: DEFAULT_THEME
|
||||||
if (themeFromPref == "status") {
|
if (themeFromPref == "status") {
|
||||||
// Migrate to the default theme
|
// Migrate to the default theme
|
||||||
|
Loading…
Reference in New Issue
Block a user