diff --git a/CHANGES.md b/CHANGES.md index 7259f70a16..3a9e37a511 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ Changes in RiotX 0.3.0 (2019-XX-XX) Features: - Create Direct Room flow + - Handle `/markdown` command Improvements: - UI for pending edits (#193) diff --git a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt index 076f5ac43b..fa4b8aa375 100644 --- a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt +++ b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt @@ -15,7 +15,6 @@ */ package im.vector.riotx.fdroid.features.settings.troubleshoot -import androidx.appcompat.app.AppCompatActivity import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.features.settings.VectorPreferences @@ -25,12 +24,12 @@ import javax.inject.Inject /** * Test that the application is started on boot */ -class TestAutoStartBoot @Inject constructor(private val context: AppCompatActivity, +class TestAutoStartBoot @Inject constructor(private val vectorPreferences: VectorPreferences, private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_service_boot_title) { override fun perform() { - if (VectorPreferences.autoStartOnBoot(context)) { + if (vectorPreferences.autoStartOnBoot()) { description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_success) status = TestStatus.SUCCESS quickFix = null @@ -38,7 +37,7 @@ class TestAutoStartBoot @Inject constructor(private val context: AppCompatActivi description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_failed) quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_service_boot_quickfix) { override fun doFix() { - VectorPreferences.setAutoStartOnBoot(context, true) + vectorPreferences.setAutoStartOnBoot(true) manager?.retry() } } diff --git a/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt b/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt index 7ca9957f77..5775fc8479 100755 --- a/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt +++ b/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt @@ -63,9 +63,9 @@ object FcmHelper { AlarmSyncBroadcastReceiver.cancelAlarm(context) } - fun onEnterBackground(context: Context, activeSessionHolder: ActiveSessionHolder) { + fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) { //We need to use alarm in this mode - if (VectorPreferences.areNotificationEnabledForDevice(context) && activeSessionHolder.hasActiveSession()) { + if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) { val currentSession = activeSessionHolder.getActiveSession() AlarmSyncBroadcastReceiver.scheduleAlarm(context, currentSession.myUserId, 4_000L) Timber.i("Alarm scheduled to restart service") diff --git a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt index a8e1c2cd1b..5ad064683c 100755 --- a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -52,6 +52,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { private lateinit var notifiableEventResolver: NotifiableEventResolver private lateinit var pusherManager: PushersManager private lateinit var activeSessionHolder: ActiveSessionHolder + private lateinit var vectorPreferences: VectorPreferences // UI handler private val mUIHandler by lazy { @@ -64,6 +65,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { notifiableEventResolver = vectorComponent().notifiableEventResolver() pusherManager = vectorComponent().pusherManager() activeSessionHolder = vectorComponent().activeSessionHolder() + vectorPreferences = vectorComponent().vectorPreferences() } /** @@ -72,7 +74,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { * @param message the message */ override fun onMessageReceived(message: RemoteMessage?) { - if (!VectorPreferences.areNotificationEnabledForDevice(applicationContext)) { + if (!vectorPreferences.areNotificationEnabledForDevice()) { Timber.i("Notification are disabled for this device") return } @@ -107,7 +109,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { if (refreshedToken == null) { Timber.w("onNewToken:received null token") } else { - if (VectorPreferences.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) { + if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) { pusherManager.registerPusherWithFcmKey(refreshedToken) } } diff --git a/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt b/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt index c19aa561d0..148a83368b 100755 --- a/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt +++ b/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt @@ -27,6 +27,7 @@ import com.google.firebase.iid.FirebaseInstanceId import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.pushers.PushersManager +import im.vector.riotx.features.settings.VectorPreferences import timber.log.Timber /** @@ -105,7 +106,7 @@ object FcmHelper { // No op } - fun onEnterBackground(context: Context, activeSessionHolder: ActiveSessionHolder) { + fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) { // TODO FCM fallback } } diff --git a/vector/src/main/java/im/vector/riotx/VectorApplication.kt b/vector/src/main/java/im/vector/riotx/VectorApplication.kt index f9416fc0a0..308daec278 100644 --- a/vector/src/main/java/im/vector/riotx/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotx/VectorApplication.kt @@ -42,6 +42,7 @@ import im.vector.riotx.core.di.DaggerVectorComponent import im.vector.riotx.core.di.HasVectorInjector import im.vector.riotx.core.di.VectorComponent import im.vector.riotx.core.extensions.configureAndStart +import im.vector.riotx.core.utils.initKnownEmojiHashSet import im.vector.riotx.features.configuration.VectorConfiguration import im.vector.riotx.features.lifecycle.VectorActivityLifecycleCallbacks import im.vector.riotx.features.notifications.NotificationDrawerManager @@ -49,12 +50,12 @@ import im.vector.riotx.features.notifications.NotificationUtils import im.vector.riotx.features.notifications.PushRuleTriggerListener import im.vector.riotx.features.rageshake.VectorFileLogger import im.vector.riotx.features.rageshake.VectorUncaughtExceptionHandler +import im.vector.riotx.features.settings.VectorPreferences import im.vector.riotx.features.version.getVersion import im.vector.riotx.push.fcm.FcmHelper import timber.log.Timber import java.text.SimpleDateFormat import java.util.* -import im.vector.riotx.core.utils.initKnownEmojiHashSet import javax.inject.Inject class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration.Provider, androidx.work.Configuration.Provider { @@ -69,6 +70,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration. @Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var notificationDrawerManager: NotificationDrawerManager @Inject lateinit var pushRuleTriggerListener: PushRuleTriggerListener + @Inject lateinit var vectorPreferences: VectorPreferences lateinit var vectorComponent: VectorComponent private var fontThreadHandler: Handler? = null @@ -122,7 +124,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration. fun entersBackground() { Timber.i("App entered background") // call persistInfo notificationDrawerManager.persistInfo() - FcmHelper.onEnterBackground(appContext, activeSessionHolder) + FcmHelper.onEnterBackground(appContext, vectorPreferences, activeSessionHolder) } }) //This should be done as early as possible diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt index 35cda2e6c6..bfea80bca9 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt @@ -59,10 +59,7 @@ import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewNoPreviewFragment -import im.vector.riotx.features.settings.VectorSettingsActivity -import im.vector.riotx.features.settings.VectorSettingsNotificationPreferenceFragment -import im.vector.riotx.features.settings.VectorSettingsNotificationsTroubleshootFragment -import im.vector.riotx.features.settings.VectorSettingsPreferencesFragment +import im.vector.riotx.features.settings.* import im.vector.riotx.features.settings.push.PushGatewaysFragment @Component(dependencies = [VectorComponent::class], modules = [ViewModelModule::class, HomeModule::class]) @@ -153,6 +150,10 @@ interface ScreenComponent { fun inject(vectorSettingsPreferencesFragment: VectorSettingsPreferencesFragment) + fun inject(vectorSettingsAdvancedNotificationPreferenceFragment: VectorSettingsAdvancedNotificationPreferenceFragment) + + fun inject(vectorSettingsSecurityPrivacyFragment: VectorSettingsSecurityPrivacyFragment) + fun inject(userAvatarPreference: UserAvatarPreference) fun inject(vectorSettingsNotificationsTroubleshootFragment: VectorSettingsNotificationsTroubleshootFragment) diff --git a/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt index 3743e886a7..d1b87f0b82 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt @@ -41,6 +41,7 @@ import im.vector.riotx.features.notifications.NotificationDrawerManager import im.vector.riotx.features.notifications.PushRuleTriggerListener import im.vector.riotx.features.rageshake.BugReporter import im.vector.riotx.features.rageshake.VectorUncaughtExceptionHandler +import im.vector.riotx.features.settings.VectorPreferences import javax.inject.Singleton @Component(modules = [VectorModule::class]) @@ -95,6 +96,8 @@ interface VectorComponent { fun notifiableEventResolver(): NotifiableEventResolver + fun vectorPreferences(): VectorPreferences + @Component.Factory interface Factory { fun create(@BindsInstance context: Context): VectorComponent diff --git a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt index 346f4766a5..0d2c30a5b9 100644 --- a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt @@ -16,13 +16,12 @@ package im.vector.riotx.core.resources -import android.content.Context import im.vector.riotx.features.settings.VectorPreferences import javax.inject.Inject -class UserPreferencesProvider @Inject constructor(private val context: Context) { +class UserPreferencesProvider @Inject constructor(private val vectorPreferences: VectorPreferences) { fun shouldShowHiddenEvents(): Boolean { - return VectorPreferences.shouldShowHiddenEvents(context) + return vectorPreferences.shouldShowHiddenEvents() } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 4d691f50e7..ebaa006b72 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -184,6 +184,7 @@ class RoomDetailFragment : private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback private lateinit var scrollOnHighlightedEventCallback: ScrollOnHighlightedEventCallback @Inject lateinit var eventHtmlRenderer: EventHtmlRenderer + @Inject lateinit var vectorPreferences: VectorPreferences override fun getLayoutResId() = R.layout.fragment_room_detail @@ -389,7 +390,7 @@ class RoomDetailFragment : recyclerView.setController(timelineEventController) timelineEventController.callback = this - if (VectorPreferences.swipeToReplyIsEnabled(requireContext())) { + if (vectorPreferences.swipeToReplyIsEnabled()) { val swipeCallback = RoomMessageTouchHelperCallback(requireContext(), R.drawable.ic_reply, object : RoomMessageTouchHelperCallback.QuickReplayHandler { @@ -482,7 +483,7 @@ class RoomDetailFragment : composerLayout.sendButton.setOnClickListener { val textMessage = composerLayout.composerEditText.text.toString() if (textMessage.isNotBlank()) { - roomDetailViewModel.process(RoomDetailActions.SendMessage(textMessage, VectorPreferences.isMarkdownEnabled(requireContext()))) + roomDetailViewModel.process(RoomDetailActions.SendMessage(textMessage, vectorPreferences.isMarkdownEnabled())) } } composerLayout.composerRelatedMessageCloseButton.setOnClickListener { @@ -507,7 +508,7 @@ class RoomDetailFragment : items.add(DialogListItem.SendFile) // Send voice - if (VectorPreferences.isSendVoiceFeatureEnabled(this)) { + if (vectorPreferences.isSendVoiceFeatureEnabled()) { items.add(DialogListItem.SendVoice.INSTANCE) } @@ -516,7 +517,7 @@ class RoomDetailFragment : //items.add(DialogListItem.SendSticker) // Camera - //if (VectorPreferences.useNativeCamera(this)) { + //if (vectorPreferences.useNativeCamera()) { items.add(DialogListItem.TakePhoto) items.add(DialogListItem.TakeVideo) //} else { @@ -638,8 +639,12 @@ class RoomDetailFragment : private fun renderSendMessageResult(sendMessageResult: SendMessageResult) { when (sendMessageResult) { - is SendMessageResult.MessageSent, + is SendMessageResult.MessageSent -> { + // Clear composer + composerLayout.composerEditText.text = null + } is SendMessageResult.SlashCommandHandled -> { + sendMessageResult.messageRes?.let { showSnackWithMessage(getString(it)) } // Clear composer composerLayout.composerEditText.text = null } @@ -959,7 +964,7 @@ class RoomDetailFragment : // vibrate = true } -// if (vibrate && VectorPreferences.vibrateWhenMentioning(context)) { +// if (vibrate && vectorPreferences.vibrateWhenMentioning()) { // val v= context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator // if (v?.hasVibrator() == true) { // v.vibrate(100) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 2bb7327d57..fe87117dcd 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -56,6 +56,7 @@ import im.vector.riotx.core.utils.subscribeLogError import im.vector.riotx.features.command.CommandParser import im.vector.riotx.features.command.ParsedCommand import im.vector.riotx.features.home.room.detail.timeline.helper.TimelineDisplayableEvents +import im.vector.riotx.features.settings.VectorPreferences import io.reactivex.rxkotlin.subscribeBy import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer @@ -66,6 +67,7 @@ import java.util.concurrent.TimeUnit class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: RoomDetailViewState, userPreferencesProvider: UserPreferencesProvider, + private val vectorPreferences: VectorPreferences, private val session: Session ) : VectorViewModel(initialState) { @@ -243,8 +245,9 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandNotImplemented) } is ParsedCommand.SetMarkdown -> { - // TODO - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandNotImplemented) + vectorPreferences.setMarkdownEnabled(slashCommandResult.enable) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled( + if (slashCommandResult.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled)) } is ParsedCommand.UnbanUser -> { // TODO @@ -268,7 +271,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } is ParsedCommand.SendEmote -> { room.sendTextMessage(slashCommandResult.message, msgType = MessageType.MSGTYPE_EMOTE) - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) } is ParsedCommand.ChangeTopic -> { handleChangeTopicSlashCommand(slashCommandResult) @@ -348,8 +351,6 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } } } - // Handle slash command - } private fun legacyRiotQuoteText(quotedText: String?, myText: String): String { @@ -371,7 +372,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleChangeTopicSlashCommand(changeTopic: ParsedCommand.ChangeTopic) { - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) room.updateTopic(changeTopic.topic, object : MatrixCallback { override fun onSuccess(data: Unit) { @@ -385,7 +386,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) { - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) room.invite(invite.userId, object : MatrixCallback { override fun onSuccess(data: Unit) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt index ae7a470605..c64b1fbd19 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt @@ -16,13 +16,14 @@ package im.vector.riotx.features.home.room.detail +import androidx.annotation.StringRes import im.vector.riotx.features.command.Command sealed class SendMessageResult { object MessageSent : SendMessageResult() class SlashCommandError(val command: Command) : SendMessageResult() class SlashCommandUnknown(val command: String) : SendMessageResult() - object SlashCommandHandled : SendMessageResult() + data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult() object SlashCommandResultOk : SendMessageResult() class SlashCommandResultError(val throwable: Throwable) : SendMessageResult() // TODO Remove diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt index 45317da570..6695c10955 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt @@ -44,6 +44,7 @@ import javax.inject.Singleton */ @Singleton class NotificationDrawerManager @Inject constructor(private val context: Context, + private val vectorPreferences: VectorPreferences, private val activeSessionHolder: ActiveSessionHolder, private val iconLoader: IconLoader, private val bitmapLoader: BitmapLoader, @@ -73,7 +74,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context Events might be grouped and there might not be one notification per event! */ fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { - if (!VectorPreferences.areNotificationEnabledForDevice(context)) { + if (!vectorPreferences.areNotificationEnabledForDevice()) { Timber.i("Notification are disabled for this device") return } @@ -326,7 +327,13 @@ class NotificationDrawerManager @Inject constructor(private val context: Context globalLastMessageTimestamp = lastMessageTimestamp } - NotificationUtils.buildMessagesListNotification(context, style, roomEventGroupInfo, largeBitmap, lastMessageTimestamp, myUserDisplayName) + NotificationUtils.buildMessagesListNotification(context, + vectorPreferences, + style, + roomEventGroupInfo, + largeBitmap, + lastMessageTimestamp, + myUserDisplayName) ?.let { //is there an id for this room? notifications.add(it) @@ -344,7 +351,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context for (event in simpleEvents) { //We build a simple event if (firstTime || !event.hasBeenDisplayed) { - NotificationUtils.buildSimpleEventNotification(context, event, null, session.myUserId)?.let { + NotificationUtils.buildSimpleEventNotification(context, vectorPreferences, event, null, session.myUserId)?.let { notifications.add(it) NotificationUtils.showNotificationMessage(context, event.eventId, ROOM_EVENT_NOTIFICATION_ID, it) event.hasBeenDisplayed = true //we can consider it as displayed @@ -383,6 +390,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context NotificationUtils.buildSummaryListNotification( context, + vectorPreferences, summaryInboxStyle, sumTitle, noisy = hasNewEvent && summaryIsNoisy, diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt index 80249912db..4d7a3edfd8 100755 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt @@ -367,6 +367,7 @@ object NotificationUtils { * Build a notification for a Room */ fun buildMessagesListNotification(context: Context, + vectorPreferences: VectorPreferences, messageStyle: NotificationCompat.MessagingStyle, roomInfo: RoomEventGroupInfo, largeIcon: Bitmap?, @@ -420,7 +421,7 @@ object NotificationUtils { priority = NotificationCompat.PRIORITY_DEFAULT if (roomInfo.shouldBing) { //Compat - VectorPreferences.getNotificationRingTone(context)?.let { + vectorPreferences.getNotificationRingTone()?.let { setSound(it) } setLights(accentColor, 500, 500) @@ -476,7 +477,11 @@ object NotificationUtils { } - fun buildSimpleEventNotification(context: Context, simpleNotifiableEvent: NotifiableEvent, largeIcon: Bitmap?, matrixId: String): Notification? { + fun buildSimpleEventNotification(context: Context, + vectorPreferences: VectorPreferences, + simpleNotifiableEvent: NotifiableEvent, + largeIcon: Bitmap?, + matrixId: String): Notification? { val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) // Build the pending intent for when the notification is clicked val smallIcon = R.drawable.ic_status_bar @@ -534,7 +539,7 @@ object NotificationUtils { if (simpleNotifiableEvent.noisy) { //Compat priority = NotificationCompat.PRIORITY_DEFAULT - VectorPreferences.getNotificationRingTone(context)?.let { + vectorPreferences.getNotificationRingTone()?.let { setSound(it) } setLights(accentColor, 500, 500) @@ -606,6 +611,7 @@ object NotificationUtils { * Build the summary notification */ fun buildSummaryListNotification(context: Context, + vectorPreferences: VectorPreferences, style: NotificationCompat.InboxStyle, compatSummary: String, noisy: Boolean, @@ -630,7 +636,7 @@ object NotificationUtils { if (noisy) { //Compat priority = NotificationCompat.PRIORITY_DEFAULT - VectorPreferences.getNotificationRingTone(context)?.let { + vectorPreferences.getNotificationRingTone()?.let { setSound(it) } setLights(accentColor, 500, 500) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index b607b5a6b6..8ba6c7ed12 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -31,187 +31,192 @@ import im.vector.riotx.features.themes.ThemeUtils import timber.log.Timber import java.io.File import java.util.* +import javax.inject.Inject -object VectorPreferences { +class VectorPreferences @Inject constructor(private val context: Context) { - const val SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2" - const val SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY" - const val SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY" - const val SETTINGS_SDK_VERSION_PREFERENCE_KEY = "SETTINGS_SDK_VERSION_PREFERENCE_KEY" - const val SETTINGS_OLM_VERSION_PREFERENCE_KEY = "SETTINGS_OLM_VERSION_PREFERENCE_KEY" - const val SETTINGS_LOGGED_IN_PREFERENCE_KEY = "SETTINGS_LOGGED_IN_PREFERENCE_KEY" - const val SETTINGS_HOME_SERVER_PREFERENCE_KEY = "SETTINGS_HOME_SERVER_PREFERENCE_KEY" - const val SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY = "SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY" - const val SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY = "SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY" - const val SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY = "SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY" + companion object { + const val SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2" + const val SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY" + const val SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY" + const val SETTINGS_SDK_VERSION_PREFERENCE_KEY = "SETTINGS_SDK_VERSION_PREFERENCE_KEY" + const val SETTINGS_OLM_VERSION_PREFERENCE_KEY = "SETTINGS_OLM_VERSION_PREFERENCE_KEY" + const val SETTINGS_LOGGED_IN_PREFERENCE_KEY = "SETTINGS_LOGGED_IN_PREFERENCE_KEY" + const val SETTINGS_HOME_SERVER_PREFERENCE_KEY = "SETTINGS_HOME_SERVER_PREFERENCE_KEY" + const val SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY = "SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY" + const val SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY = "SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY" + const val SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY = "SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY" - const val SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY" - const val SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY" - const val SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY" - const val SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY" - const val SETTINGS_COPYRIGHT_PREFERENCE_KEY = "SETTINGS_COPYRIGHT_PREFERENCE_KEY" - const val SETTINGS_CLEAR_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_CACHE_PREFERENCE_KEY" - const val SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY" - const val SETTINGS_USER_SETTINGS_PREFERENCE_KEY = "SETTINGS_USER_SETTINGS_PREFERENCE_KEY" - const val SETTINGS_CONTACT_PREFERENCE_KEYS = "SETTINGS_CONTACT_PREFERENCE_KEYS" - const val SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY" - const val SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_IGNORED_USERS_PREFERENCE_KEY = "SETTINGS_IGNORED_USERS_PREFERENCE_KEY" - const val SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY = "SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY" - const val SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_LABS_PREFERENCE_KEY = "SETTINGS_LABS_PREFERENCE_KEY" - const val SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY" - const val SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY" - const val SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_DEVICES_LIST_PREFERENCE_KEY" - const val SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY = "SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY" - const val SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY = "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY" - const val SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY = "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY" - const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY" + const val SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY" + const val SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY" + const val SETTINGS_COPYRIGHT_PREFERENCE_KEY = "SETTINGS_COPYRIGHT_PREFERENCE_KEY" + const val SETTINGS_CLEAR_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_CACHE_PREFERENCE_KEY" + const val SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY" + const val SETTINGS_USER_SETTINGS_PREFERENCE_KEY = "SETTINGS_USER_SETTINGS_PREFERENCE_KEY" + const val SETTINGS_CONTACT_PREFERENCE_KEYS = "SETTINGS_CONTACT_PREFERENCE_KEYS" + const val SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_IGNORED_USERS_PREFERENCE_KEY = "SETTINGS_IGNORED_USERS_PREFERENCE_KEY" + const val SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY = "SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY" + const val SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_LABS_PREFERENCE_KEY = "SETTINGS_LABS_PREFERENCE_KEY" + const val SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY" + const val SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY" + const val SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_DEVICES_LIST_PREFERENCE_KEY" + const val SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY = "SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY" + const val SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY = "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY" + const val SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY = "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY" + const val SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY" - const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY" + const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY" - // user - const val SETTINGS_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_DISPLAY_NAME_PREFERENCE_KEY" - const val SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY = "SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY" + // user + const val SETTINGS_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_DISPLAY_NAME_PREFERENCE_KEY" + const val SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY = "SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY" - // contacts - const val SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY = "SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY" + // contacts + const val SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY = "SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY" - // interface - const val SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY = "SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY" - const val SETTINGS_INTERFACE_TEXT_SIZE_KEY = "SETTINGS_INTERFACE_TEXT_SIZE_KEY" - const val SETTINGS_SHOW_URL_PREVIEW_KEY = "SETTINGS_SHOW_URL_PREVIEW_KEY" - private const val SETTINGS_SEND_TYPING_NOTIF_KEY = "SETTINGS_SEND_TYPING_NOTIF_KEY" - private const val SETTINGS_ENABLE_MARKDOWN_KEY = "SETTINGS_ENABLE_MARKDOWN_KEY" - private const val SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY = "SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY" - private const val SETTINGS_12_24_TIMESTAMPS_KEY = "SETTINGS_12_24_TIMESTAMPS_KEY" - private const val SETTINGS_SHOW_READ_RECEIPTS_KEY = "SETTINGS_SHOW_READ_RECEIPTS_KEY" - private const val SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY = "SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY" - private const val SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY = "SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY" - private const val SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY" - private const val SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER" + // interface + const val SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY = "SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY" + const val SETTINGS_INTERFACE_TEXT_SIZE_KEY = "SETTINGS_INTERFACE_TEXT_SIZE_KEY" + const val SETTINGS_SHOW_URL_PREVIEW_KEY = "SETTINGS_SHOW_URL_PREVIEW_KEY" + private const val SETTINGS_SEND_TYPING_NOTIF_KEY = "SETTINGS_SEND_TYPING_NOTIF_KEY" + private const val SETTINGS_ENABLE_MARKDOWN_KEY = "SETTINGS_ENABLE_MARKDOWN_KEY" + private const val SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY = "SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY" + private const val SETTINGS_12_24_TIMESTAMPS_KEY = "SETTINGS_12_24_TIMESTAMPS_KEY" + private const val SETTINGS_SHOW_READ_RECEIPTS_KEY = "SETTINGS_SHOW_READ_RECEIPTS_KEY" + private const val SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY = "SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY" + private const val SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY = "SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY" + private const val SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY" + private const val SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER" - // home - private const val SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY = "SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY" - private const val SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY = "SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY" + // home + private const val SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY = "SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY" + private const val SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY = "SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY" - // flair - const val SETTINGS_GROUPS_FLAIR_KEY = "SETTINGS_GROUPS_FLAIR_KEY" + // flair + const val SETTINGS_GROUPS_FLAIR_KEY = "SETTINGS_GROUPS_FLAIR_KEY" - // notifications - const val SETTINGS_NOTIFICATIONS_KEY = "SETTINGS_NOTIFICATIONS_KEY" - const val SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY = "SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY" - const val SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY = "SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY" - // public static final String SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY = "SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"; - const val SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY" - const val SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY" - const val SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY" - const val SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY" - const val SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY" - const val SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY_2" - const val SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY_2" - const val SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY_2" - const val SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY_2" - const val SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY = "SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY_2" - const val SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY = "SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY_2" + // notifications + const val SETTINGS_NOTIFICATIONS_KEY = "SETTINGS_NOTIFICATIONS_KEY" + const val SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY = "SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY" + const val SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY = "SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY" + // public static final String SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY = "SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"; + const val SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY" + const val SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY" + const val SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY" + const val SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY_2" + const val SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY_2" + const val SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY_2" + const val SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY_2" + const val SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY = "SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY_2" + const val SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY = "SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY_2" - // media - private const val SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY = "SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY" - private const val SETTINGS_DEFAULT_MEDIA_SOURCE_KEY = "SETTINGS_DEFAULT_MEDIA_SOURCE_KEY" - private const val SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY = "SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY" - private const val SETTINGS_PLAY_SHUTTER_SOUND_KEY = "SETTINGS_PLAY_SHUTTER_SOUND_KEY" + // media + private const val SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY = "SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY" + private const val SETTINGS_DEFAULT_MEDIA_SOURCE_KEY = "SETTINGS_DEFAULT_MEDIA_SOURCE_KEY" + private const val SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY = "SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY" + private const val SETTINGS_PLAY_SHUTTER_SOUND_KEY = "SETTINGS_PLAY_SHUTTER_SOUND_KEY" - // background sync - const val SETTINGS_START_ON_BOOT_PREFERENCE_KEY = "SETTINGS_START_ON_BOOT_PREFERENCE_KEY" - const val SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY" - const val SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY = "SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY" - const val SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY = "SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY" + // background sync + const val SETTINGS_START_ON_BOOT_PREFERENCE_KEY = "SETTINGS_START_ON_BOOT_PREFERENCE_KEY" + const val SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY" + const val SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY = "SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY" + const val SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY = "SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY" - // Calls - const val SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY" - const val SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY" + // Calls + const val SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY" + const val SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY" - // labs - const val SETTINGS_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_LAZY_LOADING_PREFERENCE_KEY" - const val SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY" - const val SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY = "SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY" - private const val SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY = "SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY" - private const val SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY = "SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY" - private const val SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY = "SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY" + // labs + const val SETTINGS_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_LAZY_LOADING_PREFERENCE_KEY" + const val SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY" + const val SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY = "SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY" + private const val SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY = "SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY" + private const val SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY = "SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY" + private const val SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY = "SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY" - private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY" - private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY" + private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY" + private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY" - // analytics - const val SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY" - const val SETTINGS_USE_RAGE_SHAKE_KEY = "SETTINGS_USE_RAGE_SHAKE_KEY" + // analytics + const val SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY" + const val SETTINGS_USE_RAGE_SHAKE_KEY = "SETTINGS_USE_RAGE_SHAKE_KEY" - // other - const val SETTINGS_MEDIA_SAVING_PERIOD_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_KEY" - private const val SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY" - private const val DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY = "DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY" - private const val DID_MIGRATE_TO_NOTIFICATION_REWORK = "DID_MIGRATE_TO_NOTIFICATION_REWORK" - private const val DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY = "DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY" - const val SETTINGS_DEACTIVATE_ACCOUNT_KEY = "SETTINGS_DEACTIVATE_ACCOUNT_KEY" - private const val SETTINGS_DISPLAY_ALL_EVENTS_KEY = "SETTINGS_DISPLAY_ALL_EVENTS_KEY" + // other + const val SETTINGS_MEDIA_SAVING_PERIOD_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_KEY" + private const val SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY" + private const val DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY = "DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY" + private const val DID_MIGRATE_TO_NOTIFICATION_REWORK = "DID_MIGRATE_TO_NOTIFICATION_REWORK" + private const val DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY = "DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY" + const val SETTINGS_DEACTIVATE_ACCOUNT_KEY = "SETTINGS_DEACTIVATE_ACCOUNT_KEY" + private const val SETTINGS_DISPLAY_ALL_EVENTS_KEY = "SETTINGS_DISPLAY_ALL_EVENTS_KEY" - private const val MEDIA_SAVING_3_DAYS = 0 - private const val MEDIA_SAVING_1_WEEK = 1 - private const val MEDIA_SAVING_1_MONTH = 2 - private const val MEDIA_SAVING_FOREVER = 3 + private const val MEDIA_SAVING_3_DAYS = 0 + private const val MEDIA_SAVING_1_WEEK = 1 + private const val MEDIA_SAVING_1_MONTH = 2 + private const val MEDIA_SAVING_FOREVER = 3 - // some preferences keys must be kept after a logout - private val mKeysToKeepAfterLogout = Arrays.asList( - SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY, - SETTINGS_DEFAULT_MEDIA_SOURCE_KEY, - SETTINGS_PLAY_SHUTTER_SOUND_KEY, + // some preferences keys must be kept after a logout + private val mKeysToKeepAfterLogout = Arrays.asList( + SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY, + SETTINGS_DEFAULT_MEDIA_SOURCE_KEY, + SETTINGS_PLAY_SHUTTER_SOUND_KEY, - SETTINGS_SEND_TYPING_NOTIF_KEY, - SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, - SETTINGS_12_24_TIMESTAMPS_KEY, - SETTINGS_SHOW_READ_RECEIPTS_KEY, - SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, - SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY, - SETTINGS_MEDIA_SAVING_PERIOD_KEY, - SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, - SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY, - SETTINGS_SEND_MESSAGE_WITH_ENTER, + SETTINGS_SEND_TYPING_NOTIF_KEY, + SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, + SETTINGS_12_24_TIMESTAMPS_KEY, + SETTINGS_SHOW_READ_RECEIPTS_KEY, + SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, + SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY, + SETTINGS_MEDIA_SAVING_PERIOD_KEY, + SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, + SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY, + SETTINGS_SEND_MESSAGE_WITH_ENTER, - SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY, - SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY, - // Do not keep SETTINGS_LAZY_LOADING_PREFERENCE_KEY because the user may log in on a server which does not support lazy loading - SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY, - SETTINGS_START_ON_BOOT_PREFERENCE_KEY, - SETTINGS_INTERFACE_TEXT_SIZE_KEY, - SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY, - SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, - SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY, + SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY, + SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY, + // Do not keep SETTINGS_LAZY_LOADING_PREFERENCE_KEY because the user may log in on a server which does not support lazy loading + SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY, + SETTINGS_START_ON_BOOT_PREFERENCE_KEY, + SETTINGS_INTERFACE_TEXT_SIZE_KEY, + SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY, + SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, + SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY, - SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY, - SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY, - SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY, - SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY, - SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY, - SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY, - SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY, + SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY, + SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY, + SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY, + SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY, + SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY, + SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY, + SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY, - SETTINGS_USE_RAGE_SHAKE_KEY - ) + SETTINGS_USE_RAGE_SHAKE_KEY + ) + } + + private val defaultPrefs = PreferenceManager.getDefaultSharedPreferences(context) /** * Clear the preferences. * * @param context the context */ - fun clearPreferences(context: Context) { + fun clearPreferences() { val keysToKeep = HashSet(mKeysToKeepAfterLogout) // home server urls @@ -221,37 +226,35 @@ object VectorPreferences { // theme keysToKeep.add(ThemeUtils.APPLICATION_THEME_KEY) - val preferences = PreferenceManager.getDefaultSharedPreferences(context) - preferences.edit { - // get all the existing keys - val keys = preferences.all.keys - // remove the one to keep + // get all the existing keys + val keys = defaultPrefs.all.keys - keys.removeAll(keysToKeep) + // remove the one to keep + keys.removeAll(keysToKeep) + defaultPrefs.edit { for (key in keys) { remove(key) } } } - fun areNotificationEnabledForDevice(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, true) + fun areNotificationEnabledForDevice(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, true) } - fun setNotificationEnabledForDevice(context: Context, enabled: Boolean?) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, enabled!!) - } + fun setNotificationEnabledForDevice(enabled: Boolean?) { + defaultPrefs.edit { + putBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, enabled!!) + } } - fun shouldShowHiddenEvents(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY, false) + fun shouldShowHiddenEvents(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY, false) } - fun swipeToReplyIsEnabled(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY, true) + fun swipeToReplyIsEnabled(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY, true) } /** @@ -260,8 +263,8 @@ object VectorPreferences { * @param context the context * @return true if it was already requested */ - fun didAskUserToIgnoreBatteryOptimizations(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, false) + fun didAskUserToIgnoreBatteryOptimizations(): Boolean { + return defaultPrefs.getBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, false) } /** @@ -269,22 +272,20 @@ object VectorPreferences { * * @param context the context */ - fun setDidAskUserToIgnoreBatteryOptimizations(context: Context) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, true) - } + fun setDidAskUserToIgnoreBatteryOptimizations() { + defaultPrefs.edit { + putBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, true) + } } - fun didMigrateToNotificationRework(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, false) + fun didMigrateToNotificationRework(): Boolean { + return defaultPrefs.getBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, false) } - fun setDidMigrateToNotificationRework(context: Context) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, true) - } + fun setDidMigrateToNotificationRework() { + defaultPrefs.edit { + putBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, true) + } } /** @@ -293,8 +294,8 @@ object VectorPreferences { * @param context the context * @return true if the time must be displayed in 12h format */ - fun displayTimeIn12hFormat(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_12_24_TIMESTAMPS_KEY, false) + fun displayTimeIn12hFormat(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_12_24_TIMESTAMPS_KEY, false) } /** @@ -303,8 +304,8 @@ object VectorPreferences { * @param context the context * @return true if the join and leave membership events should be shown in the messages list */ - fun showJoinLeaveMessages(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, true) + fun showJoinLeaveMessages(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, true) } /** @@ -313,8 +314,8 @@ object VectorPreferences { * @param context the context * @return true true if the avatar and display name events should be shown in the messages list. */ - fun showAvatarDisplayNameChangeMessages(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY, true) + fun showAvatarDisplayNameChangeMessages(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY, true) } /** @@ -323,8 +324,8 @@ object VectorPreferences { * @param context the context * @return true to use the native camera app to record video or take photo. */ - fun useNativeCamera(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY, false) + fun useNativeCamera(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY, false) } /** @@ -333,8 +334,8 @@ object VectorPreferences { * @param context the context * @return true if the send voice feature is enabled. */ - fun isSendVoiceFeatureEnabled(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY, false) + fun isSendVoiceFeatureEnabled(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY, false) } /** @@ -343,8 +344,8 @@ object VectorPreferences { * @param context the context * @return the selected compression level */ - fun getSelectedDefaultMediaCompressionLevel(context: Context): Int { - return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY, "0")!!) + fun getSelectedDefaultMediaCompressionLevel(): Int { + return Integer.parseInt(defaultPrefs.getString(SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY, "0")!!) } /** @@ -353,8 +354,8 @@ object VectorPreferences { * @param context the context * @return the selected media source */ - fun getSelectedDefaultMediaSource(context: Context): Int { - return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_DEFAULT_MEDIA_SOURCE_KEY, "0")!!) + fun getSelectedDefaultMediaSource(): Int { + return Integer.parseInt(defaultPrefs.getString(SETTINGS_DEFAULT_MEDIA_SOURCE_KEY, "0")!!) } /** @@ -363,8 +364,8 @@ object VectorPreferences { * @param context the context * @return true if shutter sound should play */ - fun useShutterSound(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PLAY_SHUTTER_SOUND_KEY, true) + fun useShutterSound(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_PLAY_SHUTTER_SOUND_KEY, true) } /** @@ -373,9 +374,8 @@ object VectorPreferences { * @param context the context * @param uri the new notification ringtone, or null for no RingTone */ - fun setNotificationRingTone(context: Context, uri: Uri?) { - PreferenceManager.getDefaultSharedPreferences(context).edit { - + fun setNotificationRingTone(uri: Uri?) { + defaultPrefs.edit { var value = "" if (null != uri) { @@ -399,8 +399,8 @@ object VectorPreferences { * @param context the context * @return the selected ring tone or null for no RingTone */ - fun getNotificationRingTone(context: Context): Uri? { - val url = PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, null) + fun getNotificationRingTone(): Uri? { + val url = defaultPrefs.getString(SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, null) // the user selects "None" if (TextUtils.equals(url, "")) { @@ -433,8 +433,8 @@ object VectorPreferences { * @param context the context * @return the filename or null if "None" is selected */ - fun getNotificationRingToneName(context: Context): String? { - val toneUri = getNotificationRingTone(context) ?: return null + fun getNotificationRingToneName(): String? { + val toneUri = getNotificationRingTone() ?: return null var name: String? = null @@ -467,11 +467,10 @@ object VectorPreferences { * @param context the context * @param newValue true to enable lazy loading, false to disable it */ - fun setUseLazyLoading(context: Context, newValue: Boolean) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, newValue) - } + fun setUseLazyLoading(newValue: Boolean) { + defaultPrefs.edit { + putBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, newValue) + } } /** @@ -480,8 +479,8 @@ object VectorPreferences { * @param context the context * @return true if the lazy loading of room members is enabled */ - fun useLazyLoading(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, false) + fun useLazyLoading(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, false) } /** @@ -489,11 +488,10 @@ object VectorPreferences { * * @param context the context */ - fun setUserRefuseLazyLoading(context: Context) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, true) - } + fun setUserRefuseLazyLoading() { + defaultPrefs.edit { + putBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, true) + } } /** @@ -502,8 +500,8 @@ object VectorPreferences { * @param context the context * @return true if the user has explicitly refuse the lazy loading of room members */ - fun hasUserRefusedLazyLoading(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, false) + fun hasUserRefusedLazyLoading(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, false) } /** @@ -512,8 +510,8 @@ object VectorPreferences { * @param context the context * @return true if the data save mode is enabled */ - fun useDataSaveMode(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY, false) + fun useDataSaveMode(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY, false) } /** @@ -522,8 +520,8 @@ object VectorPreferences { * @param context the context * @return true if the conference call must be done with jitsi. */ - fun useJitsiConfCall(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY, true) + fun useJitsiConfCall(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY, true) } /** @@ -532,8 +530,8 @@ object VectorPreferences { * @param context the context * @return true if the application must be started on boot */ - fun autoStartOnBoot(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, true) + fun autoStartOnBoot(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, true) } /** @@ -542,11 +540,10 @@ object VectorPreferences { * @param context the context * @param value true to start the application on boot */ - fun setAutoStartOnBoot(context: Context, value: Boolean) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, value) - } + fun setAutoStartOnBoot(value: Boolean) { + defaultPrefs.edit { + putBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, value) + } } /** @@ -555,8 +552,8 @@ object VectorPreferences { * @param context the context * @return the selected period */ - fun getSelectedMediasSavingPeriod(context: Context): Int { - return PreferenceManager.getDefaultSharedPreferences(context).getInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, MEDIA_SAVING_1_WEEK) + fun getSelectedMediasSavingPeriod(): Int { + return defaultPrefs.getInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, MEDIA_SAVING_1_WEEK) } /** @@ -565,11 +562,10 @@ object VectorPreferences { * @param context the context * @param index the selected period index */ - fun setSelectedMediasSavingPeriod(context: Context, index: Int) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, index) - } + fun setSelectedMediasSavingPeriod(index: Int) { + defaultPrefs.edit { + putInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, index) + } } /** @@ -578,8 +574,8 @@ object VectorPreferences { * @param context the context * @return the min last access time (in seconds) */ - fun getMinMediasLastAccessTime(context: Context): Long { - val selection = getSelectedMediasSavingPeriod(context) + fun getMinMediasLastAccessTime(): Long { + val selection = getSelectedMediasSavingPeriod() when (selection) { MEDIA_SAVING_3_DAYS -> return System.currentTimeMillis() / 1000 - 3 * 24 * 60 * 60 @@ -597,8 +593,8 @@ object VectorPreferences { * @param context the context * @return the selected period */ - fun getSelectedMediasSavingPeriodString(context: Context): String { - val selection = getSelectedMediasSavingPeriod(context) + fun getSelectedMediasSavingPeriodString(): String { + val selection = getSelectedMediasSavingPeriod() when (selection) { MEDIA_SAVING_3_DAYS -> return context.getString(R.string.media_saving_period_3_days) @@ -612,7 +608,7 @@ object VectorPreferences { /** * Fix some migration issues */ - fun fixMigrationIssues(context: Context) { + fun fixMigrationIssues() { // Nothing to do for the moment } @@ -622,8 +618,8 @@ object VectorPreferences { * @param context the context * @return true if the markdown is enabled */ - fun isMarkdownEnabled(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, true) + fun isMarkdownEnabled(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, true) } /** @@ -632,11 +628,10 @@ object VectorPreferences { * @param context the context * @param isEnabled true to enable the markdown */ - fun setMarkdownEnabled(context: Context, isEnabled: Boolean) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, isEnabled) - } + fun setMarkdownEnabled(isEnabled: Boolean) { + defaultPrefs.edit { + putBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, isEnabled) + } } /** @@ -645,8 +640,8 @@ object VectorPreferences { * @param context the context * @return true if the read receipts should be shown */ - fun showReadReceipts(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, true) + fun showReadReceipts(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, true) } /** @@ -655,8 +650,8 @@ object VectorPreferences { * @param context the context * @return true if the message timestamps must be always shown */ - fun alwaysShowTimeStamps(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, false) + fun alwaysShowTimeStamps(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, false) } /** @@ -665,8 +660,8 @@ object VectorPreferences { * @param context the context * @return true to send the typing notifs */ - fun sendTypingNotifs(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SEND_TYPING_NOTIF_KEY, true) + fun sendTypingNotifs(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SEND_TYPING_NOTIF_KEY, true) } /** @@ -675,8 +670,8 @@ object VectorPreferences { * @param context the context * @return true to move the missed notifications to the left side */ - fun pinMissedNotifications(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY, true) + fun pinMissedNotifications(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY, true) } /** @@ -685,8 +680,8 @@ object VectorPreferences { * @param context the context * @return true to move the unread room to the left side */ - fun pinUnreadMessages(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY, true) + fun pinUnreadMessages(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY, true) } /** @@ -695,8 +690,8 @@ object VectorPreferences { * @param context the context * @return true */ - fun vibrateWhenMentioning(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_VIBRATE_ON_MENTION_KEY, false) + fun vibrateWhenMentioning(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_VIBRATE_ON_MENTION_KEY, false) } /** @@ -705,8 +700,8 @@ object VectorPreferences { * @param context the context * @return true if a dialog has been displayed to ask to use the analytics tracking */ - fun didAskToUseAnalytics(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, false) + fun didAskToUseAnalytics(): Boolean { + return defaultPrefs.getBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, false) } /** @@ -714,11 +709,10 @@ object VectorPreferences { * * @param context the context */ - fun setDidAskToUseAnalytics(context: Context) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, true) - } + fun setDidAskToUseAnalytics() { + defaultPrefs.edit { + putBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, true) + } } /** @@ -727,8 +721,8 @@ object VectorPreferences { * @param context the context * @return true if the analytics tracking is authorized */ - fun useAnalytics(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_ANALYTICS_KEY, false) + fun useAnalytics(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_USE_ANALYTICS_KEY, false) } /** @@ -737,11 +731,10 @@ object VectorPreferences { * @param context the context * @param useAnalytics true to enable the analytics tracking */ - fun setUseAnalytics(context: Context, useAnalytics: Boolean) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_USE_ANALYTICS_KEY, useAnalytics) - } + fun setUseAnalytics(useAnalytics: Boolean) { + defaultPrefs.edit { + putBoolean(SETTINGS_USE_ANALYTICS_KEY, useAnalytics) + } } /** @@ -750,8 +743,8 @@ object VectorPreferences { * @param context the context * @return true to preview media */ - fun previewMediaWhenSending(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY, false) + fun previewMediaWhenSending(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY, false) } /** @@ -760,8 +753,8 @@ object VectorPreferences { * @param context the context * @return true to send message with enter */ - fun sendMessageWithEnter(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SEND_MESSAGE_WITH_ENTER, false) + fun sendMessageWithEnter(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SEND_MESSAGE_WITH_ENTER, false) } /** @@ -770,8 +763,8 @@ object VectorPreferences { * @param context the context * @return true if the rage shake is used */ - fun useRageshake(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, true) + fun useRageshake(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, true) } /** @@ -780,11 +773,10 @@ object VectorPreferences { * @param context the context * @param isEnabled true to enable the rage shake */ - fun setUseRageshake(context: Context, isEnabled: Boolean) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit { - putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, isEnabled) - } + fun setUseRageshake(isEnabled: Boolean) { + defaultPrefs.edit { + putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, isEnabled) + } } /** @@ -793,7 +785,7 @@ object VectorPreferences { * @param context the context * @return true to display all the events even the redacted ones. */ - fun displayAllEvents(context: Context): Boolean { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_DISPLAY_ALL_EVENTS_KEY, false) + fun displayAllEvents(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_DISPLAY_ALL_EVENTS_KEY, false) } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt index 5694ecf8e1..cdd489a9ed 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -24,11 +24,13 @@ import androidx.core.content.edit import androidx.preference.Preference import androidx.preference.PreferenceManager import im.vector.riotx.R +import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.withArgs import im.vector.riotx.core.preference.BingRule import im.vector.riotx.core.preference.BingRulePreference import im.vector.riotx.features.notifications.NotificationUtils import im.vector.riotx.features.notifications.supportNotificationChannels +import javax.inject.Inject class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseFragment() { @@ -45,6 +47,13 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences + @Inject lateinit var vectorPreferences: VectorPreferences + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + + override fun bindPref() { val callNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY) if (supportNotificationChannels()) { @@ -83,13 +92,13 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF if (supportNotificationChannels()) { ringtonePreference.isVisible = false } else { - ringtonePreference.summary = VectorPreferences.getNotificationRingToneName(requireContext()) + ringtonePreference.summary = vectorPreferences.getNotificationRingToneName() ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) - if (null != VectorPreferences.getNotificationRingTone(requireContext())) { - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, VectorPreferences.getNotificationRingTone(requireContext())) + if (null != vectorPreferences.getNotificationRingTone()) { + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, vectorPreferences.getNotificationRingTone()) } startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE) @@ -152,13 +161,12 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF if (resultCode == Activity.RESULT_OK) { when (requestCode) { REQUEST_NOTIFICATION_RINGTONE -> { - VectorPreferences.setNotificationRingTone(requireContext(), - data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) + vectorPreferences.setNotificationRingTone(data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) // test if the selected ring tone can be played - val notificationRingToneName = VectorPreferences.getNotificationRingToneName(requireContext()) + val notificationRingToneName = vectorPreferences.getNotificationRingToneName() if (null != notificationRingToneName) { - VectorPreferences.setNotificationRingTone(requireContext(), VectorPreferences.getNotificationRingTone(requireContext())) + vectorPreferences.setNotificationRingTone(vectorPreferences.getNotificationRingTone()) findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY).summary = notificationRingToneName } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt index f7e3fbfd84..6536c170ee 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt @@ -36,6 +36,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( @Inject lateinit var pushManager: PushersManager @Inject lateinit var activeSessionHolder: ActiveSessionHolder + @Inject lateinit var vectorPreferences: VectorPreferences override fun bindPref() { findPreference(VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY).let { pref -> @@ -84,7 +85,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( val switchPref = preference as SwitchPreference if (switchPref.isChecked) { FcmHelper.getFcmToken(requireContext())?.let { - if (VectorPreferences.areNotificationEnabledForDevice(requireContext())) { + if (vectorPreferences.areNotificationEnabledForDevice()) { pushManager.registerPusherWithFcmKey(it) } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt index 92ea21d05a..60b8f6a0b9 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt @@ -44,6 +44,7 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { } @Inject lateinit var vectorConfiguration: VectorConfiguration + @Inject lateinit var vectorPreferences: VectorPreferences override fun injectWith(injector: ScreenComponent) { injector.inject(this) @@ -113,17 +114,17 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { // update keep medias period findPreference(VectorPreferences.SETTINGS_MEDIA_SAVING_PERIOD_KEY).let { - it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(requireContext()) + it.summary = vectorPreferences.getSelectedMediasSavingPeriodString() it.onPreferenceClickListener = Preference.OnPreferenceClickListener { context?.let { context: Context -> AlertDialog.Builder(context) .setSingleChoiceItems(R.array.media_saving_choice, - VectorPreferences.getSelectedMediasSavingPeriod(context)) { d, n -> - VectorPreferences.setSelectedMediasSavingPeriod(context, n) + vectorPreferences.getSelectedMediasSavingPeriod()) { d, n -> + vectorPreferences.setSelectedMediasSavingPeriod(n) d.cancel() - it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(context) + it.summary = vectorPreferences.getSelectedMediasSavingPeriodString() } .show() } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 06a3343486..8fd24924d3 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -42,6 +42,7 @@ import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.model.rest.DeviceInfo import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse import im.vector.riotx.R +import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.dialogs.ExportKeysDialog import im.vector.riotx.core.intent.ExternalIntentData import im.vector.riotx.core.intent.analyseIntent @@ -57,6 +58,7 @@ import timber.log.Timber import java.text.DateFormat import java.text.SimpleDateFormat import java.util.* +import javax.inject.Inject class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { @@ -127,6 +129,12 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { findPreference(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY) as SwitchPreference } + @Inject lateinit var vectorPreferences: VectorPreferences + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun bindPref() { // Push target refreshPushersList() @@ -142,20 +150,20 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { // Analytics tracking management (findPreference(VectorPreferences.SETTINGS_USE_ANALYTICS_KEY) as SwitchPreference).let { // On if the analytics tracking is activated - it.isChecked = VectorPreferences.useAnalytics(requireContext()) + it.isChecked = vectorPreferences.useAnalytics() it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - VectorPreferences.setUseAnalytics(requireContext(), newValue as Boolean) + vectorPreferences.setUseAnalytics(newValue as Boolean) true } } // Rageshake Management (findPreference(VectorPreferences.SETTINGS_USE_RAGE_SHAKE_KEY) as SwitchPreference).let { - it.isChecked = VectorPreferences.useRageshake(requireContext()) + it.isChecked = vectorPreferences.useRageshake() it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - VectorPreferences.setUseRageshake(requireContext(), newValue as Boolean) + vectorPreferences.setUseRageshake(newValue as Boolean) true } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt index bef1c834c3..c39b94155b 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt @@ -15,7 +15,6 @@ */ package im.vector.riotx.features.settings.troubleshoot -import androidx.appcompat.app.AppCompatActivity import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.features.settings.VectorPreferences @@ -24,20 +23,20 @@ import javax.inject.Inject /** * Checks if notifications are enable in the system settings for this app. */ -class TestDeviceSettings @Inject constructor(private val context: AppCompatActivity, +class TestDeviceSettings @Inject constructor(private val vectorPreferences: VectorPreferences, private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_device_settings_title) { override fun perform() { - if (VectorPreferences.areNotificationEnabledForDevice(context)) { + if (vectorPreferences.areNotificationEnabledForDevice()) { description = stringProvider.getString(R.string.settings_troubleshoot_test_device_settings_success) quickFix = null status = TestStatus.SUCCESS } else { quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) { override fun doFix() { - VectorPreferences.setNotificationEnabledForDevice(context, true) + vectorPreferences.setNotificationEnabledForDevice(true) manager?.retry() } }