Merge pull request #319 from vector-im/feature/code_quality

Feature/code quality
This commit is contained in:
Benoit Marty 2019-07-09 16:29:44 +02:00 committed by GitHub
commit 24b2387703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1098 additions and 1103 deletions

View file

@ -87,7 +87,8 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo
val matrixConfiguration = (appContext as MatrixConfiguration.Provider).providesMatrixConfiguration() val matrixConfiguration = (appContext as MatrixConfiguration.Provider).providesMatrixConfiguration()
instance = Matrix(appContext, matrixConfiguration) instance = Matrix(appContext, matrixConfiguration)
} else { } else {
throw IllegalStateException("Matrix is not initialized properly. You should call Matrix.initialize or let your application implements MatrixConfiguration.Provider.") throw IllegalStateException("Matrix is not initialized properly." +
" You should call Matrix.initialize or let your application implements MatrixConfiguration.Provider.")
} }
} }
return instance return instance

View file

@ -40,7 +40,8 @@ data class PushCondition(
/** /**
* Required for room_member_count conditions. * Required for room_member_count conditions.
* A decimal integer optionally prefixed by one of, ==, <, >, >= or <=. * A decimal integer optionally prefixed by one of, ==, <, >, >= or <=.
* A prefix of < matches rooms where the member count is strictly less than the given number and so forth. If no prefix is present, this parameter defaults to ==. * A prefix of < matches rooms where the member count is strictly less than the given number and so forth.
* If no prefix is present, this parameter defaults to ==.
*/ */
@Json(name = "is") val iz: String? = null @Json(name = "is") val iz: String? = null
) { ) {

View file

@ -85,7 +85,9 @@ sealed class MXCryptoError : Throwable() {
const val BAD_ENCRYPTED_MESSAGE_REASON = "Bad Encrypted Message" const val BAD_ENCRYPTED_MESSAGE_REASON = "Bad Encrypted Message"
const val DUPLICATE_MESSAGE_INDEX_REASON = "Duplicate message index, possible replay attack %1\$s" const val DUPLICATE_MESSAGE_INDEX_REASON = "Duplicate message index, possible replay attack %1\$s"
const val ERROR_MISSING_PROPERTY_REASON = "No '%1\$s' property. Cannot prevent unknown-key attack" const val ERROR_MISSING_PROPERTY_REASON = "No '%1\$s' property. Cannot prevent unknown-key attack"
const val UNKNOWN_DEVICES_REASON = "This room contains unknown devices which have not been verified.\n" + "We strongly recommend you verify them before continuing." const val UNKNOWN_DEVICES_REASON = "This room contains unknown devices which have not been verified.\n" +
const val NO_MORE_ALGORITHM_REASON = "Room was previously configured to use encryption, but is no longer." + " Perhaps the homeserver is hiding the configuration event." "We strongly recommend you verify them before continuing."
const val NO_MORE_ALGORITHM_REASON = "Room was previously configured to use encryption, but is no longer." +
" Perhaps the homeserver is hiding the configuration event."
} }
} }

View file

@ -40,7 +40,8 @@ interface KeysBackupService {
* @param keysBackupCreationInfo the info object from [prepareKeysBackupVersion]. * @param keysBackupCreationInfo the info object from [prepareKeysBackupVersion].
* @param callback Asynchronous callback * @param callback Asynchronous callback
*/ */
fun createKeysBackupVersion(keysBackupCreationInfo: MegolmBackupCreationInfo, callback: MatrixCallback<KeysVersion>) fun createKeysBackupVersion(keysBackupCreationInfo: MegolmBackupCreationInfo,
callback: MatrixCallback<KeysVersion>)
/** /**
* Facility method to get the total number of locally stored keys * Facility method to get the total number of locally stored keys
@ -58,7 +59,8 @@ interface KeysBackupService {
* @param progressListener the callback to follow the progress * @param progressListener the callback to follow the progress
* @param callback the main callback * @param callback the main callback
*/ */
fun backupAllGroupSessions(progressListener: ProgressListener?, callback: MatrixCallback<Unit>?) fun backupAllGroupSessions(progressListener: ProgressListener?,
callback: MatrixCallback<Unit>?)
/** /**
* Check trust on a key backup version. * Check trust on a key backup version.
@ -66,7 +68,8 @@ interface KeysBackupService {
* @param keysBackupVersion the backup version to check. * @param keysBackupVersion the backup version to check.
* @param callback block called when the operations completes. * @param callback block called when the operations completes.
*/ */
fun getKeysBackupTrust(keysBackupVersion: KeysVersionResult, callback: MatrixCallback<KeysBackupVersionTrust>) fun getKeysBackupTrust(keysBackupVersion: KeysVersionResult,
callback: MatrixCallback<KeysBackupVersionTrust>)
/** /**
* Return the current progress of the backup * Return the current progress of the backup
@ -80,7 +83,8 @@ interface KeysBackupService {
* @param version the backup version * @param version the backup version
* @param callback * @param callback
*/ */
fun getVersion(version: String, callback: MatrixCallback<KeysVersionResult?>) fun getVersion(version: String,
callback: MatrixCallback<KeysVersionResult?>)
/** /**
* This method fetches the last backup version on the server, then compare to the currently backup version use. * This method fetches the last backup version on the server, then compare to the currently backup version use.
@ -114,7 +118,9 @@ interface KeysBackupService {
* @param progressListener a progress listener, as generating private key from password may take a while * @param progressListener a progress listener, as generating private key from password may take a while
* @param callback Asynchronous callback * @param callback Asynchronous callback
*/ */
fun prepareKeysBackupVersion(password: String?, progressListener: ProgressListener?, callback: MatrixCallback<MegolmBackupCreationInfo>) fun prepareKeysBackupVersion(password: String?,
progressListener: ProgressListener?,
callback: MatrixCallback<MegolmBackupCreationInfo>)
/** /**
* Delete a keys backup version. It will delete all backed up keys on the server, and the backup itself. * Delete a keys backup version. It will delete all backed up keys on the server, and the backup itself.
@ -123,7 +129,8 @@ interface KeysBackupService {
* @param version the backup version to delete. * @param version the backup version to delete.
* @param callback Asynchronous callback * @param callback Asynchronous callback
*/ */
fun deleteBackup(version: String, callback: MatrixCallback<Unit>?) fun deleteBackup(version: String,
callback: MatrixCallback<Unit>?)
/** /**
* Ask if the backup on the server contains keys that we may do not have locally. * Ask if the backup on the server contains keys that we may do not have locally.
@ -139,7 +146,9 @@ interface KeysBackupService {
* @param trust the trust to set to the keys backup. * @param trust the trust to set to the keys backup.
* @param callback block called when the operations completes. * @param callback block called when the operations completes.
*/ */
fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult, trust: Boolean, callback: MatrixCallback<Unit>) fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult,
trust: Boolean,
callback: MatrixCallback<Unit>)
/** /**
* Set trust on a keys backup version. * Set trust on a keys backup version.
@ -148,7 +157,9 @@ interface KeysBackupService {
* @param recoveryKey the recovery key to challenge with the key backup public key. * @param recoveryKey the recovery key to challenge with the key backup public key.
* @param callback block called when the operations completes. * @param callback block called when the operations completes.
*/ */
fun trustKeysBackupVersionWithRecoveryKey(keysBackupVersion: KeysVersionResult, recoveryKey: String, callback: MatrixCallback<Unit>) fun trustKeysBackupVersionWithRecoveryKey(keysBackupVersion: KeysVersionResult,
recoveryKey: String,
callback: MatrixCallback<Unit>)
/** /**
* Set trust on a keys backup version. * Set trust on a keys backup version.
@ -157,7 +168,9 @@ interface KeysBackupService {
* @param password the pass phrase to challenge with the keyBackupVersion public key. * @param password the pass phrase to challenge with the keyBackupVersion public key.
* @param callback block called when the operations completes. * @param callback block called when the operations completes.
*/ */
fun trustKeysBackupVersionWithPassphrase(keysBackupVersion: KeysVersionResult, password: String, callback: MatrixCallback<Unit>) fun trustKeysBackupVersionWithPassphrase(keysBackupVersion: KeysVersionResult,
password: String,
callback: MatrixCallback<Unit>)
/** /**
* Restore a backup with a recovery key from a given backup version stored on the homeserver. * Restore a backup with a recovery key from a given backup version stored on the homeserver.
@ -169,7 +182,11 @@ interface KeysBackupService {
* @param stepProgressListener the step progress listener * @param stepProgressListener the step progress listener
* @param callback Callback. It provides the number of found keys and the number of successfully imported keys. * @param callback Callback. It provides the number of found keys and the number of successfully imported keys.
*/ */
fun restoreKeysWithRecoveryKey(keysVersionResult: KeysVersionResult, recoveryKey: String, roomId: String?, sessionId: String?, stepProgressListener: StepProgressListener?, callback: MatrixCallback<ImportRoomKeysResult>) fun restoreKeysWithRecoveryKey(keysVersionResult: KeysVersionResult,
recoveryKey: String, roomId: String?,
sessionId: String?,
stepProgressListener: StepProgressListener?,
callback: MatrixCallback<ImportRoomKeysResult>)
/** /**
* Restore a backup with a password from a given backup version stored on the homeserver. * Restore a backup with a password from a given backup version stored on the homeserver.
@ -181,7 +198,12 @@ interface KeysBackupService {
* @param stepProgressListener the step progress listener * @param stepProgressListener the step progress listener
* @param callback Callback. It provides the number of found keys and the number of successfully imported keys. * @param callback Callback. It provides the number of found keys and the number of successfully imported keys.
*/ */
fun restoreKeyBackupWithPassword(keysBackupVersion: KeysVersionResult, password: String, roomId: String?, sessionId: String?, stepProgressListener: StepProgressListener?, callback: MatrixCallback<ImportRoomKeysResult>) fun restoreKeyBackupWithPassword(keysBackupVersion: KeysVersionResult,
password: String,
roomId: String?,
sessionId: String?,
stepProgressListener: StepProgressListener?,
callback: MatrixCallback<ImportRoomKeysResult>)
val keysBackupVersion: KeysVersionResult? val keysBackupVersion: KeysVersionResult?
val currentBackupVersion: String? val currentBackupVersion: String?

View file

@ -67,7 +67,8 @@ data class PublicRoom(
var worldReadable: Boolean = false, var worldReadable: Boolean = false,
/** /**
* Required. Whether guest users may join the room and participate in it. If they can, they will be subject to ordinary power level rules like any other user. * Required. Whether guest users may join the room and participate in it. If they can,
* they will be subject to ordinary power level rules like any other user.
*/ */
@Json(name = "guest_can_join") @Json(name = "guest_can_join")
var guestCanJoin: Boolean = false, var guestCanJoin: Boolean = false,

View file

@ -168,8 +168,10 @@ internal abstract class CryptoModule {
abstract fun bindSendToDeviceTask(sendToDeviceTask: DefaultSendToDeviceTask): SendToDeviceTask abstract fun bindSendToDeviceTask(sendToDeviceTask: DefaultSendToDeviceTask): SendToDeviceTask
@Binds @Binds
abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice): ClaimOneTimeKeysForUsersDeviceTask abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice)
: ClaimOneTimeKeysForUsersDeviceTask
@Binds @Binds
abstract fun bindDeleteDeviceWithUserPasswordTask(deleteDeviceWithUserPasswordTask: DefaultDeleteDeviceWithUserPasswordTask): DeleteDeviceWithUserPasswordTask abstract fun bindDeleteDeviceWithUserPasswordTask(deleteDeviceWithUserPasswordTask: DefaultDeleteDeviceWithUserPasswordTask)
: DeleteDeviceWithUserPasswordTask
} }

View file

@ -229,7 +229,7 @@ object MXMegolmExportEncryption {
throw Exception("Header line not found") throw Exception("Header line not found")
} }
val line = fileStr.substring(lineStart, lineEnd).trim { it <= ' ' } val line = fileStr.substring(lineStart, lineEnd).trim()
// start the next line after the newline // start the next line after the newline
lineStart = lineEnd + 1 lineStart = lineEnd + 1
@ -247,9 +247,9 @@ object MXMegolmExportEncryption {
val line: String val line: String
if (lineEnd < 0) { if (lineEnd < 0) {
line = fileStr.substring(lineStart).trim { it <= ' ' } line = fileStr.substring(lineStart).trim()
} else { } else {
line = fileStr.substring(lineStart, lineEnd).trim { it <= ' ' } line = fileStr.substring(lineStart, lineEnd).trim()
} }
if (TextUtils.equals(line, TRAILER_LINE)) { if (TextUtils.equals(line, TRAILER_LINE)) {

View file

@ -684,7 +684,8 @@ internal class MXOlmDevice @Inject constructor(
adapter.fromJson(payloadString) adapter.fromJson(payloadString)
} catch (e: Exception) { } catch (e: Exception) {
Timber.e("## decryptGroupMessage() : fails to parse the payload") Timber.e("## decryptGroupMessage() : fails to parse the payload")
return@flatMap Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)) return@flatMap Try.Failure(
MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON))
} }
return@flatMap Try.just( return@flatMap Try.just(

View file

@ -31,7 +31,6 @@ import im.vector.matrix.android.internal.task.TaskThread
import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.util.createBackgroundHandler import im.vector.matrix.android.internal.util.createBackgroundHandler
import timber.log.Timber import timber.log.Timber
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject import javax.inject.Inject
@ -132,20 +131,26 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
Timber.v("cancelRoomKeyRequest: requestId: " + req.requestId + " state: " + req.state + " andResend: " + andResend) Timber.v("cancelRoomKeyRequest: requestId: " + req.requestId + " state: " + req.state + " andResend: " + andResend)
if (req.state === OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING || req.state === OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND) { when (req.state) {
// nothing to do here OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING,
} else if (req.state === OutgoingRoomKeyRequest.RequestState.UNSENT || req.state === OutgoingRoomKeyRequest.RequestState.FAILED) { OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND -> {
Timber.v("## cancelRoomKeyRequest() : deleting unnecessary room key request for $requestBody") // nothing to do here
cryptoStore.deleteOutgoingRoomKeyRequest(req.requestId) }
} else if (req.state === OutgoingRoomKeyRequest.RequestState.SENT) { OutgoingRoomKeyRequest.RequestState.UNSENT,
if (andResend) { OutgoingRoomKeyRequest.RequestState.FAILED -> {
req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND Timber.v("## cancelRoomKeyRequest() : deleting unnecessary room key request for $requestBody")
} else { cryptoStore.deleteOutgoingRoomKeyRequest(req.requestId)
req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING }
OutgoingRoomKeyRequest.RequestState.SENT -> {
if (andResend) {
req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND
} else {
req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING
}
req.cancellationTxnId = makeTxnId()
cryptoStore.updateOutgoingRoomKeyRequest(req)
sendOutgoingRoomKeyRequestCancellation(req)
} }
req.cancellationTxnId = makeTxnId()
cryptoStore.updateOutgoingRoomKeyRequest(req)
sendOutgoingRoomKeyRequestCancellation(req)
} }
} }
@ -179,9 +184,9 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
Timber.v("## sendOutgoingRoomKeyRequests() : Looking for queued outgoing room key requests") Timber.v("## sendOutgoingRoomKeyRequests() : Looking for queued outgoing room key requests")
val outgoingRoomKeyRequest = cryptoStore.getOutgoingRoomKeyRequestByState( val outgoingRoomKeyRequest = cryptoStore.getOutgoingRoomKeyRequestByState(
HashSet<OutgoingRoomKeyRequest.RequestState>(Arrays.asList<OutgoingRoomKeyRequest.RequestState>(OutgoingRoomKeyRequest.RequestState.UNSENT, setOf(OutgoingRoomKeyRequest.RequestState.UNSENT,
OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING, OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING,
OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND))) OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND))
if (null == outgoingRoomKeyRequest) { if (null == outgoingRoomKeyRequest) {
Timber.e("## sendOutgoingRoomKeyRequests() : No more outgoing room key requests") Timber.e("## sendOutgoingRoomKeyRequests() : No more outgoing room key requests")

View file

@ -81,7 +81,11 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)) return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON))
} }
return olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext, event.roomId, timeline, encryptedEventContent.sessionId, encryptedEventContent.senderKey) return olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext,
event.roomId,
timeline,
encryptedEventContent.sessionId,
encryptedEventContent.senderKey)
.fold( .fold(
{ throwable -> { throwable ->
if (throwable is MXCryptoError.OlmError) { if (throwable is MXCryptoError.OlmError) {
@ -211,7 +215,8 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
return return
} }
if (event.getClearType() == EventType.FORWARDED_ROOM_KEY) { if (event.getClearType() == EventType.FORWARDED_ROOM_KEY) {
Timber.v("## onRoomKeyEvent(), forward adding key : roomId ${roomKeyContent.roomId} sessionId ${roomKeyContent.sessionId} sessionKey ${roomKeyContent.sessionKey}") // from " + event); Timber.v("## onRoomKeyEvent(), forward adding key : roomId ${roomKeyContent.roomId}" +
" sessionId ${roomKeyContent.sessionId} sessionKey ${roomKeyContent.sessionKey}")
val forwardedRoomKeyContent = event.getClearContent().toModel<ForwardedRoomKeyContent>() val forwardedRoomKeyContent = event.getClearContent().toModel<ForwardedRoomKeyContent>()
?: return ?: return
@ -259,7 +264,13 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
return return
} }
val added = olmDevice.addInboundGroupSession(roomKeyContent.sessionId, roomKeyContent.sessionKey, roomKeyContent.roomId, senderKey, forwardingCurve25519KeyChain, keysClaimed, exportFormat) val added = olmDevice.addInboundGroupSession(roomKeyContent.sessionId,
roomKeyContent.sessionKey,
roomKeyContent.roomId,
senderKey,
forwardingCurve25519KeyChain,
keysClaimed,
exportFormat)
if (added) { if (added) {
keysBackup.maybeBackupKeys() keysBackup.maybeBackupKeys()
@ -322,7 +333,8 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
// were no one-time keys. // were no one-time keys.
Try.just(Unit) Try.just(Unit)
} }
Timber.v("""## shareKeysWithDevice() : sharing keys for session ${body?.senderKey}|${body?.sessionId} with device $userId:$deviceId""") Timber.v("## shareKeysWithDevice() : sharing keys for session" +
" ${body?.senderKey}|${body?.sessionId} with device $userId:$deviceId")
val payloadJson = HashMap<String, Any>() val payloadJson = HashMap<String, Any>()
payloadJson["type"] = EventType.FORWARDED_ROOM_KEY payloadJson["type"] = EventType.FORWARDED_ROOM_KEY

View file

@ -106,7 +106,8 @@ internal class MXOlmDecryption(
} }
if (olmPayloadContent.recipient != credentials.userId) { if (olmPayloadContent.recipient != credentials.userId) {
Timber.e("## decryptEvent() : Event ${event.eventId}: Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}") Timber.e("## decryptEvent() : Event ${event.eventId}:" +
" Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT, return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT,
String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))) String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient)))
} }

View file

@ -665,7 +665,8 @@ internal class KeysBackup @Inject constructor(
// Do not trigger a backup for them if they come from the backup version we are using // Do not trigger a backup for them if they come from the backup version we are using
val backUp = keysVersionResult.version != keysBackupVersion?.version val backUp = keysVersionResult.version != keysBackupVersion?.version
if (backUp) { if (backUp) {
Timber.v("restoreKeysWithRecoveryKey: Those keys will be backed up to backup version: " + keysBackupVersion?.version) Timber.v("restoreKeysWithRecoveryKey: Those keys will be backed up to backup version: "
+ keysBackupVersion?.version)
} }
// Import them into the crypto store // Import them into the crypto store
@ -1224,7 +1225,8 @@ internal class KeysBackup @Inject constructor(
} }
try { try {
keysBackupData.roomIdToRoomKeysBackupData[olmInboundGroupSessionWrapper.roomId]!!.sessionIdToKeyBackupData[olmInboundGroupSessionWrapper.olmInboundGroupSession!!.sessionIdentifier()] = keyBackupData keysBackupData.roomIdToRoomKeysBackupData[olmInboundGroupSessionWrapper.roomId]!!
.sessionIdToKeyBackupData[olmInboundGroupSessionWrapper.olmInboundGroupSession!!.sessionIdentifier()] = keyBackupData
} catch (e: OlmException) { } catch (e: OlmException) {
Timber.e(e, "OlmException") Timber.e(e, "OlmException")
} }
@ -1276,7 +1278,8 @@ internal class KeysBackup @Inject constructor(
// Do not stay in KeysBackupState.WrongBackUpVersion but check what is available on the homeserver // Do not stay in KeysBackupState.WrongBackUpVersion but check what is available on the homeserver
checkAndStartKeysBackup() checkAndStartKeysBackup()
} }
else -> // Come back to the ready state so that we will retry on the next received key else ->
// Come back to the ready state so that we will retry on the next received key
keysBackupStateManager.state = KeysBackupState.ReadyToBackUp keysBackupStateManager.state = KeysBackupState.ReadyToBackUp
} }
} }

View file

@ -34,7 +34,10 @@ import io.realm.Sort
// By default if a chunk is empty we consider it unlinked // By default if a chunk is empty we consider it unlinked
internal fun ChunkEntity.isUnlinked(): Boolean { internal fun ChunkEntity.isUnlinked(): Boolean {
assertIsManaged() assertIsManaged()
return timelineEvents.where().equalTo(TimelineEventEntityFields.ROOT.IS_UNLINKED, false).findAll().isEmpty() return timelineEvents.where()
.equalTo(TimelineEventEntityFields.ROOT.IS_UNLINKED, false)
.findAll()
.isEmpty()
} }
internal fun ChunkEntity.deleteOnCascade() { internal fun ChunkEntity.deleteOnCascade() {

View file

@ -23,7 +23,8 @@ import io.realm.annotations.Index
// at java.lang.Thread.run(Thread.java:764) // at java.lang.Thread.run(Thread.java:764)
// Caused by: java.lang.IllegalArgumentException: 'value' is not a valid managed object. // Caused by: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
// at io.realm.ProxyState.checkValidObject(ProxyState.java:213) // at io.realm.ProxyState.checkValidObject(ProxyState.java:213)
// at io.realm.im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy.realmSet$data(im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy.java:413) // at io.realm.im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy
// .realmSet$data(im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy.java:413)
// at im.vector.matrix.android.internal.database.model.PusherEntity.setData(PusherEntity.kt:16) // at im.vector.matrix.android.internal.database.model.PusherEntity.setData(PusherEntity.kt:16)
// at im.vector.matrix.android.internal.session.pushers.AddHttpPusherWorker$doWork$$inlined$fold$lambda$2.execute(AddHttpPusherWorker.kt:70) // at im.vector.matrix.android.internal.session.pushers.AddHttpPusherWorker$doWork$$inlined$fold$lambda$2.execute(AddHttpPusherWorker.kt:70)
// at io.realm.Realm.executeTransaction(Realm.java:1493) // at io.realm.Realm.executeTransaction(Realm.java:1493)

View file

@ -26,11 +26,13 @@ import io.realm.Sort
import io.realm.kotlin.where import io.realm.kotlin.where
internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventEntity> { internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventEntity> {
return realm.where<EventEntity>().equalTo(EventEntityFields.EVENT_ID, eventId) return realm.where<EventEntity>()
.equalTo(EventEntityFields.EVENT_ID, eventId)
} }
internal fun EventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<EventEntity> { internal fun EventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<EventEntity> {
return realm.where<EventEntity>().`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray()) return realm.where<EventEntity>()
.`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray())
} }
internal fun EventEntity.Companion.where(realm: Realm, internal fun EventEntity.Companion.where(realm: Realm,
@ -86,7 +88,9 @@ internal fun RealmQuery<EventEntity>.prev(since: Int? = null, strict: Boolean =
} }
internal fun RealmList<EventEntity>.find(eventId: String): EventEntity? { internal fun RealmList<EventEntity>.find(eventId: String): EventEntity? {
return this.where().equalTo(EventEntityFields.EVENT_ID, eventId).findFirst() return this.where()
.equalTo(EventEntityFields.EVENT_ID, eventId)
.findFirst()
} }
internal fun RealmList<EventEntity>.fastContains(eventId: String): Boolean { internal fun RealmList<EventEntity>.fastContains(eventId: String): Boolean {

View file

@ -24,7 +24,8 @@ import io.realm.RealmQuery
import io.realm.kotlin.where import io.realm.kotlin.where
internal fun GroupEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<GroupEntity> { internal fun GroupEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<GroupEntity> {
return realm.where<GroupEntity>().equalTo(GroupEntityFields.GROUP_ID, roomId) return realm.where<GroupEntity>()
.equalTo(GroupEntityFields.GROUP_ID, roomId)
} }
internal fun GroupEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<GroupEntity> { internal fun GroupEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<GroupEntity> {

View file

@ -25,7 +25,8 @@ import io.realm.RealmQuery
import io.realm.kotlin.where import io.realm.kotlin.where
internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<RoomEntity> { internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<RoomEntity> {
return realm.where<RoomEntity>().equalTo(RoomEntityFields.ROOM_ID, roomId) return realm.where<RoomEntity>()
.equalTo(RoomEntityFields.ROOM_ID, roomId)
} }
internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<RoomEntity> { internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<RoomEntity> {

View file

@ -29,11 +29,13 @@ import io.realm.Sort
import io.realm.kotlin.where import io.realm.kotlin.where
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<TimelineEventEntity> { internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<TimelineEventEntity> {
return realm.where<TimelineEventEntity>().equalTo(TimelineEventEntityFields.EVENT_ID, eventId) return realm.where<TimelineEventEntity>()
.equalTo(TimelineEventEntityFields.EVENT_ID, eventId)
} }
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<TimelineEventEntity> { internal fun TimelineEventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<TimelineEventEntity> {
return realm.where<TimelineEventEntity>().`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray()) return realm.where<TimelineEventEntity>()
.`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray())
} }
internal fun TimelineEventEntity.Companion.where(realm: Realm, internal fun TimelineEventEntity.Companion.where(realm: Realm,
@ -111,5 +113,7 @@ internal fun RealmQuery<TimelineEventEntity>.prev(since: Int? = null, strict: Bo
internal fun RealmList<TimelineEventEntity>.find(eventId: String): TimelineEventEntity? { internal fun RealmList<TimelineEventEntity>.find(eventId: String): TimelineEventEntity? {
return this.where().equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId).findFirst() return this.where()
.equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId)
.findFirst()
} }

View file

@ -14,16 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.riotx.core.di; package im.vector.matrix.android.internal.di
import java.lang.annotation.Documented; import javax.inject.Scope
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.inject.Scope;
@Scope @Scope
@Documented @MustBeDocumented
@Retention(RetentionPolicy.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
public @interface ScreenScope { annotation class MatrixScope
}

View file

@ -14,16 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.matrix.android.internal.di; package im.vector.matrix.android.internal.session
import java.lang.annotation.Documented; import javax.inject.Scope
import java.lang.annotation.Retention;
import javax.inject.Scope;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Scope @Scope
@Documented @MustBeDocumented
@Retention(RUNTIME) @Retention(AnnotationRetention.RUNTIME)
public @interface MatrixScope {} annotation class SessionScope

View file

@ -36,7 +36,8 @@ private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER"
internal class GroupSummaryUpdater @Inject constructor(private val context: Context, internal class GroupSummaryUpdater @Inject constructor(private val context: Context,
private val credentials: Credentials, private val credentials: Credentials,
@SessionDatabase realmConfiguration: RealmConfiguration) : RealmLiveEntityObserver<GroupEntity>(realmConfiguration) { @SessionDatabase realmConfiguration: RealmConfiguration)
: RealmLiveEntityObserver<GroupEntity>(realmConfiguration) {
override val query = Monarchy.Query<GroupEntity> { GroupEntity.where(it) } override val query = Monarchy.Query<GroupEntity> { GroupEntity.where(it) }

View file

@ -69,7 +69,8 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
}.filter { }.filter {
it.senderId != sessionParams.credentials.userId it.senderId != sessionParams.credentials.userId
} }
Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size} to check for push rules with ${params.rules.size} rules") Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size}" +
" to check for push rules with ${params.rules.size} rules")
allEvents.forEach { event -> allEvents.forEach { event ->
fulfilledBingRule(event, params.rules)?.let { fulfilledBingRule(event, params.rules)?.let {
Timber.v("[PushRules] Rule $it match for event ${event.eventId}") Timber.v("[PushRules] Rule $it match for event ${event.eventId}")

View file

@ -66,7 +66,8 @@ internal class RoomFactory @Inject constructor(private val context: Context,
val stateService = DefaultStateService(roomId, taskExecutor, sendStateTask) val stateService = DefaultStateService(roomId, taskExecutor, sendStateTask)
val roomMembersService = DefaultMembershipService(roomId, monarchy, taskExecutor, loadRoomMembersTask, inviteTask, joinRoomTask, leaveRoomTask) val roomMembersService = DefaultMembershipService(roomId, monarchy, taskExecutor, loadRoomMembersTask, inviteTask, joinRoomTask, leaveRoomTask)
val readService = DefaultReadService(roomId, monarchy, taskExecutor, setReadMarkersTask, credentials) val readService = DefaultReadService(roomId, monarchy, taskExecutor, setReadMarkersTask, credentials)
val relationService = DefaultRelationService(context, credentials, roomId, eventFactory, cryptoService, findReactionEventForUndoTask, monarchy, taskExecutor) val relationService = DefaultRelationService(context,
credentials, roomId, eventFactory, cryptoService, findReactionEventForUndoTask, monarchy, taskExecutor)
return DefaultRoom( return DefaultRoom(
roomId, roomId,

View file

@ -116,9 +116,11 @@ internal class DefaultRelationService @Inject constructor(private val context: C
} }
override fun editTextMessage(targetEventId: String, newBodyText: String, newBodyAutoMarkdown: Boolean, compatibilityBodyText: String): Cancelable { override fun editTextMessage(targetEventId: String, newBodyText: String, newBodyAutoMarkdown: Boolean, compatibilityBodyText: String): Cancelable {
val event = eventFactory.createReplaceTextEvent(roomId, targetEventId, newBodyText, newBodyAutoMarkdown, MessageType.MSGTYPE_TEXT, compatibilityBodyText).also { val event = eventFactory
saveLocalEcho(it) .createReplaceTextEvent(roomId, targetEventId, newBodyText, newBodyAutoMarkdown, MessageType.MSGTYPE_TEXT, compatibilityBodyText)
} .also {
saveLocalEcho(it)
}
val workRequest = createSendEventWork(event) val workRequest = createSendEventWork(event)
TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) TimelineSendEventWorkCommon.postWork(context, roomId, workRequest)
return CancelableWork(context, workRequest.id) return CancelableWork(context, workRequest.id)

View file

@ -81,7 +81,12 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
} }
fun createReplaceTextEvent(roomId: String, targetEventId: String, newBodyText: String, newBodyAutoMarkdown: Boolean, msgType: String, compatibilityText: String): Event { fun createReplaceTextEvent(roomId: String,
targetEventId: String,
newBodyText: String,
newBodyAutoMarkdown: Boolean,
msgType: String,
compatibilityText: String): Event {
var newContent = MessageTextContent( var newContent = MessageTextContent(
type = MessageType.MSGTYPE_TEXT, type = MessageType.MSGTYPE_TEXT,
@ -255,9 +260,15 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
// </mx-reply> // </mx-reply>
// This is where the reply goes. // This is where the reply goes.
val body = bodyForReply(eventReplied.getClearContent().toModel<MessageContent>()) val body = bodyForReply(eventReplied.getClearContent().toModel<MessageContent>())
val replyFallbackTemplateFormatted = """ val replyFallbackTemplateFormatted = """<mx-reply>
<mx-reply><blockquote><a href="%s">${stringProvider.getString(R.string.message_reply_to_prefix)}</a><a href="%s">%s</a><br />%s</blockquote></mx-reply>%s <blockquote>
""".trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText) <a href="%s">${stringProvider.getString(R.string.message_reply_to_prefix)}</a>
<a href="%s">%s</a>
<br />
%s
</blockquote>
</mx-reply>
%s""".trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText)
// //
// > <@alice:example.org> This is the original body // > <@alice:example.org> This is the original body
// //

View file

@ -30,9 +30,9 @@ internal class DefaultStateService @Inject constructor(private val roomId: Strin
override fun updateTopic(topic: String, callback: MatrixCallback<Unit>) { override fun updateTopic(topic: String, callback: MatrixCallback<Unit>) {
val params = SendStateTask.Params(roomId, val params = SendStateTask.Params(roomId,
EventType.STATE_ROOM_TOPIC, EventType.STATE_ROOM_TOPIC,
HashMap<String, String>().apply { mapOf(
put("topic", topic) "topic" to topic
}) ))
sendStateTask.configureWith(params) sendStateTask.configureWith(params)

View file

@ -351,7 +351,9 @@ internal class DefaultTimeline(
val initialDisplayIndex = if (isLive) { val initialDisplayIndex = if (isLive) {
liveEvents.firstOrNull()?.root?.displayIndex liveEvents.firstOrNull()?.root?.displayIndex
} else { } else {
val initialEvent = liveEvents.where().equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId).findFirst() val initialEvent = liveEvents.where()
.equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId)
.findFirst()
shouldFetchInitialEvent = initialEvent == null shouldFetchInitialEvent = initialEvent == null
initialEvent?.root?.displayIndex initialEvent?.root?.displayIndex
} ?: DISPLAY_INDEX_UNKNOWN } ?: DISPLAY_INDEX_UNKNOWN

View file

@ -40,7 +40,9 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc
val newDirectRoomIds = directMessages.content.values.flatten() val newDirectRoomIds = directMessages.content.values.flatten()
monarchy.runTransactionSync { realm -> monarchy.runTransactionSync { realm ->
val oldDirectRooms = RoomSummaryEntity.where(realm).equalTo(RoomSummaryEntityFields.IS_DIRECT, true).findAll() val oldDirectRooms = RoomSummaryEntity.where(realm)
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
.findAll()
oldDirectRooms.forEach { it.isDirect = false } oldDirectRooms.forEach { it.isDirect = false }
newDirectRoomIds.forEach { roomId -> newDirectRoomIds.forEach { roomId ->

View file

@ -120,7 +120,8 @@ object CompatUtil {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
// Get the version of Android when the key has been generated, default to the current version of the system. In this case, the // Get the version of Android when the key has been generated, default to the current version of the system. In this case, the
// key will be generated // key will be generated
val androidVersionWhenTheKeyHasBeenGenerated = sharedPreferences.getInt(SHARED_KEY_ANDROID_VERSION_WHEN_KEY_HAS_BEEN_GENERATED, Build.VERSION.SDK_INT) val androidVersionWhenTheKeyHasBeenGenerated = sharedPreferences
.getInt(SHARED_KEY_ANDROID_VERSION_WHEN_KEY_HAS_BEEN_GENERATED, Build.VERSION.SDK_INT)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (keyStore.containsAlias(AES_LOCAL_PROTECTION_KEY_ALIAS)) { if (keyStore.containsAlias(AES_LOCAL_PROTECTION_KEY_ALIAS)) {

View file

@ -65,7 +65,13 @@ echo
echo "Search for forbidden patterns in code..." echo "Search for forbidden patterns in code..."
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_code.txt \ ${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_code.txt \
./vector/src/main/java ./matrix-sdk-android/src/main/java \
./matrix-sdk-android-rx/src/main/java \
./vector/src/main/java \
./vector/src/debug/java \
./vector/src/release/java \
./vector/src/fdroid/java \
./vector/src/gplay/java
resultForbiddenStringInCode=$? resultForbiddenStringInCode=$?

View file

@ -50,7 +50,7 @@ succes[^s]
### Use int instead of Integer ### Use int instead of Integer
protected Integer protected Integer
### Use the interface declaration. Example: use type "Map" instead of type "HashMap" to declare variable or parameter ### Use the interface declaration. Example: use type "Map" instead of type "HashMap" to declare variable or parameter. For Kotlin, use mapOf, setOf, ...
(private|public|protected| ) (static )?(final )?(HashMap|HashSet|ArrayList)< (private|public|protected| ) (static )?(final )?(HashMap|HashSet|ArrayList)<
### Use int instead of short ### Use int instead of short
@ -117,11 +117,9 @@ ButterKnife\.findById\(
### Bad formatting of chain (missing new line) ### Bad formatting of chain (missing new line)
\w\.flatMap\( \w\.flatMap\(
\w\.map\(
### Bad formatting of Realm query chain. Insert new line ### Bad formatting of Realm query chain. Insert new line
\)\.equalTo \)\.equalTo
\)\.findAll
# Use StandardCharsets.UTF_8.name() # Use StandardCharsets.UTF_8.name()
# DISABLED (min API to low) # DISABLED (min API to low)

View file

@ -18,7 +18,7 @@ package im.vector.riotx.fdroid.features.settings.troubleshoot
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest
import javax.inject.Inject import javax.inject.Inject
@ -26,10 +26,11 @@ import javax.inject.Inject
* Test that the application is started on boot * Test that the application is started on boot
*/ */
class TestAutoStartBoot @Inject constructor(private val context: AppCompatActivity, class TestAutoStartBoot @Inject constructor(private val context: AppCompatActivity,
private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_service_boot_title) { private val stringProvider: StringProvider)
: TroubleshootTest(R.string.settings_troubleshoot_test_service_boot_title) {
override fun perform() { override fun perform() {
if (PreferencesManager.autoStartOnBoot(context)) { if (VectorPreferences.autoStartOnBoot(context)) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_success) description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_success)
status = TestStatus.SUCCESS status = TestStatus.SUCCESS
quickFix = null quickFix = null
@ -37,7 +38,7 @@ class TestAutoStartBoot @Inject constructor(private val context: AppCompatActivi
description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_failed) description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_failed)
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_service_boot_quickfix) { quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_service_boot_quickfix) {
override fun doFix() { override fun doFix() {
PreferencesManager.setAutoStartOnBoot(context, true) VectorPreferences.setAutoStartOnBoot(context, true)
manager?.retry() manager?.retry()
} }
} }

View file

@ -25,7 +25,8 @@ import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest
import javax.inject.Inject import javax.inject.Inject
class TestBackgroundRestrictions @Inject constructor(private val context: AppCompatActivity, class TestBackgroundRestrictions @Inject constructor(private val context: AppCompatActivity,
private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_bg_restricted_title) { private val stringProvider: StringProvider)
: TroubleshootTest(R.string.settings_troubleshoot_test_bg_restricted_title) {
override fun perform() { override fun perform() {
(context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).apply { (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).apply {

View file

@ -21,7 +21,7 @@ import android.content.Context
import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.pushers.PushersManager import im.vector.riotx.core.pushers.PushersManager
import im.vector.riotx.fdroid.receiver.AlarmSyncBroadcastReceiver import im.vector.riotx.fdroid.receiver.AlarmSyncBroadcastReceiver
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import timber.log.Timber import timber.log.Timber
/** /**
@ -65,7 +65,7 @@ object FcmHelper {
fun onEnterBackground(context: Context, activeSessionHolder: ActiveSessionHolder) { fun onEnterBackground(context: Context, activeSessionHolder: ActiveSessionHolder) {
//We need to use alarm in this mode //We need to use alarm in this mode
if (PreferencesManager.areNotificationEnabledForDevice(context) && activeSessionHolder.hasActiveSession()) { if (VectorPreferences.areNotificationEnabledForDevice(context) && activeSessionHolder.hasActiveSession()) {
val currentSession = activeSessionHolder.getActiveSession() val currentSession = activeSessionHolder.getActiveSession()
AlarmSyncBroadcastReceiver.scheduleAlarm(context, currentSession.myUserId, 4_000L) AlarmSyncBroadcastReceiver.scheduleAlarm(context, currentSession.myUserId, 4_000L)
Timber.i("Alarm scheduled to restart service") Timber.i("Alarm scheduled to restart service")

View file

@ -28,7 +28,8 @@ import javax.inject.Inject
* Check that the play services APK is available an up-to-date. If needed provide quick fix to install it. * Check that the play services APK is available an up-to-date. If needed provide quick fix to install it.
*/ */
class TestPlayServices @Inject constructor(private val context: AppCompatActivity, class TestPlayServices @Inject constructor(private val context: AppCompatActivity,
private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_play_services_title) { private val stringProvider: StringProvider)
: TroubleshootTest(R.string.settings_troubleshoot_test_play_services_title) {
override fun perform() { override fun perform() {
val apiAvailability = GoogleApiAvailability.getInstance() val apiAvailability = GoogleApiAvailability.getInstance()

View file

@ -34,7 +34,8 @@ import javax.inject.Inject
class TestTokenRegistration @Inject constructor(private val context: AppCompatActivity, class TestTokenRegistration @Inject constructor(private val context: AppCompatActivity,
private val stringProvider: StringProvider, private val stringProvider: StringProvider,
private val pushersManager: PushersManager, private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder) : TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) { private val activeSessionHolder: ActiveSessionHolder)
: TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) {
override fun perform() { override fun perform() {
//Check if we have a registered pusher for this token //Check if we have a registered pusher for this token

View file

@ -39,7 +39,7 @@ import im.vector.riotx.features.notifications.NotifiableEventResolver
import im.vector.riotx.features.notifications.NotifiableMessageEvent import im.vector.riotx.features.notifications.NotifiableMessageEvent
import im.vector.riotx.features.notifications.NotificationDrawerManager import im.vector.riotx.features.notifications.NotificationDrawerManager
import im.vector.riotx.features.notifications.SimpleNotifiableEvent import im.vector.riotx.features.notifications.SimpleNotifiableEvent
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import im.vector.riotx.push.fcm.FcmHelper import im.vector.riotx.push.fcm.FcmHelper
import timber.log.Timber import timber.log.Timber
@ -72,7 +72,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
* @param message the message * @param message the message
*/ */
override fun onMessageReceived(message: RemoteMessage?) { override fun onMessageReceived(message: RemoteMessage?) {
if (!PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { if (!VectorPreferences.areNotificationEnabledForDevice(applicationContext)) {
Timber.i("Notification are disabled for this device") Timber.i("Notification are disabled for this device")
return return
} }
@ -107,7 +107,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
if (refreshedToken == null) { if (refreshedToken == null) {
Timber.w("onNewToken:received null token") Timber.w("onNewToken:received null token")
} else { } else {
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) { if (VectorPreferences.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) {
pusherManager.registerPusherWithFcmKey(refreshedToken) pusherManager.registerPusherWithFcmKey(refreshedToken)
} }
} }

View file

@ -14,16 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.matrix.android.internal.session; package im.vector.riotx.core.di
import java.lang.annotation.Documented; import javax.inject.Scope
import java.lang.annotation.Retention;
import javax.inject.Scope;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Scope @Scope
@Documented @MustBeDocumented
@Retention(RUNTIME) @Retention(AnnotationRetention.RUNTIME)
public @interface SessionScope {} annotation class ScreenScope

View file

@ -17,12 +17,12 @@
package im.vector.riotx.core.resources package im.vector.riotx.core.resources
import android.content.Context import android.content.Context
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import javax.inject.Inject import javax.inject.Inject
class UserPreferencesProvider @Inject constructor(private val context: Context) { class UserPreferencesProvider @Inject constructor(private val context: Context) {
fun shouldShowHiddenEvents(): Boolean { fun shouldShowHiddenEvents(): Boolean {
return PreferencesManager.shouldShowHiddenEvents(context) return VectorPreferences.shouldShowHiddenEvents(context)
} }
} }

View file

@ -22,7 +22,7 @@ import android.media.RingtoneManager
import android.net.Uri import android.net.Uri
import android.preference.PreferenceManager import android.preference.PreferenceManager
import androidx.core.content.edit import androidx.core.content.edit
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
/** /**
* This file manages the sound ringtone for calls. * This file manages the sound ringtone for calls.
@ -41,7 +41,7 @@ import im.vector.riotx.features.settings.PreferencesManager
*/ */
fun getCallRingtoneUri(context: Context): Uri? { fun getCallRingtoneUri(context: Context): Uri? {
val callRingtone: String? = PreferenceManager.getDefaultSharedPreferences(context) val callRingtone: String? = PreferenceManager.getDefaultSharedPreferences(context)
.getString(PreferencesManager.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, null) .getString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, null)
callRingtone?.let { callRingtone?.let {
return Uri.parse(it) return Uri.parse(it)
@ -96,7 +96,7 @@ fun getCallRingtoneName(context: Context): String? {
fun setCallRingtoneUri(context: Context, ringtoneUri: Uri) { fun setCallRingtoneUri(context: Context, ringtoneUri: Uri) {
PreferenceManager.getDefaultSharedPreferences(context) PreferenceManager.getDefaultSharedPreferences(context)
.edit { .edit {
putString(PreferencesManager.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, ringtoneUri.toString()) putString(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY, ringtoneUri.toString())
} }
} }
@ -104,7 +104,7 @@ fun setCallRingtoneUri(context: Context, ringtoneUri: Uri) {
* Set using Riot default ringtone * Set using Riot default ringtone
*/ */
fun useRiotDefaultRingtone(context: Context): Boolean { fun useRiotDefaultRingtone(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PreferencesManager.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true) return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, true)
} }
/** /**
@ -113,7 +113,7 @@ fun useRiotDefaultRingtone(context: Context): Boolean {
fun setUseRiotDefaultRingtone(context: Context, useRiotDefault: Boolean) { fun setUseRiotDefaultRingtone(context: Context, useRiotDefault: Boolean) {
PreferenceManager.getDefaultSharedPreferences(context) PreferenceManager.getDefaultSharedPreferences(context)
.edit { .edit {
putBoolean(PreferencesManager.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault) putBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault)
} }
} }

View file

@ -98,7 +98,7 @@ import im.vector.riotx.features.media.VideoContentRenderer
import im.vector.riotx.features.media.VideoMediaViewerActivity import im.vector.riotx.features.media.VideoMediaViewerActivity
import im.vector.riotx.features.notifications.NotificationDrawerManager import im.vector.riotx.features.notifications.NotificationDrawerManager
import im.vector.riotx.features.reactions.EmojiReactionPickerActivity import im.vector.riotx.features.reactions.EmojiReactionPickerActivity
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import im.vector.riotx.features.themes.ThemeUtils import im.vector.riotx.features.themes.ThemeUtils
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.fragment_room_detail.* import kotlinx.android.synthetic.main.fragment_room_detail.*
@ -419,7 +419,7 @@ class RoomDetailFragment :
composerLayout.sendButton.setOnClickListener { composerLayout.sendButton.setOnClickListener {
val textMessage = composerLayout.composerEditText.text.toString() val textMessage = composerLayout.composerEditText.text.toString()
if (textMessage.isNotBlank()) { if (textMessage.isNotBlank()) {
roomDetailViewModel.process(RoomDetailActions.SendMessage(textMessage, PreferencesManager.isMarkdownEnabled(requireContext()))) roomDetailViewModel.process(RoomDetailActions.SendMessage(textMessage, VectorPreferences.isMarkdownEnabled(requireContext())))
} }
} }
} }
@ -440,7 +440,7 @@ class RoomDetailFragment :
items.add(DialogListItem.SendFile) items.add(DialogListItem.SendFile)
// Send voice // Send voice
if (PreferencesManager.isSendVoiceFeatureEnabled(this)) { if (VectorPreferences.isSendVoiceFeatureEnabled(this)) {
items.add(DialogListItem.SendVoice.INSTANCE) items.add(DialogListItem.SendVoice.INSTANCE)
} }
@ -449,7 +449,7 @@ class RoomDetailFragment :
//items.add(DialogListItem.SendSticker) //items.add(DialogListItem.SendSticker)
// Camera // Camera
//if (PreferencesManager.useNativeCamera(this)) { //if (VectorPreferences.useNativeCamera(this)) {
items.add(DialogListItem.TakePhoto) items.add(DialogListItem.TakePhoto)
items.add(DialogListItem.TakeVideo) items.add(DialogListItem.TakeVideo)
//} else { //} else {
@ -829,7 +829,7 @@ class RoomDetailFragment :
// vibrate = true // vibrate = true
} }
// if (vibrate && PreferencesManager.vibrateWhenMentioning(context)) { // if (vibrate && VectorPreferences.vibrateWhenMentioning(context)) {
// val v= context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator // val v= context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator
// if (v?.hasVibrator() == true) { // if (v?.hasVibrator() == true) {
// v.vibrate(100) // v.vibrate(100)

View file

@ -178,7 +178,8 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M
this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source,event.root.toContentStringWithIndent())) this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source,event.root.toContentStringWithIndent()))
if (event.isEncrypted()) { if (event.isEncrypted()) {
val decryptedContent = event.root.toClearContentStringWithIndent() ?: stringProvider.getString(R.string.encryption_information_decryption_error) val decryptedContent = event.root.toClearContentStringWithIndent()
?: stringProvider.getString(R.string.encryption_information_decryption_error)
this.add(SimpleAction(VIEW_DECRYPTED_SOURCE, R.string.view_decrypted_source, R.drawable.ic_view_source, decryptedContent)) this.add(SimpleAction(VIEW_DECRYPTED_SOURCE, R.string.view_decrypted_source, R.drawable.ic_view_source, decryptedContent))
} }
this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId)) this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId))

View file

@ -28,7 +28,7 @@ import im.vector.matrix.android.api.util.SecretStoringUtils
import im.vector.riotx.BuildConfig import im.vector.riotx.BuildConfig
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import me.gujun.android.span.span import me.gujun.android.span.span
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
@ -73,7 +73,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
Events might be grouped and there might not be one notification per event! Events might be grouped and there might not be one notification per event!
*/ */
fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
if (!PreferencesManager.areNotificationEnabledForDevice(context)) { if (!VectorPreferences.areNotificationEnabledForDevice(context)) {
Timber.i("Notification are disabled for this device") Timber.i("Notification are disabled for this device")
return return
} }

View file

@ -41,7 +41,7 @@ import im.vector.riotx.core.utils.startNotificationChannelSettingsIntent
import im.vector.riotx.features.home.HomeActivity import im.vector.riotx.features.home.HomeActivity
import im.vector.riotx.features.home.room.detail.RoomDetailActivity import im.vector.riotx.features.home.room.detail.RoomDetailActivity
import im.vector.riotx.features.home.room.detail.RoomDetailArgs import im.vector.riotx.features.home.room.detail.RoomDetailArgs
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
@ -420,7 +420,7 @@ object NotificationUtils {
priority = NotificationCompat.PRIORITY_DEFAULT priority = NotificationCompat.PRIORITY_DEFAULT
if (roomInfo.shouldBing) { if (roomInfo.shouldBing) {
//Compat //Compat
PreferencesManager.getNotificationRingTone(context)?.let { VectorPreferences.getNotificationRingTone(context)?.let {
setSound(it) setSound(it)
} }
setLights(accentColor, 500, 500) setLights(accentColor, 500, 500)
@ -534,7 +534,7 @@ object NotificationUtils {
if (simpleNotifiableEvent.noisy) { if (simpleNotifiableEvent.noisy) {
//Compat //Compat
priority = NotificationCompat.PRIORITY_DEFAULT priority = NotificationCompat.PRIORITY_DEFAULT
PreferencesManager.getNotificationRingTone(context)?.let { VectorPreferences.getNotificationRingTone(context)?.let {
setSound(it) setSound(it)
} }
setLights(accentColor, 500, 500) setLights(accentColor, 500, 500)
@ -630,7 +630,7 @@ object NotificationUtils {
if (noisy) { if (noisy) {
//Compat //Compat
priority = NotificationCompat.PRIORITY_DEFAULT priority = NotificationCompat.PRIORITY_DEFAULT
PreferencesManager.getNotificationRingTone(context)?.let { VectorPreferences.getNotificationRingTone(context)?.let {
setSound(it) setSound(it)
} }
setLights(accentColor, 500, 500) setLights(accentColor, 500, 500)

View file

@ -1,879 +0,0 @@
/*
* Copyright 2016 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotx.features.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.MediaStore;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import im.vector.riotx.R;
import im.vector.riotx.features.homeserver.ServerUrlsRepository;
import im.vector.riotx.features.themes.ThemeUtils;
import timber.log.Timber;
public class PreferencesManager {
public static final String SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2";
public static final String SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY";
public static final String SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY";
public static final String SETTINGS_SDK_VERSION_PREFERENCE_KEY = "SETTINGS_SDK_VERSION_PREFERENCE_KEY";
public static final String SETTINGS_OLM_VERSION_PREFERENCE_KEY = "SETTINGS_OLM_VERSION_PREFERENCE_KEY";
public static final String SETTINGS_LOGGED_IN_PREFERENCE_KEY = "SETTINGS_LOGGED_IN_PREFERENCE_KEY";
public static final String SETTINGS_HOME_SERVER_PREFERENCE_KEY = "SETTINGS_HOME_SERVER_PREFERENCE_KEY";
public static final String SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY = "SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY";
public static final String SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY = "SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY";
public static final String SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY = "SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY";
public static final String SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY";
public static final String SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY";
public static final String SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY";
public static final String SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY";
public static final String SETTINGS_COPYRIGHT_PREFERENCE_KEY = "SETTINGS_COPYRIGHT_PREFERENCE_KEY";
public static final String SETTINGS_CLEAR_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_CACHE_PREFERENCE_KEY";
public static final String SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY = "SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY";
public static final String SETTINGS_USER_SETTINGS_PREFERENCE_KEY = "SETTINGS_USER_SETTINGS_PREFERENCE_KEY";
public static final String SETTINGS_CONTACT_PREFERENCE_KEYS = "SETTINGS_CONTACT_PREFERENCE_KEYS";
public static final String SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY";
public static final String SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY = "SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_IGNORED_USERS_PREFERENCE_KEY = "SETTINGS_IGNORED_USERS_PREFERENCE_KEY";
public static final String SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY = "SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY";
public static final String SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_LABS_PREFERENCE_KEY = "SETTINGS_LABS_PREFERENCE_KEY";
public static final String SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY";
public static final String SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY";
public static final String SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_DEVICES_LIST_PREFERENCE_KEY";
public static final String SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY = "SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY";
public static final String SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY = "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY";
public static final String SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY
= "SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY";
public static final String SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY";
public static final String SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY";
// user
public static final String SETTINGS_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_DISPLAY_NAME_PREFERENCE_KEY";
public static final String SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY = "SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY";
// contacts
public static final String SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY = "SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY";
// interface
public static final String SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY = "SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY";
public static final String SETTINGS_INTERFACE_TEXT_SIZE_KEY = "SETTINGS_INTERFACE_TEXT_SIZE_KEY";
public static final String SETTINGS_SHOW_URL_PREVIEW_KEY = "SETTINGS_SHOW_URL_PREVIEW_KEY";
private static final String SETTINGS_SEND_TYPING_NOTIF_KEY = "SETTINGS_SEND_TYPING_NOTIF_KEY";
private static final String SETTINGS_ENABLE_MARKDOWN_KEY = "SETTINGS_ENABLE_MARKDOWN_KEY";
private static final String SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY = "SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY";
private static final String SETTINGS_12_24_TIMESTAMPS_KEY = "SETTINGS_12_24_TIMESTAMPS_KEY";
private static final String SETTINGS_SHOW_READ_RECEIPTS_KEY = "SETTINGS_SHOW_READ_RECEIPTS_KEY";
private static final String SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY = "SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY";
private static final String SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY = "SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY";
private static final String SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY";
private static final String SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER";
// home
private static final String SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY = "SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY";
private static final String SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY = "SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY";
// flair
public static final String SETTINGS_GROUPS_FLAIR_KEY = "SETTINGS_GROUPS_FLAIR_KEY";
// notifications
public static final String SETTINGS_NOTIFICATIONS_KEY = "SETTINGS_NOTIFICATIONS_KEY";
public static final String SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY = "SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY";
public static final String 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";
public static final String SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY";
public static final String SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY";
public static final String SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY";
public static final String SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY";
public static final String SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY";
public static final String SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY_2";
public static final String SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY = "SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY_2";
public static final String SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY_2";
public static final String SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY = "SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY_2";
public static final String SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY = "SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY_2";
public static final String SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY = "SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY_2";
// media
private static final String SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY = "SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY";
private static final String SETTINGS_DEFAULT_MEDIA_SOURCE_KEY = "SETTINGS_DEFAULT_MEDIA_SOURCE_KEY";
private static final String SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY = "SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY";
private static final String SETTINGS_PLAY_SHUTTER_SOUND_KEY = "SETTINGS_PLAY_SHUTTER_SOUND_KEY";
// background sync
public static final String SETTINGS_START_ON_BOOT_PREFERENCE_KEY = "SETTINGS_START_ON_BOOT_PREFERENCE_KEY";
public static final String SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY = "SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY";
public static final String SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY = "SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY";
public static final String SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY = "SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY";
// Calls
public static final String SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY";
public static final String SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY";
// labs
public static final String SETTINGS_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_LAZY_LOADING_PREFERENCE_KEY";
public static final String SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY = "SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY";
public static final String SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY = "SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY";
private static final String SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY = "SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY";
private static final String SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY = "SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY";
private static final String SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY = "SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY";
private static final String SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY";
// analytics
public static final String SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY";
public static final String SETTINGS_USE_RAGE_SHAKE_KEY = "SETTINGS_USE_RAGE_SHAKE_KEY";
// other
public static final String SETTINGS_MEDIA_SAVING_PERIOD_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_KEY";
private static final String SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY";
private static final String DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY = "DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY";
private static final String DID_MIGRATE_TO_NOTIFICATION_REWORK = "DID_MIGRATE_TO_NOTIFICATION_REWORK";
private static final String DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY = "DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY";
public static final String SETTINGS_DEACTIVATE_ACCOUNT_KEY = "SETTINGS_DEACTIVATE_ACCOUNT_KEY";
private static final String SETTINGS_DISPLAY_ALL_EVENTS_KEY = "SETTINGS_DISPLAY_ALL_EVENTS_KEY";
private static final int MEDIA_SAVING_3_DAYS = 0;
private static final int MEDIA_SAVING_1_WEEK = 1;
private static final int MEDIA_SAVING_1_MONTH = 2;
private static final int MEDIA_SAVING_FOREVER = 3;
// some preferences keys must be kept after a logout
private static final List<String> 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_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_USE_RAGE_SHAKE_KEY
);
/**
* Clear the preferences.
*
* @param context the context
*/
public static void clearPreferences(Context context) {
Set<String> keysToKeep = new HashSet<>(mKeysToKeepAfterLogout);
// home server urls
keysToKeep.add(ServerUrlsRepository.HOME_SERVER_URL_PREF);
keysToKeep.add(ServerUrlsRepository.IDENTITY_SERVER_URL_PREF);
// theme
keysToKeep.add(ThemeUtils.APPLICATION_THEME_KEY);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
// get all the existing keys
Set<String> keys = preferences.getAll().keySet();
// remove the one to keep
keys.removeAll(keysToKeep);
for (String key : keys) {
editor.remove(key);
}
editor.apply();
}
public static boolean areNotificationEnabledForDevice(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, true);
}
public static void setNotificationEnabledForDevice(Context context, Boolean enabled) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, enabled)
.apply();
}
public static boolean shouldShowHiddenEvents(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY, false);
}
/**
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
*
* @param context the context
* @return true if it was already requested
*/
public static boolean didAskUserToIgnoreBatteryOptimizations(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, false);
}
/**
* Mark as requested the question to disable battery optimisations.
*
* @param context the context
*/
public static void setDidAskUserToIgnoreBatteryOptimizations(Context context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(DID_ASK_TO_IGNORE_BATTERY_OPTIMIZATIONS_KEY, true)
.apply();
}
public static boolean didMigrateToNotificationRework(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, false);
}
public static void setDidMigrateToNotificationRework(Context context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, true)
.apply();
}
/**
* Tells if the timestamp must be displayed in 12h format
*
* @param context the context
* @return true if the time must be displayed in 12h format
*/
public static boolean displayTimeIn12hFormat(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_12_24_TIMESTAMPS_KEY, false);
}
/**
* Tells if the join and leave membership events should be shown in the messages list.
*
* @param context the context
* @return true if the join and leave membership events should be shown in the messages list
*/
public static boolean showJoinLeaveMessages(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, true);
}
/**
* Tells if the avatar and display name events should be shown in the messages list.
*
* @param context the context
* @return true true if the avatar and display name events should be shown in the messages list.
*/
public static boolean showAvatarDisplayNameChangeMessages(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY, true);
}
/**
* Tells the native camera to take a photo or record a video.
*
* @param context the context
* @return true to use the native camera app to record video or take photo.
*/
public static boolean useNativeCamera(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_NATIVE_CAMERA_PREFERENCE_KEY, false);
}
/**
* Tells if the send voice feature is enabled.
*
* @param context the context
* @return true if the send voice feature is enabled.
*/
public static boolean isSendVoiceFeatureEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY, false);
}
/**
* Tells which compression level to use by default
*
* @param context the context
* @return the selected compression level
*/
public static int getSelectedDefaultMediaCompressionLevel(Context context) {
return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_DEFAULT_MEDIA_COMPRESSION_KEY, "0"));
}
/**
* Tells which media source to use by default
*
* @param context the context
* @return the selected media source
*/
public static int getSelectedDefaultMediaSource(Context context) {
return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_DEFAULT_MEDIA_SOURCE_KEY, "0"));
}
/**
* Tells whether to use shutter sound.
*
* @param context the context
* @return true if shutter sound should play
*/
public static boolean useShutterSound(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PLAY_SHUTTER_SOUND_KEY, true);
}
/**
* Update the notification ringtone
*
* @param context the context
* @param uri the new notification ringtone, or null for no RingTone
*/
public static void setNotificationRingTone(Context context, @Nullable Uri uri) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
String value = "";
if (null != uri) {
value = uri.toString();
if (value.startsWith("file://")) {
// it should never happen
// else android.os.FileUriExposedException will be triggered.
// see https://github.com/vector-im/riot-android/issues/1725
return;
}
}
editor.putString(SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, value);
editor.apply();
}
/**
* Provides the selected notification ring tone
*
* @param context the context
* @return the selected ring tone or null for no RingTone
*/
@Nullable
public static Uri getNotificationRingTone(Context context) {
String url = PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, null);
// the user selects "None"
if (TextUtils.equals(url, "")) {
return null;
}
Uri uri = null;
// https://github.com/vector-im/riot-android/issues/1725
if ((null != url) && !url.startsWith("file://")) {
try {
uri = Uri.parse(url);
} catch (Exception e) {
Timber.e(e, "## getNotificationRingTone() : Uri.parse failed");
}
}
if (null == uri) {
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Timber.v("## getNotificationRingTone() returns " + uri);
return uri;
}
/**
* Provide the notification ringtone filename
*
* @param context the context
* @return the filename or null if "None" is selected
*/
@Nullable
public static String getNotificationRingToneName(Context context) {
Uri toneUri = getNotificationRingTone(context);
if (null == toneUri) {
return null;
}
String name = null;
Cursor cursor = null;
try {
String[] proj = {MediaStore.Audio.Media.DATA};
cursor = context.getContentResolver().query(toneUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
File file = new File(cursor.getString(column_index));
name = file.getName();
if (name.contains(".")) {
name = name.substring(0, name.lastIndexOf("."));
}
} catch (Exception e) {
Timber.e(e, "## getNotificationRingToneName() failed() : " + e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
}
}
return name;
}
/**
* Enable or disable the lazy loading
*
* @param context the context
* @param newValue true to enable lazy loading, false to disable it
*/
public static void setUseLazyLoading(Context context, boolean newValue) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, newValue)
.apply();
}
/**
* Tells if the lazy loading is enabled
*
* @param context the context
* @return true if the lazy loading of room members is enabled
*/
public static boolean useLazyLoading(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LAZY_LOADING_PREFERENCE_KEY, false);
}
/**
* User explicitly refuses the lazy loading.
*
* @param context the context
*/
public static void setUserRefuseLazyLoading(Context context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, true)
.apply();
}
/**
* Tells if the user has explicitly refused the lazy loading
*
* @param context the context
* @return true if the user has explicitly refuse the lazy loading of room members
*/
public static boolean hasUserRefusedLazyLoading(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, false);
}
/**
* Tells if the data save mode is enabled
*
* @param context the context
* @return true if the data save mode is enabled
*/
public static boolean useDataSaveMode(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY, false);
}
/**
* Tells if the conf calls must be done with Jitsi.
*
* @param context the context
* @return true if the conference call must be done with jitsi.
*/
public static boolean useJitsiConfCall(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_JITSI_CONF_PREFERENCE_KEY, true);
}
/**
* Tells if the application is started on boot
*
* @param context the context
* @return true if the application must be started on boot
*/
public static boolean autoStartOnBoot(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, true);
}
/**
* Tells if the application is started on boot
*
* @param context the context
* @param value true to start the application on boot
*/
public static void setAutoStartOnBoot(Context context, boolean value) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_START_ON_BOOT_PREFERENCE_KEY, value)
.apply();
}
/**
* Provides the selected saving period.
*
* @param context the context
* @return the selected period
*/
public static int getSelectedMediasSavingPeriod(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, MEDIA_SAVING_1_WEEK);
}
/**
* Updates the selected saving period.
*
* @param context the context
* @param index the selected period index
*/
public static void setSelectedMediasSavingPeriod(Context context, int index) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putInt(SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY, index)
.apply();
}
/**
* Provides the minimum last access time to keep a media file.
*
* @param context the context
* @return the min last access time (in seconds)
*/
public static long getMinMediasLastAccessTime(Context context) {
int selection = getSelectedMediasSavingPeriod(context);
switch (selection) {
case MEDIA_SAVING_3_DAYS:
return (System.currentTimeMillis() / 1000) - (3 * 24 * 60 * 60);
case MEDIA_SAVING_1_WEEK:
return (System.currentTimeMillis() / 1000) - (7 * 24 * 60 * 60);
case MEDIA_SAVING_1_MONTH:
return (System.currentTimeMillis() / 1000) - (30 * 24 * 60 * 60);
case MEDIA_SAVING_FOREVER:
return 0;
}
return 0;
}
/**
* Provides the selected saving period.
*
* @param context the context
* @return the selected period
*/
public static String getSelectedMediasSavingPeriodString(Context context) {
int selection = getSelectedMediasSavingPeriod(context);
switch (selection) {
case MEDIA_SAVING_3_DAYS:
return context.getString(R.string.media_saving_period_3_days);
case MEDIA_SAVING_1_WEEK:
return context.getString(R.string.media_saving_period_1_week);
case MEDIA_SAVING_1_MONTH:
return context.getString(R.string.media_saving_period_1_month);
case MEDIA_SAVING_FOREVER:
return context.getString(R.string.media_saving_period_forever);
}
return "?";
}
/**
* Fix some migration issues
*/
public static void fixMigrationIssues(Context context) {
// some key names have been updated to supported language switch
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.contains(context.getString(R.string.settings_pin_missed_notifications))) {
preferences.edit()
.putBoolean(SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY,
preferences.getBoolean(context.getString(R.string.settings_pin_missed_notifications), false))
.remove(context.getString(R.string.settings_pin_missed_notifications))
.apply();
}
if (preferences.contains(context.getString(R.string.settings_pin_unread_messages))) {
preferences.edit()
.putBoolean(SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY,
preferences.getBoolean(context.getString(R.string.settings_pin_unread_messages), false))
.remove(context.getString(R.string.settings_pin_unread_messages))
.apply();
}
if (preferences.contains("MARKDOWN_PREFERENCE_KEY")) {
preferences.edit()
.putBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, preferences.getBoolean("MARKDOWN_PREFERENCE_KEY", true))
.remove("MARKDOWN_PREFERENCE_KEY")
.apply();
}
if (preferences.contains("SETTINGS_DONT_SEND_TYPING_NOTIF_KEY")) {
preferences.edit()
.putBoolean(SETTINGS_SEND_TYPING_NOTIF_KEY, !preferences.getBoolean("SETTINGS_DONT_SEND_TYPING_NOTIF_KEY", true))
.remove("SETTINGS_DONT_SEND_TYPING_NOTIF_KEY")
.apply();
}
if (preferences.contains("SETTINGS_DISABLE_MARKDOWN_KEY")) {
preferences.edit()
.putBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, !preferences.getBoolean("SETTINGS_DISABLE_MARKDOWN_KEY", true))
.remove("SETTINGS_DISABLE_MARKDOWN_KEY")
.apply();
}
if (preferences.contains("SETTINGS_HIDE_READ_RECEIPTS")) {
preferences.edit()
.putBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, !preferences.getBoolean("SETTINGS_HIDE_READ_RECEIPTS", true))
.remove("SETTINGS_HIDE_READ_RECEIPTS")
.apply();
}
if (preferences.contains("SETTINGS_HIDE_JOIN_LEAVE_MESSAGES_KEY")) {
preferences.edit()
.putBoolean(SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY, !preferences.getBoolean("SETTINGS_HIDE_JOIN_LEAVE_MESSAGES_KEY", true))
.remove("SETTINGS_HIDE_JOIN_LEAVE_MESSAGES_KEY")
.apply();
}
if (preferences.contains("SETTINGS_HIDE_AVATAR_DISPLAY_NAME_CHANGES")) {
preferences.edit()
.putBoolean(SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY,
!preferences.getBoolean("SETTINGS_HIDE_AVATAR_DISPLAY_NAME_CHANGES", true))
.remove("SETTINGS_HIDE_AVATAR_DISPLAY_NAME_CHANGES")
.apply();
}
}
/**
* Tells if the markdown is enabled
*
* @param context the context
* @return true if the markdown is enabled
*/
public static boolean isMarkdownEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, true);
}
/**
* Update the markdown enable status.
*
* @param context the context
* @param isEnabled true to enable the markdown
*/
public static void setMarkdownEnabled(Context context, boolean isEnabled) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, isEnabled)
.apply();
}
/**
* Tells if the read receipts should be shown
*
* @param context the context
* @return true if the read receipts should be shown
*/
public static boolean showReadReceipts(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, true);
}
/**
* Tells if the message timestamps must be always shown
*
* @param context the context
* @return true if the message timestamps must be always shown
*/
public static boolean alwaysShowTimeStamps(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, false);
}
/**
* Tells if the typing notifications should be sent
*
* @param context the context
* @return true to send the typing notifs
*/
public static boolean sendTypingNotifs(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SEND_TYPING_NOTIF_KEY, true);
}
/**
* Tells of the missing notifications rooms must be displayed at left (home screen)
*
* @param context the context
* @return true to move the missed notifications to the left side
*/
public static boolean pinMissedNotifications(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY, true);
}
/**
* Tells of the unread rooms must be displayed at left (home screen)
*
* @param context the context
* @return true to move the unread room to the left side
*/
public static boolean pinUnreadMessages(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY, true);
}
/**
* Tells if the phone must vibrate when mentioning
*
* @param context the context
* @return true
*/
public static boolean vibrateWhenMentioning(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_VIBRATE_ON_MENTION_KEY, false);
}
/**
* Tells if a dialog has been displayed to ask to use the analytics tracking (piwik, matomo, etc.).
*
* @param context the context
* @return true if a dialog has been displayed to ask to use the analytics tracking
*/
public static boolean didAskToUseAnalytics(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, false);
}
/**
* To call if the user has been asked for analytics tracking.
*
* @param context the context
*/
public static void setDidAskToUseAnalytics(Context context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, true)
.apply();
}
/**
* Tells if the analytics tracking is authorized (piwik, matomo, etc.).
*
* @param context the context
* @return true if the analytics tracking is authorized
*/
public static boolean useAnalytics(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_ANALYTICS_KEY, false);
}
/**
* Enable or disable the analytics tracking.
*
* @param context the context
* @param useAnalytics true to enable the analytics tracking
*/
public static void setUseAnalytics(Context context, boolean useAnalytics) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_USE_ANALYTICS_KEY, useAnalytics)
.apply();
}
/**
* Tells if media should be previewed before sending
*
* @param context the context
* @return true to preview media
*/
public static boolean previewMediaWhenSending(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_PREVIEW_MEDIA_BEFORE_SENDING_KEY, false);
}
/**
* Tells if message should be send by pressing enter on the soft keyboard
*
* @param context the context
* @return true to send message with enter
*/
public static boolean sendMessageWithEnter(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_SEND_MESSAGE_WITH_ENTER, false);
}
/**
* Tells if the rage shake is used.
*
* @param context the context
* @return true if the rage shake is used
*/
public static boolean useRageshake(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, true);
}
/**
* Update the rage shake status.
*
* @param context the context
* @param isEnabled true to enable the rage shake
*/
public static void setUseRageshake(Context context, boolean isEnabled) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, isEnabled)
.apply();
}
/**
* Tells if all the events must be displayed ie even the redacted events.
*
* @param context the context
* @return true to display all the events even the redacted ones.
*/
public static boolean displayAllEvents(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_DISPLAY_ALL_EVENTS_KEY, false);
}
}

View file

@ -0,0 +1,794 @@
/*
* Copyright 2016 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotx.features.settings
import android.content.Context
import android.database.Cursor
import android.media.RingtoneManager
import android.net.Uri
import android.provider.MediaStore
import android.text.TextUtils
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import im.vector.riotx.R
import im.vector.riotx.features.homeserver.ServerUrlsRepository
import im.vector.riotx.features.themes.ThemeUtils
import timber.log.Timber
import java.io.File
import java.util.*
object VectorPreferences {
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_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"
// 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"
// 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"
// 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"
// 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"
// 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"
// 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"
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,
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_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
)
/**
* Clear the preferences.
*
* @param context the context
*/
fun clearPreferences(context: Context) {
val keysToKeep = HashSet(mKeysToKeepAfterLogout)
// home server urls
keysToKeep.add(ServerUrlsRepository.HOME_SERVER_URL_PREF)
keysToKeep.add(ServerUrlsRepository.IDENTITY_SERVER_URL_PREF)
// 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
keys.removeAll(keysToKeep)
for (key in keys) {
remove(key)
}
}
}
fun areNotificationEnabledForDevice(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).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 shouldShowHiddenEvents(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY, false)
}
/**
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
*
* @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)
}
/**
* Mark as requested the question to disable battery optimisations.
*
* @param context the context
*/
fun setDidAskUserToIgnoreBatteryOptimizations(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context)
.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 setDidMigrateToNotificationRework(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit {
putBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, true)
}
}
/**
* Tells if the timestamp must be displayed in 12h format
*
* @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)
}
/**
* Tells if the join and leave membership events should be shown in the messages list.
*
* @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)
}
/**
* Tells if the avatar and display name events should be shown in the messages list.
*
* @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)
}
/**
* Tells the native camera to take a photo or record a video.
*
* @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)
}
/**
* Tells if the send voice feature is enabled.
*
* @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)
}
/**
* Tells which compression level to use by default
*
* @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")!!)
}
/**
* Tells which media source to use by default
*
* @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")!!)
}
/**
* Tells whether to use shutter sound.
*
* @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)
}
/**
* Update the notification ringtone
*
* @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 {
var value = ""
if (null != uri) {
value = uri.toString()
if (value.startsWith("file://")) {
// it should never happen
// else android.os.FileUriExposedException will be triggered.
// see https://github.com/vector-im/riot-android/issues/1725
return
}
}
putString(SETTINGS_NOTIFICATION_RINGTONE_PREFERENCE_KEY, value)
}
}
/**
* Provides the selected notification ring tone
*
* @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)
// the user selects "None"
if (TextUtils.equals(url, "")) {
return null
}
var uri: Uri? = null
// https://github.com/vector-im/riot-android/issues/1725
if (null != url && !url.startsWith("file://")) {
try {
uri = Uri.parse(url)
} catch (e: Exception) {
Timber.e(e, "## getNotificationRingTone() : Uri.parse failed")
}
}
if (null == uri) {
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
}
Timber.v("## getNotificationRingTone() returns " + uri!!)
return uri
}
/**
* Provide the notification ringtone filename
*
* @param context the context
* @return the filename or null if "None" is selected
*/
fun getNotificationRingToneName(context: Context): String? {
val toneUri = getNotificationRingTone(context) ?: return null
var name: String? = null
var cursor: Cursor? = null
try {
val proj = arrayOf(MediaStore.Audio.Media.DATA)
cursor = context.contentResolver.query(toneUri, proj, null, null, null)
val column_index = cursor!!.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)
cursor.moveToFirst()
val file = File(cursor.getString(column_index))
name = file.name
if (name!!.contains(".")) {
name = name.substring(0, name.lastIndexOf("."))
}
} catch (e: Exception) {
Timber.e(e, "## getNotificationRingToneName() failed() : " + e.message)
} finally {
cursor?.close()
}
return name
}
/**
* Enable or disable the lazy loading
*
* @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)
}
}
/**
* Tells if the lazy loading is enabled
*
* @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)
}
/**
* User explicitly refuses the lazy loading.
*
* @param context the context
*/
fun setUserRefuseLazyLoading(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit {
putBoolean(SETTINGS_USER_REFUSED_LAZY_LOADING_PREFERENCE_KEY, true)
}
}
/**
* Tells if the user has explicitly refused the lazy loading
*
* @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)
}
/**
* Tells if the data save mode is enabled
*
* @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)
}
/**
* Tells if the conf calls must be done with Jitsi.
*
* @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)
}
/**
* Tells if the application is started on boot
*
* @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)
}
/**
* Tells if the application is started on boot
*
* @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)
}
}
/**
* Provides the selected saving period.
*
* @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)
}
/**
* Updates the selected saving period.
*
* @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)
}
}
/**
* Provides the minimum last access time to keep a media file.
*
* @param context the context
* @return the min last access time (in seconds)
*/
fun getMinMediasLastAccessTime(context: Context): Long {
val selection = getSelectedMediasSavingPeriod(context)
when (selection) {
MEDIA_SAVING_3_DAYS -> return System.currentTimeMillis() / 1000 - 3 * 24 * 60 * 60
MEDIA_SAVING_1_WEEK -> return System.currentTimeMillis() / 1000 - 7 * 24 * 60 * 60
MEDIA_SAVING_1_MONTH -> return System.currentTimeMillis() / 1000 - 30 * 24 * 60 * 60
MEDIA_SAVING_FOREVER -> return 0
}
return 0
}
/**
* Provides the selected saving period.
*
* @param context the context
* @return the selected period
*/
fun getSelectedMediasSavingPeriodString(context: Context): String {
val selection = getSelectedMediasSavingPeriod(context)
when (selection) {
MEDIA_SAVING_3_DAYS -> return context.getString(R.string.media_saving_period_3_days)
MEDIA_SAVING_1_WEEK -> return context.getString(R.string.media_saving_period_1_week)
MEDIA_SAVING_1_MONTH -> return context.getString(R.string.media_saving_period_1_month)
MEDIA_SAVING_FOREVER -> return context.getString(R.string.media_saving_period_forever)
}
return "?"
}
/**
* Fix some migration issues
*/
fun fixMigrationIssues(context: Context) {
// Nothing to do for the moment
}
/**
* Tells if the markdown is enabled
*
* @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)
}
/**
* Update the markdown enable status.
*
* @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)
}
}
/**
* Tells if the read receipts should be shown
*
* @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)
}
/**
* Tells if the message timestamps must be always shown
*
* @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)
}
/**
* Tells if the typing notifications should be sent
*
* @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)
}
/**
* Tells of the missing notifications rooms must be displayed at left (home screen)
*
* @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)
}
/**
* Tells of the unread rooms must be displayed at left (home screen)
*
* @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)
}
/**
* Tells if the phone must vibrate when mentioning
*
* @param context the context
* @return true
*/
fun vibrateWhenMentioning(context: Context): Boolean {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_VIBRATE_ON_MENTION_KEY, false)
}
/**
* Tells if a dialog has been displayed to ask to use the analytics tracking (piwik, matomo, etc.).
*
* @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)
}
/**
* To call if the user has been asked for analytics tracking.
*
* @param context the context
*/
fun setDidAskToUseAnalytics(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit {
putBoolean(DID_ASK_TO_USE_ANALYTICS_TRACKING_KEY, true)
}
}
/**
* Tells if the analytics tracking is authorized (piwik, matomo, etc.).
*
* @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)
}
/**
* Enable or disable the analytics tracking.
*
* @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)
}
}
/**
* Tells if media should be previewed before sending
*
* @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)
}
/**
* Tells if message should be send by pressing enter on the soft keyboard
*
* @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)
}
/**
* Tells if the rage shake is used.
*
* @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)
}
/**
* Update the rage shake status.
*
* @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)
}
}
/**
* Tells if all the events must be displayed ie even the redacted events.
*
* @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)
}
}

View file

@ -78,9 +78,9 @@ class VectorSettingsActivity : VectorBaseActivity(),
override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat?, pref: Preference?): Boolean { override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat?, pref: Preference?): Boolean {
var oFragment: Fragment? = null var oFragment: Fragment? = null
if (PreferencesManager.SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY == pref?.key) { if (VectorPreferences.SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY == pref?.key) {
oFragment = VectorSettingsNotificationsTroubleshootFragment.newInstance(session.sessionParams.credentials.userId) oFragment = VectorSettingsNotificationsTroubleshootFragment.newInstance(session.sessionParams.credentials.userId)
} else if (PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY == pref?.key) { } else if (VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY == pref?.key) {
oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.sessionParams.credentials.userId) oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.sessionParams.credentials.userId)
} else { } else {
try { try {

View file

@ -46,7 +46,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences
override fun bindPref() { override fun bindPref() {
val callNotificationsSystemOptions = findPreference(PreferencesManager.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY) val callNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY)
if (supportNotificationChannels()) { if (supportNotificationChannels()) {
callNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { callNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener {
NotificationUtils.openSystemSettingsForCallCategory(this) NotificationUtils.openSystemSettingsForCallCategory(this)
@ -56,7 +56,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
callNotificationsSystemOptions.isVisible = false callNotificationsSystemOptions.isVisible = false
} }
val noisyNotificationsSystemOptions = findPreference(PreferencesManager.SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY) val noisyNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY)
if (supportNotificationChannels()) { if (supportNotificationChannels()) {
noisyNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { noisyNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener {
NotificationUtils.openSystemSettingsForNoisyCategory(this) NotificationUtils.openSystemSettingsForNoisyCategory(this)
@ -66,7 +66,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
noisyNotificationsSystemOptions.isVisible = false noisyNotificationsSystemOptions.isVisible = false
} }
val silentNotificationsSystemOptions = findPreference(PreferencesManager.SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY) val silentNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY)
if (supportNotificationChannels()) { if (supportNotificationChannels()) {
silentNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { silentNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener {
NotificationUtils.openSystemSettingsForSilentCategory(this) NotificationUtils.openSystemSettingsForSilentCategory(this)
@ -78,18 +78,18 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
// Ringtone // Ringtone
val ringtonePreference = findPreference(PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY) val ringtonePreference = findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)
if (supportNotificationChannels()) { if (supportNotificationChannels()) {
ringtonePreference.isVisible = false ringtonePreference.isVisible = false
} else { } else {
ringtonePreference.summary = PreferencesManager.getNotificationRingToneName(activity) ringtonePreference.summary = VectorPreferences.getNotificationRingToneName(requireContext())
ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
if (null != PreferencesManager.getNotificationRingTone(activity)) { if (null != VectorPreferences.getNotificationRingTone(requireContext())) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, PreferencesManager.getNotificationRingTone(activity)) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, VectorPreferences.getNotificationRingTone(requireContext()))
} }
startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE) startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE)
@ -152,14 +152,14 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
when (requestCode) { when (requestCode) {
REQUEST_NOTIFICATION_RINGTONE -> { REQUEST_NOTIFICATION_RINGTONE -> {
PreferencesManager.setNotificationRingTone(activity, VectorPreferences.setNotificationRingTone(requireContext(),
data?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) data?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?)
// test if the selected ring tone can be played // test if the selected ring tone can be played
val notificationRingToneName = PreferencesManager.getNotificationRingToneName(activity) val notificationRingToneName = VectorPreferences.getNotificationRingToneName(requireContext())
if (null != notificationRingToneName) { if (null != notificationRingToneName) {
PreferencesManager.setNotificationRingTone(activity, PreferencesManager.getNotificationRingTone(activity)) VectorPreferences.setNotificationRingTone(requireContext(), VectorPreferences.getNotificationRingTone(requireContext()))
findPreference(PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY).summary = notificationRingToneName findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY).summary = notificationRingToneName
} }
} }
} }
@ -217,13 +217,13 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF
// preference name <-> rule Id // preference name <-> rule Id
private var mPrefKeyToBingRuleId = mapOf( private var mPrefKeyToBingRuleId = mapOf(
PreferencesManager.SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_DISPLAY_NAME, VectorPreferences.SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_DISPLAY_NAME,
PreferencesManager.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_USER_NAME, VectorPreferences.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_USER_NAME,
PreferencesManager.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY to BingRule.RULE_ID_ONE_TO_ONE_ROOM, VectorPreferences.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY to BingRule.RULE_ID_ONE_TO_ONE_ROOM,
PreferencesManager.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY to BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS, VectorPreferences.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY to BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
PreferencesManager.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY to BingRule.RULE_ID_INVITE_ME, VectorPreferences.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY to BingRule.RULE_ID_INVITE_ME,
PreferencesManager.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY to BingRule.RULE_ID_CALL, VectorPreferences.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY to BingRule.RULE_ID_CALL,
PreferencesManager.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY to BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS VectorPreferences.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY to BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS
) )
fun newInstance(matrixId: String) = VectorSettingsAdvancedNotificationPreferenceFragment() fun newInstance(matrixId: String) = VectorSettingsAdvancedNotificationPreferenceFragment()

View file

@ -30,7 +30,7 @@ class VectorSettingsFlairFragment : VectorSettingsBaseFragment() {
// Group Flairs // Group Flairs
private val mGroupsFlairCategory by lazy { private val mGroupsFlairCategory by lazy {
findPreference(PreferencesManager.SETTINGS_GROUPS_FLAIR_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_GROUPS_FLAIR_KEY) as PreferenceCategory
} }
override fun bindPref() { override fun bindPref() {

View file

@ -61,25 +61,25 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
private var mDisplayedPhoneNumber = ArrayList<String>() private var mDisplayedPhoneNumber = ArrayList<String>()
private val mUserSettingsCategory by lazy { private val mUserSettingsCategory by lazy {
findPreference(PreferencesManager.SETTINGS_USER_SETTINGS_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_USER_SETTINGS_PREFERENCE_KEY) as PreferenceCategory
} }
private val mUserAvatarPreference by lazy { private val mUserAvatarPreference by lazy {
findPreference(PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY) as UserAvatarPreference findPreference(VectorPreferences.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY) as UserAvatarPreference
} }
private val mDisplayNamePreference by lazy { private val mDisplayNamePreference by lazy {
findPreference(PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY) as EditTextPreference findPreference(VectorPreferences.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY) as EditTextPreference
} }
private val mPasswordPreference by lazy { private val mPasswordPreference by lazy {
findPreference(PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY)
} }
// Local contacts // Local contacts
private val mContactSettingsCategory by lazy { private val mContactSettingsCategory by lazy {
findPreference(PreferencesManager.SETTINGS_CONTACT_PREFERENCE_KEYS) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_CONTACT_PREFERENCE_KEYS) as PreferenceCategory
} }
private val mContactPhonebookCountryPreference by lazy { private val mContactPhonebookCountryPreference by lazy {
findPreference(PreferencesManager.SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY)
} }
@ -147,15 +147,15 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
// Advanced settings // Advanced settings
// user account // user account
findPreference(PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_LOGGED_IN_PREFERENCE_KEY)
.summary = session.sessionParams.credentials.userId .summary = session.sessionParams.credentials.userId
// home server // home server
findPreference(PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY)
.summary = session.sessionParams.homeServerConnectionConfig.homeServerUri.toString() .summary = session.sessionParams.homeServerConnectionConfig.homeServerUri.toString()
// identity server // identity server
findPreference(PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY)
.summary = session.sessionParams.homeServerConnectionConfig.identityServerUri.toString() .summary = session.sessionParams.homeServerConnectionConfig.identityServerUri.toString()
@ -165,7 +165,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
setContactsPreferences() setContactsPreferences()
// clear cache // clear cache
findPreference(PreferencesManager.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY).let { findPreference(VectorPreferences.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY).let {
/* /*
TODO TODO
MXSession.getApplicationSizeCaches(activity, object : SimpleApiCallback<Long>() { MXSession.getApplicationSizeCaches(activity, object : SimpleApiCallback<Long>() {
@ -185,7 +185,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
} }
// clear medias cache // clear medias cache
findPreference(PreferencesManager.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY).let { findPreference(VectorPreferences.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY).let {
val size = getSizeOfFiles(requireContext(), val size = getSizeOfFiles(requireContext(),
File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR))
@ -232,7 +232,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
// Deactivate account section // Deactivate account section
// deactivate account // deactivate account
findPreference(PreferencesManager.SETTINGS_DEACTIVATE_ACCOUNT_KEY) findPreference(VectorPreferences.SETTINGS_DEACTIVATE_ACCOUNT_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.let { activity?.let {
notImplemented() notImplemented()
@ -834,7 +834,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
override fun onSuccess(info: Void?) { override fun onSuccess(info: Void?) {
// refresh the settings value // refresh the settings value
PreferenceManager.getDefaultSharedPreferences(activity).edit { PreferenceManager.getDefaultSharedPreferences(activity).edit {
putString(PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY, value) putString(VectorPreferences.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY, value)
} }
onCommonDone(null) onCommonDone(null)

View file

@ -53,7 +53,7 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() {
} }
// application version // application version
(findPreference(PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY)).let { (findPreference(VectorPreferences.SETTINGS_VERSION_PREFERENCE_KEY)).let {
it.summary = getVersion(longFormat = false, useBuildNumber = true) it.summary = getVersion(longFormat = false, useBuildNumber = true)
it.setOnPreferenceClickListener { pref -> it.setOnPreferenceClickListener { pref ->
@ -63,7 +63,7 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() {
} }
// SDK version // SDK version
(findPreference(PreferencesManager.SETTINGS_SDK_VERSION_PREFERENCE_KEY)).let { (findPreference(VectorPreferences.SETTINGS_SDK_VERSION_PREFERENCE_KEY)).let {
it.summary = Matrix.getSdkVersion() it.summary = Matrix.getSdkVersion()
it.setOnPreferenceClickListener { pref -> it.setOnPreferenceClickListener { pref ->
@ -73,38 +73,38 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() {
} }
// olm version // olm version
findPreference(PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY)
.summary = session.getCryptoVersion(requireContext(), false) .summary = session.getCryptoVersion(requireContext(), false)
// copyright // copyright
findPreference(PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_COPYRIGHT_PREFERENCE_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.displayInWebView(VectorSettingsUrls.COPYRIGHT) activity?.displayInWebView(VectorSettingsUrls.COPYRIGHT)
false false
} }
// terms & conditions // terms & conditions
findPreference(PreferencesManager.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.displayInWebView(VectorSettingsUrls.TAC) activity?.displayInWebView(VectorSettingsUrls.TAC)
false false
} }
// privacy policy // privacy policy
findPreference(PreferencesManager.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.displayInWebView(VectorSettingsUrls.PRIVACY_POLICY) activity?.displayInWebView(VectorSettingsUrls.PRIVACY_POLICY)
false false
} }
// third party notice // third party notice
findPreference(PreferencesManager.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.displayInWebView(VectorSettingsUrls.THIRD_PARTY_LICENSES) activity?.displayInWebView(VectorSettingsUrls.THIRD_PARTY_LICENSES)
false false
} }
findPreference(PreferencesManager.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY)
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
// See https://developers.google.com/android/guides/opensource // See https://developers.google.com/android/guides/opensource
startActivity(Intent(requireActivity(), OssLicensesMenuActivity::class.java)) startActivity(Intent(requireActivity(), OssLicensesMenuActivity::class.java))

View file

@ -34,10 +34,10 @@ class VectorSettingsIgnoredUsersFragment : VectorSettingsBaseFragment() {
// displayed the ignored users list // displayed the ignored users list
private val mIgnoredUserSettingsCategoryDivider by lazy { private val mIgnoredUserSettingsCategoryDivider by lazy {
findPreference(PreferencesManager.SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY)
} }
private val mIgnoredUserSettingsCategory by lazy { private val mIgnoredUserSettingsCategory by lazy {
findPreference(PreferencesManager.SETTINGS_IGNORED_USERS_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_IGNORED_USERS_PREFERENCE_KEY) as PreferenceCategory
} }
override fun bindPref() { override fun bindPref() {

View file

@ -25,8 +25,8 @@ class VectorSettingsLabsFragment : VectorSettingsBaseFragment() {
override fun bindPref() { override fun bindPref() {
// Lab // Lab
// val useCryptoPref = findPreference(PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY) as SwitchPreference // val useCryptoPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY) as SwitchPreference
// val cryptoIsEnabledPref = findPreference(PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY) // val cryptoIsEnabledPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY)
if (session.isCryptoEnabled()) { if (session.isCryptoEnabled()) {
@ -102,7 +102,7 @@ class VectorSettingsLabsFragment : VectorSettingsBaseFragment() {
} }
// SaveMode Management // SaveMode Management
// findPreference(PreferencesManager.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY) // findPreference(VectorPreferences.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY)
// .onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> // .onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
// notImplemented() // notImplemented()
// /* TODO // /* TODO

View file

@ -38,7 +38,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
@Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var activeSessionHolder: ActiveSessionHolder
override fun bindPref() { override fun bindPref() {
findPreference(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY).let { pref -> findPreference(VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY).let { pref ->
val pushRuleService = session val pushRuleService = session
val mRuleMaster = pushRuleService.getPushRules() val mRuleMaster = pushRuleService.getPushRules()
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } .find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
@ -65,15 +65,15 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) { return when (preference?.key) {
PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> { VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> {
updateEnabledForDevice(preference) updateEnabledForDevice(preference)
true true
} }
PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> { VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> {
updateEnabledForAccount(preference) updateEnabledForAccount(preference)
true true
} }
else -> { else -> {
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
} }
@ -84,7 +84,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
val switchPref = preference as SwitchPreference val switchPref = preference as SwitchPreference
if (switchPref.isChecked) { if (switchPref.isChecked) {
FcmHelper.getFcmToken(requireContext())?.let { FcmHelper.getFcmToken(requireContext())?.let {
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) { if (VectorPreferences.areNotificationEnabledForDevice(requireContext())) {
pushManager.registerPusherWithFcmKey(it) pushManager.registerPusherWithFcmKey(it)
} }
} }

View file

@ -37,10 +37,10 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() {
override val preferenceXmlRes = R.xml.vector_settings_preferences override val preferenceXmlRes = R.xml.vector_settings_preferences
private val selectedLanguagePreference by lazy { private val selectedLanguagePreference by lazy {
findPreference(PreferencesManager.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY)
} }
private val textSizePreference by lazy { private val textSizePreference by lazy {
findPreference(PreferencesManager.SETTINGS_INTERFACE_TEXT_SIZE_KEY) findPreference(VectorPreferences.SETTINGS_INTERFACE_TEXT_SIZE_KEY)
} }
@Inject lateinit var vectorConfiguration: VectorConfiguration @Inject lateinit var vectorConfiguration: VectorConfiguration
@ -72,7 +72,7 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() {
} }
// Url preview // Url preview
(findPreference(PreferencesManager.SETTINGS_SHOW_URL_PREVIEW_KEY) as SwitchPreference).let { (findPreference(VectorPreferences.SETTINGS_SHOW_URL_PREVIEW_KEY) as SwitchPreference).let {
/* /*
TODO TODO
it.isChecked = session.isURLPreviewEnabled it.isChecked = session.isURLPreviewEnabled
@ -112,18 +112,18 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() {
} }
// update keep medias period // update keep medias period
findPreference(PreferencesManager.SETTINGS_MEDIA_SAVING_PERIOD_KEY).let { findPreference(VectorPreferences.SETTINGS_MEDIA_SAVING_PERIOD_KEY).let {
it.summary = PreferencesManager.getSelectedMediasSavingPeriodString(activity) it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(requireContext())
it.onPreferenceClickListener = Preference.OnPreferenceClickListener { it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
context?.let { context: Context -> context?.let { context: Context ->
AlertDialog.Builder(context) AlertDialog.Builder(context)
.setSingleChoiceItems(R.array.media_saving_choice, .setSingleChoiceItems(R.array.media_saving_choice,
PreferencesManager.getSelectedMediasSavingPeriod(activity)) { d, n -> VectorPreferences.getSelectedMediasSavingPeriod(context)) { d, n ->
PreferencesManager.setSelectedMediasSavingPeriod(activity, n) VectorPreferences.setSelectedMediasSavingPeriod(context, n)
d.cancel() d.cancel()
it.summary = PreferencesManager.getSelectedMediasSavingPeriodString(activity) it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(context)
} }
.show() .show()
} }

View file

@ -74,57 +74,57 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() {
// cryptography // cryptography
private val mCryptographyCategory by lazy { private val mCryptographyCategory by lazy {
findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY) as PreferenceCategory
} }
private val mCryptographyCategoryDivider by lazy { private val mCryptographyCategoryDivider by lazy {
findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY)
} }
// cryptography manage // cryptography manage
private val mCryptographyManageCategory by lazy { private val mCryptographyManageCategory by lazy {
findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY) as PreferenceCategory
} }
private val mCryptographyManageCategoryDivider by lazy { private val mCryptographyManageCategoryDivider by lazy {
findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY)
} }
// displayed pushers // displayed pushers
private val mPushersSettingsDivider by lazy { private val mPushersSettingsDivider by lazy {
findPreference(PreferencesManager.SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY)
} }
private val mPushersSettingsCategory by lazy { private val mPushersSettingsCategory by lazy {
findPreference(PreferencesManager.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY) as PreferenceCategory
} }
private val mDevicesListSettingsCategory by lazy { private val mDevicesListSettingsCategory by lazy {
findPreference(PreferencesManager.SETTINGS_DEVICES_LIST_PREFERENCE_KEY) as PreferenceCategory findPreference(VectorPreferences.SETTINGS_DEVICES_LIST_PREFERENCE_KEY) as PreferenceCategory
} }
private val mDevicesListSettingsCategoryDivider by lazy { private val mDevicesListSettingsCategoryDivider by lazy {
findPreference(PreferencesManager.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY)
} }
private val cryptoInfoDeviceNamePreference by lazy { private val cryptoInfoDeviceNamePreference by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY) as VectorPreference findPreference(VectorPreferences.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY) as VectorPreference
} }
private val cryptoInfoDeviceIdPreference by lazy { private val cryptoInfoDeviceIdPreference by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY)
} }
private val manageBackupPref by lazy { private val manageBackupPref by lazy {
findPreference(PreferencesManager.SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY)
} }
private val exportPref by lazy { private val exportPref by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY)
} }
private val importPref by lazy { private val importPref by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY)
} }
private val cryptoInfoTextPreference by lazy { private val cryptoInfoTextPreference by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY)
} }
// encrypt to unverified devices // encrypt to unverified devices
private val sendToUnverifiedDevicesPref by lazy { private val sendToUnverifiedDevicesPref by lazy {
findPreference(PreferencesManager.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY) as SwitchPreference findPreference(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY) as SwitchPreference
} }
override fun bindPref() { override fun bindPref() {
@ -140,22 +140,22 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() {
// Analytics // Analytics
// Analytics tracking management // Analytics tracking management
(findPreference(PreferencesManager.SETTINGS_USE_ANALYTICS_KEY) as SwitchPreference).let { (findPreference(VectorPreferences.SETTINGS_USE_ANALYTICS_KEY) as SwitchPreference).let {
// On if the analytics tracking is activated // On if the analytics tracking is activated
it.isChecked = PreferencesManager.useAnalytics(requireContext()) it.isChecked = VectorPreferences.useAnalytics(requireContext())
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
PreferencesManager.setUseAnalytics(requireContext(), newValue as Boolean) VectorPreferences.setUseAnalytics(requireContext(), newValue as Boolean)
true true
} }
} }
// Rageshake Management // Rageshake Management
(findPreference(PreferencesManager.SETTINGS_USE_RAGE_SHAKE_KEY) as SwitchPreference).let { (findPreference(VectorPreferences.SETTINGS_USE_RAGE_SHAKE_KEY) as SwitchPreference).let {
it.isChecked = PreferencesManager.useRageshake(requireContext()) it.isChecked = VectorPreferences.useRageshake(requireContext())
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
PreferencesManager.setUseRageshake(requireContext(), newValue as Boolean) VectorPreferences.setUseRageshake(requireContext(), newValue as Boolean)
true true
} }
} }

View file

@ -34,10 +34,10 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() {
override val preferenceXmlRes = R.xml.vector_settings_voice_video override val preferenceXmlRes = R.xml.vector_settings_voice_video
private val mUseRiotCallRingtonePreference by lazy { private val mUseRiotCallRingtonePreference by lazy {
findPreference(PreferencesManager.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY) as SwitchPreference findPreference(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY) as SwitchPreference
} }
private val mCallRingtonePreference by lazy { private val mCallRingtonePreference by lazy {
findPreference(PreferencesManager.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY)
} }
override fun bindPref() { override fun bindPref() {

View file

@ -72,7 +72,7 @@ class TestBingRulesSettings @Inject constructor(private val activeSessionHolder:
// override fun doFix() { // override fun doFix() {
// val activity = fragment.activity // val activity = fragment.activity
// if (activity is VectorSettingsFragmentInteractionListener) { // if (activity is VectorSettingsFragmentInteractionListener) {
// activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY) // activity.requestHighlightPreferenceKeyOnResume(VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)
// } // }
// activity?.supportFragmentManager?.popBackStack() // activity?.supportFragmentManager?.popBackStack()
// } // }

View file

@ -18,7 +18,7 @@ package im.vector.riotx.features.settings.troubleshoot
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.settings.PreferencesManager import im.vector.riotx.features.settings.VectorPreferences
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -30,14 +30,14 @@ class TestDeviceSettings @Inject constructor(private val context: AppCompatActiv
override fun perform() { override fun perform() {
if (PreferencesManager.areNotificationEnabledForDevice(context)) { if (VectorPreferences.areNotificationEnabledForDevice(context)) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_device_settings_success) description = stringProvider.getString(R.string.settings_troubleshoot_test_device_settings_success)
quickFix = null quickFix = null
status = TestStatus.SUCCESS status = TestStatus.SUCCESS
} else { } else {
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) { quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) {
override fun doFix() { override fun doFix() {
PreferencesManager.setNotificationEnabledForDevice(context, true) VectorPreferences.setNotificationEnabledForDevice(context, true)
manager?.retry() manager?.retry()
} }
} }