diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt index 1df81889..bdc988d2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt @@ -87,7 +87,8 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo val matrixConfiguration = (appContext as MatrixConfiguration.Provider).providesMatrixConfiguration() instance = Matrix(appContext, matrixConfiguration) } 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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt index 8e63e864..8f694016 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt @@ -40,7 +40,8 @@ data class PushCondition( /** * Required for room_member_count conditions. * 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 ) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/MXCryptoError.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/MXCryptoError.kt index 42102124..b61a1e41 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/MXCryptoError.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/MXCryptoError.kt @@ -85,7 +85,9 @@ sealed class MXCryptoError : Throwable() { 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 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 NO_MORE_ALGORITHM_REASON = "Room was previously configured to use encryption, but is no longer." + " Perhaps the homeserver is hiding the configuration event." + 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 NO_MORE_ALGORITHM_REASON = "Room was previously configured to use encryption, but is no longer." + + " Perhaps the homeserver is hiding the configuration event." } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt index 02111012..6728daa5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt @@ -40,7 +40,8 @@ interface KeysBackupService { * @param keysBackupCreationInfo the info object from [prepareKeysBackupVersion]. * @param callback Asynchronous callback */ - fun createKeysBackupVersion(keysBackupCreationInfo: MegolmBackupCreationInfo, callback: MatrixCallback) + fun createKeysBackupVersion(keysBackupCreationInfo: MegolmBackupCreationInfo, + callback: MatrixCallback) /** * 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 callback the main callback */ - fun backupAllGroupSessions(progressListener: ProgressListener?, callback: MatrixCallback?) + fun backupAllGroupSessions(progressListener: ProgressListener?, + callback: MatrixCallback?) /** * Check trust on a key backup version. @@ -66,7 +68,8 @@ interface KeysBackupService { * @param keysBackupVersion the backup version to check. * @param callback block called when the operations completes. */ - fun getKeysBackupTrust(keysBackupVersion: KeysVersionResult, callback: MatrixCallback) + fun getKeysBackupTrust(keysBackupVersion: KeysVersionResult, + callback: MatrixCallback) /** * Return the current progress of the backup @@ -80,7 +83,8 @@ interface KeysBackupService { * @param version the backup version * @param callback */ - fun getVersion(version: String, callback: MatrixCallback) + fun getVersion(version: String, + callback: MatrixCallback) /** * 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 callback Asynchronous callback */ - fun prepareKeysBackupVersion(password: String?, progressListener: ProgressListener?, callback: MatrixCallback) + fun prepareKeysBackupVersion(password: String?, + progressListener: ProgressListener?, + callback: MatrixCallback) /** * 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 callback Asynchronous callback */ - fun deleteBackup(version: String, callback: MatrixCallback?) + fun deleteBackup(version: String, + callback: MatrixCallback?) /** * 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 callback block called when the operations completes. */ - fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult, trust: Boolean, callback: MatrixCallback) + fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult, + trust: Boolean, + callback: MatrixCallback) /** * 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 callback block called when the operations completes. */ - fun trustKeysBackupVersionWithRecoveryKey(keysBackupVersion: KeysVersionResult, recoveryKey: String, callback: MatrixCallback) + fun trustKeysBackupVersionWithRecoveryKey(keysBackupVersion: KeysVersionResult, + recoveryKey: String, + callback: MatrixCallback) /** * 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 callback block called when the operations completes. */ - fun trustKeysBackupVersionWithPassphrase(keysBackupVersion: KeysVersionResult, password: String, callback: MatrixCallback) + fun trustKeysBackupVersionWithPassphrase(keysBackupVersion: KeysVersionResult, + password: String, + callback: MatrixCallback) /** * 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 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) + fun restoreKeysWithRecoveryKey(keysVersionResult: KeysVersionResult, + recoveryKey: String, roomId: String?, + sessionId: String?, + stepProgressListener: StepProgressListener?, + callback: MatrixCallback) /** * 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 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) + fun restoreKeyBackupWithPassword(keysBackupVersion: KeysVersionResult, + password: String, + roomId: String?, + sessionId: String?, + stepProgressListener: StepProgressListener?, + callback: MatrixCallback) val keysBackupVersion: KeysVersionResult? val currentBackupVersion: String? diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt index 3ed3ec0c..508cbb55 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt @@ -67,7 +67,8 @@ data class PublicRoom( 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") var guestCanJoin: Boolean = false, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt index 9025d7b0..5ed0c0e2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt @@ -168,8 +168,10 @@ internal abstract class CryptoModule { abstract fun bindSendToDeviceTask(sendToDeviceTask: DefaultSendToDeviceTask): SendToDeviceTask @Binds - abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice): ClaimOneTimeKeysForUsersDeviceTask + abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice) + : ClaimOneTimeKeysForUsersDeviceTask @Binds - abstract fun bindDeleteDeviceWithUserPasswordTask(deleteDeviceWithUserPasswordTask: DefaultDeleteDeviceWithUserPasswordTask): DeleteDeviceWithUserPasswordTask + abstract fun bindDeleteDeviceWithUserPasswordTask(deleteDeviceWithUserPasswordTask: DefaultDeleteDeviceWithUserPasswordTask) + : DeleteDeviceWithUserPasswordTask } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXMegolmExportEncryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXMegolmExportEncryption.kt index 82b2c95d..b9cb59a0 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXMegolmExportEncryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXMegolmExportEncryption.kt @@ -229,7 +229,7 @@ object MXMegolmExportEncryption { 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 lineStart = lineEnd + 1 @@ -247,9 +247,9 @@ object MXMegolmExportEncryption { val line: String if (lineEnd < 0) { - line = fileStr.substring(lineStart).trim { it <= ' ' } + line = fileStr.substring(lineStart).trim() } else { - line = fileStr.substring(lineStart, lineEnd).trim { it <= ' ' } + line = fileStr.substring(lineStart, lineEnd).trim() } if (TextUtils.equals(line, TRAILER_LINE)) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt index a9ea4a73..519a850f 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt @@ -684,7 +684,8 @@ internal class MXOlmDevice @Inject constructor( adapter.fromJson(payloadString) } catch (e: Exception) { 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( diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt index 29439c44..a13ae75b 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt @@ -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.util.createBackgroundHandler import timber.log.Timber -import java.util.* import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject @@ -132,20 +131,26 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor( 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) { - // nothing to do here - } else if (req.state === OutgoingRoomKeyRequest.RequestState.UNSENT || req.state === OutgoingRoomKeyRequest.RequestState.FAILED) { - Timber.v("## cancelRoomKeyRequest() : deleting unnecessary room key request for $requestBody") - cryptoStore.deleteOutgoingRoomKeyRequest(req.requestId) - } else if (req.state === OutgoingRoomKeyRequest.RequestState.SENT) { - if (andResend) { - req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND - } else { - req.state = OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING + when (req.state) { + OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING, + OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND -> { + // nothing to do here + } + OutgoingRoomKeyRequest.RequestState.UNSENT, + OutgoingRoomKeyRequest.RequestState.FAILED -> { + Timber.v("## cancelRoomKeyRequest() : deleting unnecessary room key request for $requestBody") + cryptoStore.deleteOutgoingRoomKeyRequest(req.requestId) + } + 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") val outgoingRoomKeyRequest = cryptoStore.getOutgoingRoomKeyRequestByState( - HashSet(Arrays.asList(OutgoingRoomKeyRequest.RequestState.UNSENT, + setOf(OutgoingRoomKeyRequest.RequestState.UNSENT, OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING, - OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND))) + OutgoingRoomKeyRequest.RequestState.CANCELLATION_PENDING_AND_WILL_RESEND)) if (null == outgoingRoomKeyRequest) { Timber.e("## sendOutgoingRoomKeyRequests() : No more outgoing room key requests") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index fb90db7d..180b7aa6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -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 olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext, event.roomId, timeline, encryptedEventContent.sessionId, encryptedEventContent.senderKey) + return olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext, + event.roomId, + timeline, + encryptedEventContent.sessionId, + encryptedEventContent.senderKey) .fold( { throwable -> if (throwable is MXCryptoError.OlmError) { @@ -211,7 +215,8 @@ internal class MXMegolmDecryption(private val credentials: Credentials, return } 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() ?: return @@ -259,7 +264,13 @@ internal class MXMegolmDecryption(private val credentials: Credentials, 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) { keysBackup.maybeBackupKeys() @@ -322,7 +333,8 @@ internal class MXMegolmDecryption(private val credentials: Credentials, // were no one-time keys. 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() payloadJson["type"] = EventType.FORWARDED_ROOM_KEY diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt index e24132c3..7b5a8cd4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt @@ -106,7 +106,8 @@ internal class MXOlmDecryption( } 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, String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt index 4dc3c634..5d4a9504 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt @@ -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 val backUp = keysVersionResult.version != keysBackupVersion?.version 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 @@ -1224,7 +1225,8 @@ internal class KeysBackup @Inject constructor( } try { - keysBackupData.roomIdToRoomKeysBackupData[olmInboundGroupSessionWrapper.roomId]!!.sessionIdToKeyBackupData[olmInboundGroupSessionWrapper.olmInboundGroupSession!!.sessionIdentifier()] = keyBackupData + keysBackupData.roomIdToRoomKeysBackupData[olmInboundGroupSessionWrapper.roomId]!! + .sessionIdToKeyBackupData[olmInboundGroupSessionWrapper.olmInboundGroupSession!!.sessionIdentifier()] = keyBackupData } catch (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 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 } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt index b779ec08..8e877f89 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt @@ -34,7 +34,10 @@ import io.realm.Sort // By default if a chunk is empty we consider it unlinked internal fun ChunkEntity.isUnlinked(): Boolean { 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() { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt index 6e567c0a..a9d33c86 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt @@ -23,7 +23,8 @@ import io.realm.annotations.Index // at java.lang.Thread.run(Thread.java:764) // Caused by: java.lang.IllegalArgumentException: 'value' is not a valid managed object. // 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.session.pushers.AddHttpPusherWorker$doWork$$inlined$fold$lambda$2.execute(AddHttpPusherWorker.kt:70) // at io.realm.Realm.executeTransaction(Realm.java:1493) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt index 4327b6ee..6610edb8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt @@ -26,11 +26,13 @@ import io.realm.Sort import io.realm.kotlin.where internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery { - return realm.where().equalTo(EventEntityFields.EVENT_ID, eventId) + return realm.where() + .equalTo(EventEntityFields.EVENT_ID, eventId) } internal fun EventEntity.Companion.where(realm: Realm, eventIds: List): RealmQuery { - return realm.where().`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray()) + return realm.where() + .`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray()) } internal fun EventEntity.Companion.where(realm: Realm, @@ -86,7 +88,9 @@ internal fun RealmQuery.prev(since: Int? = null, strict: Boolean = } internal fun RealmList.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.fastContains(eventId: String): Boolean { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt index 3d27a56b..33c9d868 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt @@ -24,7 +24,8 @@ import io.realm.RealmQuery import io.realm.kotlin.where internal fun GroupEntity.Companion.where(realm: Realm, roomId: String): RealmQuery { - return realm.where().equalTo(GroupEntityFields.GROUP_ID, roomId) + return realm.where() + .equalTo(GroupEntityFields.GROUP_ID, roomId) } internal fun GroupEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt index 031cb93e..81818e53 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt @@ -25,7 +25,8 @@ import io.realm.RealmQuery import io.realm.kotlin.where internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery { - return realm.where().equalTo(RoomEntityFields.ROOM_ID, roomId) + return realm.where() + .equalTo(RoomEntityFields.ROOM_ID, roomId) } internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt index 5942118d..3669ada7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt @@ -29,11 +29,13 @@ import io.realm.Sort import io.realm.kotlin.where internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery { - return realm.where().equalTo(TimelineEventEntityFields.EVENT_ID, eventId) + return realm.where() + .equalTo(TimelineEventEntityFields.EVENT_ID, eventId) } internal fun TimelineEventEntity.Companion.where(realm: Realm, eventIds: List): RealmQuery { - return realm.where().`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray()) + return realm.where() + .`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray()) } internal fun TimelineEventEntity.Companion.where(realm: Realm, @@ -111,5 +113,7 @@ internal fun RealmQuery.prev(since: Int? = null, strict: Bo internal fun RealmList.find(eventId: String): TimelineEventEntity? { - return this.where().equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId).findFirst() + return this.where() + .equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId) + .findFirst() } diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenScope.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.kt similarity index 69% rename from vector/src/main/java/im/vector/riotx/core/di/ScreenScope.java rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.kt index a2243eab..9c9327df 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenScope.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.kt @@ -14,16 +14,11 @@ * limitations under the License. */ -package im.vector.riotx.core.di; +package im.vector.matrix.android.internal.di -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import javax.inject.Scope; +import javax.inject.Scope @Scope -@Documented -@Retention(RetentionPolicy.RUNTIME) -public @interface ScreenScope { -} +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class MatrixScope \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.kt similarity index 68% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.java rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.kt index 30c9138e..37753fdf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixScope.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.kt @@ -14,16 +14,11 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.di; +package im.vector.matrix.android.internal.session -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; - -import javax.inject.Scope; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Documented -@Retention(RUNTIME) -public @interface MatrixScope {} \ No newline at end of file +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class SessionScope \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt index a2ca8503..46578272 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt @@ -36,7 +36,8 @@ private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER" internal class GroupSummaryUpdater @Inject constructor(private val context: Context, private val credentials: Credentials, - @SessionDatabase realmConfiguration: RealmConfiguration) : RealmLiveEntityObserver(realmConfiguration) { + @SessionDatabase realmConfiguration: RealmConfiguration) + : RealmLiveEntityObserver(realmConfiguration) { override val query = Monarchy.Query { GroupEntity.where(it) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt index 6989cb4c..fc6c8838 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt @@ -69,7 +69,8 @@ internal class DefaultProcessEventForPushTask @Inject constructor( }.filter { 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 -> fulfilledBingRule(event, params.rules)?.let { Timber.v("[PushRules] Rule $it match for event ${event.eventId}") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomFactory.kt index dddcd37f..143ef60b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomFactory.kt @@ -66,7 +66,8 @@ internal class RoomFactory @Inject constructor(private val context: Context, val stateService = DefaultStateService(roomId, taskExecutor, sendStateTask) val roomMembersService = DefaultMembershipService(roomId, monarchy, taskExecutor, loadRoomMembersTask, inviteTask, joinRoomTask, leaveRoomTask) 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( roomId, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt index 31c381f4..27270c3e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt @@ -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 { - val event = eventFactory.createReplaceTextEvent(roomId, targetEventId, newBodyText, newBodyAutoMarkdown, MessageType.MSGTYPE_TEXT, compatibilityBodyText).also { - saveLocalEcho(it) - } + val event = eventFactory + .createReplaceTextEvent(roomId, targetEventId, newBodyText, newBodyAutoMarkdown, MessageType.MSGTYPE_TEXT, compatibilityBodyText) + .also { + saveLocalEcho(it) + } val workRequest = createSendEventWork(event) TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) return CancelableWork(context, workRequest.id) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index 4e7e8eed..c5f7a6e3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -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( type = MessageType.MSGTYPE_TEXT, @@ -255,9 +260,15 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials // // This is where the reply goes. val body = bodyForReply(eventReplied.getClearContent().toModel()) - val replyFallbackTemplateFormatted = """ -
${stringProvider.getString(R.string.message_reply_to_prefix)}%s
%s
%s - """.trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText) + val replyFallbackTemplateFormatted = """ +
+ ${stringProvider.getString(R.string.message_reply_to_prefix)} + %s +
+ %s +
+
+ %s""".trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText) // // > <@alice:example.org> This is the original body // diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt index 053bf7f7..e51f9b46 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt @@ -30,9 +30,9 @@ internal class DefaultStateService @Inject constructor(private val roomId: Strin override fun updateTopic(topic: String, callback: MatrixCallback) { val params = SendStateTask.Params(roomId, EventType.STATE_ROOM_TOPIC, - HashMap().apply { - put("topic", topic) - }) + mapOf( + "topic" to topic + )) sendStateTask.configureWith(params) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt index 3b652d0b..3925adf1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt @@ -351,7 +351,9 @@ internal class DefaultTimeline( val initialDisplayIndex = if (isLive) { liveEvents.firstOrNull()?.root?.displayIndex } else { - val initialEvent = liveEvents.where().equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId).findFirst() + val initialEvent = liveEvents.where() + .equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId) + .findFirst() shouldFetchInitialEvent = initialEvent == null initialEvent?.root?.displayIndex } ?: DISPLAY_INDEX_UNKNOWN diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt index 52f66fa4..9c876049 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt @@ -40,7 +40,9 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc val newDirectRoomIds = directMessages.content.values.flatten() 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 } newDirectRoomIds.forEach { roomId -> diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CompatUtil.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CompatUtil.kt index 76797ac7..e713c435 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CompatUtil.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CompatUtil.kt @@ -120,7 +120,8 @@ object CompatUtil { 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 // 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 (keyStore.containsAlias(AES_LOCAL_PROTECTION_KEY_ALIAS)) { diff --git a/tools/check/check_code_quality.sh b/tools/check/check_code_quality.sh index 55d782da..aac454d8 100755 --- a/tools/check/check_code_quality.sh +++ b/tools/check/check_code_quality.sh @@ -65,7 +65,13 @@ echo echo "Search for forbidden patterns in code..." ${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=$? diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index 13328c3b..7361e5f8 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -50,7 +50,7 @@ succes[^s] ### Use int instead of 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)< ### Use int instead of short @@ -117,11 +117,9 @@ ButterKnife\.findById\( ### Bad formatting of chain (missing new line) \w\.flatMap\( -\w\.map\( ### Bad formatting of Realm query chain. Insert new line \)\.equalTo -\)\.findAll # Use StandardCharsets.UTF_8.name() # DISABLED (min API to low) diff --git a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt index 47e87aa4..076f5ac4 100644 --- a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt +++ b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt @@ -18,7 +18,7 @@ package im.vector.riotx.fdroid.features.settings.troubleshoot import androidx.appcompat.app.AppCompatActivity import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider -import im.vector.riotx.features.settings.PreferencesManager +import im.vector.riotx.features.settings.VectorPreferences import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest import javax.inject.Inject @@ -26,10 +26,11 @@ import javax.inject.Inject * Test that the application is started on boot */ 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() { - if (PreferencesManager.autoStartOnBoot(context)) { + if (VectorPreferences.autoStartOnBoot(context)) { description = stringProvider.getString(R.string.settings_troubleshoot_test_service_boot_success) status = TestStatus.SUCCESS 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) quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_service_boot_quickfix) { override fun doFix() { - PreferencesManager.setAutoStartOnBoot(context, true) + VectorPreferences.setAutoStartOnBoot(context, true) manager?.retry() } } diff --git a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt index ce9066c2..b0c40a54 100644 --- a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt +++ b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt @@ -25,7 +25,8 @@ import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest import javax.inject.Inject 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() { (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).apply { diff --git a/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt b/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt index 5293c59b..7ca9957f 100755 --- a/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt +++ b/vector/src/fdroid/java/im/vector/riotx/push/fcm/FcmHelper.kt @@ -21,7 +21,7 @@ import android.content.Context import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.pushers.PushersManager 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 /** @@ -65,7 +65,7 @@ object FcmHelper { fun onEnterBackground(context: Context, activeSessionHolder: ActiveSessionHolder) { //We need to use alarm in this mode - if (PreferencesManager.areNotificationEnabledForDevice(context) && activeSessionHolder.hasActiveSession()) { + if (VectorPreferences.areNotificationEnabledForDevice(context) && activeSessionHolder.hasActiveSession()) { val currentSession = activeSessionHolder.getActiveSession() AlarmSyncBroadcastReceiver.scheduleAlarm(context, currentSession.myUserId, 4_000L) Timber.i("Alarm scheduled to restart service") diff --git a/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestPlayServices.kt b/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestPlayServices.kt index e97f3cea..2aaa0d2e 100644 --- a/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestPlayServices.kt +++ b/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestPlayServices.kt @@ -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. */ 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() { val apiAvailability = GoogleApiAvailability.getInstance() diff --git a/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestTokenRegistration.kt b/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestTokenRegistration.kt index b7b49940..f53813af 100644 --- a/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestTokenRegistration.kt +++ b/vector/src/gplay/java/im/vector/riotx/gplay/features/settings/troubleshoot/TestTokenRegistration.kt @@ -34,7 +34,8 @@ import javax.inject.Inject class TestTokenRegistration @Inject constructor(private val context: AppCompatActivity, private val stringProvider: StringProvider, 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() { //Check if we have a registered pusher for this token diff --git a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt index 0be66b17..6c9f16c6 100755 --- a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -39,7 +39,7 @@ import im.vector.riotx.features.notifications.NotifiableEventResolver import im.vector.riotx.features.notifications.NotifiableMessageEvent import im.vector.riotx.features.notifications.NotificationDrawerManager 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 timber.log.Timber @@ -72,7 +72,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { * @param message the message */ override fun onMessageReceived(message: RemoteMessage?) { - if (!PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { + if (!VectorPreferences.areNotificationEnabledForDevice(applicationContext)) { Timber.i("Notification are disabled for this device") return } @@ -107,7 +107,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { if (refreshedToken == null) { Timber.w("onNewToken:received null token") } else { - if (PreferencesManager.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) { + if (VectorPreferences.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) { pusherManager.registerPusherWithFcmKey(refreshedToken) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.java b/vector/src/main/java/im/vector/riotx/core/di/ScreenScope.kt similarity index 68% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.java rename to vector/src/main/java/im/vector/riotx/core/di/ScreenScope.kt index 52842641..27f39b1e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionScope.java +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenScope.kt @@ -14,16 +14,11 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.session; +package im.vector.riotx.core.di -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; - -import javax.inject.Scope; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Documented -@Retention(RUNTIME) -public @interface SessionScope {} \ No newline at end of file +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class ScreenScope diff --git a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt index ddbe1536..346f4766 100644 --- a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt @@ -17,12 +17,12 @@ package im.vector.riotx.core.resources import android.content.Context -import im.vector.riotx.features.settings.PreferencesManager +import im.vector.riotx.features.settings.VectorPreferences import javax.inject.Inject class UserPreferencesProvider @Inject constructor(private val context: Context) { fun shouldShowHiddenEvents(): Boolean { - return PreferencesManager.shouldShowHiddenEvents(context) + return VectorPreferences.shouldShowHiddenEvents(context) } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/core/utils/RingtoneUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/RingtoneUtils.kt index e4da72aa..5b8834e6 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/RingtoneUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/RingtoneUtils.kt @@ -22,7 +22,7 @@ import android.media.RingtoneManager import android.net.Uri import android.preference.PreferenceManager 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. @@ -41,7 +41,7 @@ import im.vector.riotx.features.settings.PreferencesManager */ fun getCallRingtoneUri(context: Context): Uri? { 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 { return Uri.parse(it) @@ -96,7 +96,7 @@ fun getCallRingtoneName(context: Context): String? { fun setCallRingtoneUri(context: Context, ringtoneUri: Uri) { PreferenceManager.getDefaultSharedPreferences(context) .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 */ 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) { PreferenceManager.getDefaultSharedPreferences(context) .edit { - putBoolean(PreferencesManager.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault) + putBoolean(VectorPreferences.SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY, useRiotDefault) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 1439a1e9..2b3ddc51 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -98,7 +98,7 @@ import im.vector.riotx.features.media.VideoContentRenderer import im.vector.riotx.features.media.VideoMediaViewerActivity import im.vector.riotx.features.notifications.NotificationDrawerManager 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 kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_room_detail.* @@ -419,7 +419,7 @@ class RoomDetailFragment : composerLayout.sendButton.setOnClickListener { val textMessage = composerLayout.composerEditText.text.toString() 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) // Send voice - if (PreferencesManager.isSendVoiceFeatureEnabled(this)) { + if (VectorPreferences.isSendVoiceFeatureEnabled(this)) { items.add(DialogListItem.SendVoice.INSTANCE) } @@ -449,7 +449,7 @@ class RoomDetailFragment : //items.add(DialogListItem.SendSticker) // Camera - //if (PreferencesManager.useNativeCamera(this)) { + //if (VectorPreferences.useNativeCamera(this)) { items.add(DialogListItem.TakePhoto) items.add(DialogListItem.TakeVideo) //} else { @@ -829,7 +829,7 @@ class RoomDetailFragment : // vibrate = true } -// if (vibrate && PreferencesManager.vibrateWhenMentioning(context)) { +// if (vibrate && VectorPreferences.vibrateWhenMentioning(context)) { // val v= context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator // if (v?.hasVibrator() == true) { // v.vibrate(100) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index 032d690c..5b77cef7 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -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())) 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(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId)) diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt index 1e529bc6..158461a9 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt @@ -28,7 +28,7 @@ import im.vector.matrix.android.api.util.SecretStoringUtils import im.vector.riotx.BuildConfig import im.vector.riotx.R 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 timber.log.Timber 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! */ fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { - if (!PreferencesManager.areNotificationEnabledForDevice(context)) { + if (!VectorPreferences.areNotificationEnabledForDevice(context)) { Timber.i("Notification are disabled for this device") return } diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt index 5b54f502..80249912 100755 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt @@ -41,7 +41,7 @@ import im.vector.riotx.core.utils.startNotificationChannelSettingsIntent import im.vector.riotx.features.home.HomeActivity import im.vector.riotx.features.home.room.detail.RoomDetailActivity 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 java.util.* @@ -420,7 +420,7 @@ object NotificationUtils { priority = NotificationCompat.PRIORITY_DEFAULT if (roomInfo.shouldBing) { //Compat - PreferencesManager.getNotificationRingTone(context)?.let { + VectorPreferences.getNotificationRingTone(context)?.let { setSound(it) } setLights(accentColor, 500, 500) @@ -534,7 +534,7 @@ object NotificationUtils { if (simpleNotifiableEvent.noisy) { //Compat priority = NotificationCompat.PRIORITY_DEFAULT - PreferencesManager.getNotificationRingTone(context)?.let { + VectorPreferences.getNotificationRingTone(context)?.let { setSound(it) } setLights(accentColor, 500, 500) @@ -630,7 +630,7 @@ object NotificationUtils { if (noisy) { //Compat priority = NotificationCompat.PRIORITY_DEFAULT - PreferencesManager.getNotificationRingTone(context)?.let { + VectorPreferences.getNotificationRingTone(context)?.let { setSound(it) } setLights(accentColor, 500, 500) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/PreferencesManager.java b/vector/src/main/java/im/vector/riotx/features/settings/PreferencesManager.java deleted file mode 100755 index e24bc2fe..00000000 --- a/vector/src/main/java/im/vector/riotx/features/settings/PreferencesManager.java +++ /dev/null @@ -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 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 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 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); - } -} diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt new file mode 100755 index 00000000..00f66f7c --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -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) + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt index 7a7c7615..7fd60562 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt @@ -78,9 +78,9 @@ class VectorSettingsActivity : VectorBaseActivity(), override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat?, pref: Preference?): Boolean { 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) - } 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) } else { try { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt index 906cf5ea..5694ecf8 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -46,7 +46,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences 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()) { callNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { NotificationUtils.openSystemSettingsForCallCategory(this) @@ -56,7 +56,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF 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()) { noisyNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { NotificationUtils.openSystemSettingsForNoisyCategory(this) @@ -66,7 +66,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF 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()) { silentNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { NotificationUtils.openSystemSettingsForSilentCategory(this) @@ -78,18 +78,18 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF // Ringtone - val ringtonePreference = findPreference(PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY) + val ringtonePreference = findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY) if (supportNotificationChannels()) { ringtonePreference.isVisible = false } else { - ringtonePreference.summary = PreferencesManager.getNotificationRingToneName(activity) + ringtonePreference.summary = VectorPreferences.getNotificationRingToneName(requireContext()) ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) - if (null != PreferencesManager.getNotificationRingTone(activity)) { - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, PreferencesManager.getNotificationRingTone(activity)) + if (null != VectorPreferences.getNotificationRingTone(requireContext())) { + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, VectorPreferences.getNotificationRingTone(requireContext())) } startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE) @@ -152,14 +152,14 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF if (resultCode == Activity.RESULT_OK) { when (requestCode) { REQUEST_NOTIFICATION_RINGTONE -> { - PreferencesManager.setNotificationRingTone(activity, + VectorPreferences.setNotificationRingTone(requireContext(), data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) // test if the selected ring tone can be played - val notificationRingToneName = PreferencesManager.getNotificationRingToneName(activity) + val notificationRingToneName = VectorPreferences.getNotificationRingToneName(requireContext()) if (null != notificationRingToneName) { - PreferencesManager.setNotificationRingTone(activity, PreferencesManager.getNotificationRingTone(activity)) - findPreference(PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY).summary = notificationRingToneName + VectorPreferences.setNotificationRingTone(requireContext(), VectorPreferences.getNotificationRingTone(requireContext())) + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY).summary = notificationRingToneName } } } @@ -217,13 +217,13 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF // preference name <-> rule Id private var mPrefKeyToBingRuleId = mapOf( - PreferencesManager.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, - PreferencesManager.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, - PreferencesManager.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY to BingRule.RULE_ID_INVITE_ME, - PreferencesManager.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_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_DISPLAY_NAME, + VectorPreferences.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY to BingRule.RULE_ID_CONTAIN_USER_NAME, + VectorPreferences.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY to BingRule.RULE_ID_ONE_TO_ONE_ROOM, + VectorPreferences.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY to BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS, + VectorPreferences.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY to BingRule.RULE_ID_INVITE_ME, + VectorPreferences.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY to BingRule.RULE_ID_CALL, + VectorPreferences.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY to BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ) fun newInstance(matrixId: String) = VectorSettingsAdvancedNotificationPreferenceFragment() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsFlairFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsFlairFragment.kt index d2ea1970..817de1ad 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsFlairFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsFlairFragment.kt @@ -30,7 +30,7 @@ class VectorSettingsFlairFragment : VectorSettingsBaseFragment() { // Group Flairs private val mGroupsFlairCategory by lazy { - findPreference(PreferencesManager.SETTINGS_GROUPS_FLAIR_KEY) as PreferenceCategory + findPreference(VectorPreferences.SETTINGS_GROUPS_FLAIR_KEY) as PreferenceCategory } override fun bindPref() { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt index 353884f4..63246b25 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt @@ -61,25 +61,25 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { private var mDisplayedPhoneNumber = ArrayList() 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 { - findPreference(PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY) as UserAvatarPreference + findPreference(VectorPreferences.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY) as UserAvatarPreference } 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 { - findPreference(PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY) } // Local contacts 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 { - 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 // user account - findPreference(PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_LOGGED_IN_PREFERENCE_KEY) .summary = session.sessionParams.credentials.userId // home server - findPreference(PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY) .summary = session.sessionParams.homeServerConnectionConfig.homeServerUri.toString() // identity server - findPreference(PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) .summary = session.sessionParams.homeServerConnectionConfig.identityServerUri.toString() @@ -165,7 +165,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { setContactsPreferences() // clear cache - findPreference(PreferencesManager.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY).let { + findPreference(VectorPreferences.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY).let { /* TODO MXSession.getApplicationSizeCaches(activity, object : SimpleApiCallback() { @@ -185,7 +185,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { } // 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(), File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) @@ -232,7 +232,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { // Deactivate account section // deactivate account - findPreference(PreferencesManager.SETTINGS_DEACTIVATE_ACCOUNT_KEY) + findPreference(VectorPreferences.SETTINGS_DEACTIVATE_ACCOUNT_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.let { notImplemented() @@ -834,7 +834,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { override fun onSuccess(info: Void?) { // refresh the settings value PreferenceManager.getDefaultSharedPreferences(activity).edit { - putString(PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY, value) + putString(VectorPreferences.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY, value) } onCommonDone(null) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt index 2be698a2..d27ae075 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt @@ -53,7 +53,7 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() { } // application version - (findPreference(PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY)).let { + (findPreference(VectorPreferences.SETTINGS_VERSION_PREFERENCE_KEY)).let { it.summary = getVersion(longFormat = false, useBuildNumber = true) it.setOnPreferenceClickListener { pref -> @@ -63,7 +63,7 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() { } // SDK version - (findPreference(PreferencesManager.SETTINGS_SDK_VERSION_PREFERENCE_KEY)).let { + (findPreference(VectorPreferences.SETTINGS_SDK_VERSION_PREFERENCE_KEY)).let { it.summary = Matrix.getSdkVersion() it.setOnPreferenceClickListener { pref -> @@ -73,38 +73,38 @@ class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() { } // olm version - findPreference(PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY) .summary = session.getCryptoVersion(requireContext(), false) // copyright - findPreference(PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_COPYRIGHT_PREFERENCE_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.displayInWebView(VectorSettingsUrls.COPYRIGHT) false } // terms & conditions - findPreference(PreferencesManager.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.displayInWebView(VectorSettingsUrls.TAC) false } // privacy policy - findPreference(PreferencesManager.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.displayInWebView(VectorSettingsUrls.PRIVACY_POLICY) false } // third party notice - findPreference(PreferencesManager.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.displayInWebView(VectorSettingsUrls.THIRD_PARTY_LICENSES) false } - findPreference(PreferencesManager.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY) .onPreferenceClickListener = Preference.OnPreferenceClickListener { // See https://developers.google.com/android/guides/opensource startActivity(Intent(requireActivity(), OssLicensesMenuActivity::class.java)) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsIgnoredUsersFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsIgnoredUsersFragment.kt index 3532a794..5ff01e5f 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsIgnoredUsersFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsIgnoredUsersFragment.kt @@ -34,10 +34,10 @@ class VectorSettingsIgnoredUsersFragment : VectorSettingsBaseFragment() { // displayed the ignored users list 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 { - findPreference(PreferencesManager.SETTINGS_IGNORED_USERS_PREFERENCE_KEY) as PreferenceCategory + findPreference(VectorPreferences.SETTINGS_IGNORED_USERS_PREFERENCE_KEY) as PreferenceCategory } override fun bindPref() { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsLabsFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsLabsFragment.kt index bb5ad0ee..f05f5bed 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsLabsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsLabsFragment.kt @@ -25,8 +25,8 @@ class VectorSettingsLabsFragment : VectorSettingsBaseFragment() { override fun bindPref() { // Lab -// val useCryptoPref = findPreference(PreferencesManager.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 useCryptoPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY) as SwitchPreference +// val cryptoIsEnabledPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY) if (session.isCryptoEnabled()) { @@ -102,7 +102,7 @@ class VectorSettingsLabsFragment : VectorSettingsBaseFragment() { } // SaveMode Management -// findPreference(PreferencesManager.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY) +// findPreference(VectorPreferences.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY) // .onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> // notImplemented() // /* TODO diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt index 95312461..f7e3fbfd 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationFragment.kt @@ -38,7 +38,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( @Inject lateinit var activeSessionHolder: ActiveSessionHolder 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 mRuleMaster = pushRuleService.getPushRules() .find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } @@ -65,15 +65,15 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( override fun onPreferenceTreeClick(preference: Preference?): Boolean { return when (preference?.key) { - PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> { + VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> { updateEnabledForDevice(preference) true } - PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> { + VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> { updateEnabledForAccount(preference) true } - else -> { + else -> { return super.onPreferenceTreeClick(preference) } } @@ -84,7 +84,7 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( val switchPref = preference as SwitchPreference if (switchPref.isChecked) { FcmHelper.getFcmToken(requireContext())?.let { - if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) { + if (VectorPreferences.areNotificationEnabledForDevice(requireContext())) { pushManager.registerPusherWithFcmKey(it) } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt index 962be362..92ea21d0 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt @@ -37,10 +37,10 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { override val preferenceXmlRes = R.xml.vector_settings_preferences private val selectedLanguagePreference by lazy { - findPreference(PreferencesManager.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_INTERFACE_LANGUAGE_PREFERENCE_KEY) } private val textSizePreference by lazy { - findPreference(PreferencesManager.SETTINGS_INTERFACE_TEXT_SIZE_KEY) + findPreference(VectorPreferences.SETTINGS_INTERFACE_TEXT_SIZE_KEY) } @Inject lateinit var vectorConfiguration: VectorConfiguration @@ -72,7 +72,7 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { } // Url preview - (findPreference(PreferencesManager.SETTINGS_SHOW_URL_PREVIEW_KEY) as SwitchPreference).let { + (findPreference(VectorPreferences.SETTINGS_SHOW_URL_PREVIEW_KEY) as SwitchPreference).let { /* TODO it.isChecked = session.isURLPreviewEnabled @@ -112,18 +112,18 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { } // update keep medias period - findPreference(PreferencesManager.SETTINGS_MEDIA_SAVING_PERIOD_KEY).let { - it.summary = PreferencesManager.getSelectedMediasSavingPeriodString(activity) + findPreference(VectorPreferences.SETTINGS_MEDIA_SAVING_PERIOD_KEY).let { + it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(requireContext()) it.onPreferenceClickListener = Preference.OnPreferenceClickListener { context?.let { context: Context -> AlertDialog.Builder(context) .setSingleChoiceItems(R.array.media_saving_choice, - PreferencesManager.getSelectedMediasSavingPeriod(activity)) { d, n -> - PreferencesManager.setSelectedMediasSavingPeriod(activity, n) + VectorPreferences.getSelectedMediasSavingPeriod(context)) { d, n -> + VectorPreferences.setSelectedMediasSavingPeriod(context, n) d.cancel() - it.summary = PreferencesManager.getSelectedMediasSavingPeriodString(activity) + it.summary = VectorPreferences.getSelectedMediasSavingPeriodString(context) } .show() } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 474777cb..10a4fcce 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -74,57 +74,57 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { // cryptography 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 { - findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY) } // cryptography manage 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 { - findPreference(PreferencesManager.SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_MANAGE_DIVIDER_PREFERENCE_KEY) } // displayed pushers 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 { - findPreference(PreferencesManager.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY) as PreferenceCategory + findPreference(VectorPreferences.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY) as PreferenceCategory } 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 { - findPreference(PreferencesManager.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY) } 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 { - findPreference(PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY) } 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 { - 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 { - 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 { - findPreference(PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY) } // encrypt to unverified devices 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() { @@ -140,22 +140,22 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { // Analytics // 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 - it.isChecked = PreferencesManager.useAnalytics(requireContext()) + it.isChecked = VectorPreferences.useAnalytics(requireContext()) it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - PreferencesManager.setUseAnalytics(requireContext(), newValue as Boolean) + VectorPreferences.setUseAnalytics(requireContext(), newValue as Boolean) true } } // Rageshake Management - (findPreference(PreferencesManager.SETTINGS_USE_RAGE_SHAKE_KEY) as SwitchPreference).let { - it.isChecked = PreferencesManager.useRageshake(requireContext()) + (findPreference(VectorPreferences.SETTINGS_USE_RAGE_SHAKE_KEY) as SwitchPreference).let { + it.isChecked = VectorPreferences.useRageshake(requireContext()) it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - PreferencesManager.setUseRageshake(requireContext(), newValue as Boolean) + VectorPreferences.setUseRageshake(requireContext(), newValue as Boolean) true } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsVoiceVideoFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsVoiceVideoFragment.kt index 6e62efa7..27a80855 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsVoiceVideoFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsVoiceVideoFragment.kt @@ -34,10 +34,10 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() { override val preferenceXmlRes = R.xml.vector_settings_voice_video 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 { - findPreference(PreferencesManager.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY) + findPreference(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY) } override fun bindPref() { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestBingRulesSettings.kt b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestBingRulesSettings.kt index e820bc5e..8f353df2 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestBingRulesSettings.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestBingRulesSettings.kt @@ -72,7 +72,7 @@ class TestBingRulesSettings @Inject constructor(private val activeSessionHolder: // override fun doFix() { // val activity = fragment.activity // if (activity is VectorSettingsFragmentInteractionListener) { -// activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY) +// activity.requestHighlightPreferenceKeyOnResume(VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY) // } // activity?.supportFragmentManager?.popBackStack() // } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt index b6e2d3d7..bef1c834 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/troubleshoot/TestDeviceSettings.kt @@ -18,7 +18,7 @@ package im.vector.riotx.features.settings.troubleshoot import androidx.appcompat.app.AppCompatActivity import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider -import im.vector.riotx.features.settings.PreferencesManager +import im.vector.riotx.features.settings.VectorPreferences import javax.inject.Inject /** @@ -30,14 +30,14 @@ class TestDeviceSettings @Inject constructor(private val context: AppCompatActiv override fun perform() { - if (PreferencesManager.areNotificationEnabledForDevice(context)) { + if (VectorPreferences.areNotificationEnabledForDevice(context)) { description = stringProvider.getString(R.string.settings_troubleshoot_test_device_settings_success) quickFix = null status = TestStatus.SUCCESS } else { quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) { override fun doFix() { - PreferencesManager.setNotificationEnabledForDevice(context, true) + VectorPreferences.setNotificationEnabledForDevice(context, true) manager?.retry() } }