mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Merge pull request #472 from vector-im/feature/vectorPref
Dagger for VectorPreferences and /markdown command as a bonus
This commit is contained in:
commit
6d4ee83e65
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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<RoomDetailViewState>(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<Unit> {
|
||||
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<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -31,9 +31,11 @@ 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) {
|
||||
|
||||
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"
|
||||
@ -205,13 +207,16 @@ object VectorPreferences {
|
||||
|
||||
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
|
||||
val keys = defaultPrefs.all.keys
|
||||
|
||||
// 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 {
|
||||
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,20 +272,18 @@ object VectorPreferences {
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
fun setDidAskUserToIgnoreBatteryOptimizations(context: Context) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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 {
|
||||
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,9 +467,8 @@ 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 {
|
||||
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,9 +488,8 @@ object VectorPreferences {
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
fun setUserRefuseLazyLoading(context: Context) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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,9 +540,8 @@ 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 {
|
||||
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,9 +562,8 @@ object VectorPreferences {
|
||||
* @param context the context
|
||||
* @param index the selected period index
|
||||
*/
|
||||
fun setSelectedMediasSavingPeriod(context: Context, index: Int) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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,9 +628,8 @@ object VectorPreferences {
|
||||
* @param context the context
|
||||
* @param isEnabled true to enable the markdown
|
||||
*/
|
||||
fun setMarkdownEnabled(context: Context, isEnabled: Boolean) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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,9 +709,8 @@ object VectorPreferences {
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
fun setDidAskToUseAnalytics(context: Context) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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,9 +731,8 @@ object VectorPreferences {
|
||||
* @param context the context
|
||||
* @param useAnalytics true to enable the analytics tracking
|
||||
*/
|
||||
fun setUseAnalytics(context: Context, useAnalytics: Boolean) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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,9 +773,8 @@ object VectorPreferences {
|
||||
* @param context the context
|
||||
* @param isEnabled true to enable the rage shake
|
||||
*/
|
||||
fun setUseRageshake(context: Context, isEnabled: Boolean) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.edit {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -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<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?)
|
||||
vectorPreferences.setNotificationRingTone(data?.getParcelableExtra<Parcelable>(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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user