From c63f3edb0647c7d59b5f2386edd42d972e3299a0 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 12:06:50 +0300 Subject: [PATCH 01/15] Initial fixes to support targetSdk 29. --- matrix-sdk-android-rx/build.gradle | 4 ++-- matrix-sdk-android/build.gradle | 4 ++-- .../android/internal/crypto/ShareSecretCryptoProvider.kt | 2 +- .../java/im/vector/matrix/android/internal/util/Debouncer.kt | 5 +++-- vector/build.gradle | 4 ++-- .../src/main/java/im/vector/riotx/core/utils/SystemUtils.kt | 2 +- .../restore/KeysBackupRestoreFromPassphraseFragment.kt | 2 +- .../home/room/detail/timeline/factory/MessageItemFactory.kt | 4 ++-- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android-rx/build.gradle b/matrix-sdk-android-rx/build.gradle index 8907ee8b50..734ff0c130 100644 --- a/matrix-sdk-android-rx/build.gradle +++ b/matrix-sdk-android-rx/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 5f614763d5..60f22a4bdf 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -19,12 +19,12 @@ androidExtensions { } android { - compileSdkVersion 28 + compileSdkVersion 29 testOptions.unitTests.includeAndroidResources = true defaultConfig { minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "0.0.1" // Multidex is useful for tests diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareSecretCryptoProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareSecretCryptoProvider.kt index 78e587c0f1..f4457f3a7f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareSecretCryptoProvider.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareSecretCryptoProvider.kt @@ -68,7 +68,7 @@ internal class ShareSecretCryptoProvider @Inject constructor( fun decryptEvent(event: Event): MXEventDecryptionResult { return runBlocking(coroutineDispatchers.crypto) { - olmDecryptionFactory.create().decryptEvent(event, ShareSecretCryptoProvider::class.java.name ?: "") + olmDecryptionFactory.create().decryptEvent(event, ShareSecretCryptoProvider::class.java.name) } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt index 6a294d8d6c..ba966b18a2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt @@ -25,8 +25,9 @@ internal class Debouncer(private val handler: Handler) { fun debounce(identifier: String, r: Runnable, millis: Long): Boolean { if (runnables.containsKey(identifier)) { // debounce - val old = runnables[identifier] - handler.removeCallbacks(old) + runnables[identifier]?.let { + handler.removeCallbacks(it) + } } insertRunnable(identifier, r, millis) return true diff --git a/vector/build.gradle b/vector/build.gradle index 66ec6808c8..5b7a18b531 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -104,13 +104,13 @@ ext.abiVersionCodes = ["armeabi-v7a": 1, "arm64-v8a": 2, "x86": 3, "x86_64": 4]. def buildNumber = System.env.BUILDKITE_BUILD_NUMBER as Integer ?: 0 android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { applicationId "im.vector.riotx" // Set to API 19 because motionLayout is min API 18. // In the future we may consider using an alternative of MotionLayout to support API 16. But for security reason, maybe not. minSdkVersion 19 - targetSdkVersion 28 + targetSdkVersion 29 multiDexEnabled true // `develop` branch will have version code from timestamp, to ensure each build from CI has a incremented versionCode. diff --git a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt index 1e005c777b..39dab81b39 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt @@ -84,7 +84,7 @@ fun requestDisablingBatteryOptimization(activity: Activity, fragment: Fragment?, */ fun copyToClipboard(context: Context, text: CharSequence, showToast: Boolean = true, @StringRes toastMessage: Int = R.string.copied_to_clipboard) { val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - clipboard.primaryClip = ClipData.newPlainText("", text) + clipboard.setPrimaryClip(ClipData.newPlainText("", text)) if (showToast) { context.toast(toastMessage) } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt index a9bdeee2d6..8dc8855583 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt @@ -95,7 +95,7 @@ class KeysBackupRestoreFromPassphraseFragment @Inject constructor(): VectorBaseF // used just to have default link representation val clickableSpan = object : ClickableSpan() { - override fun onClick(widget: View?) {} + override fun onClick(widget: View) {} } val start = helperText.indexOf(clickableText) val end = start + clickableText.length diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 2b221b9fef..f34a578832 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -440,11 +440,11 @@ class MessageItemFactory @Inject constructor( Spanned.SPAN_INCLUSIVE_EXCLUSIVE) spannable.setSpan(object : ClickableSpan() { - override fun onClick(widget: View?) { + override fun onClick(widget: View) { callback?.onEditedDecorationClicked(informationData) } - override fun updateDrawState(ds: TextPaint?) { + override fun updateDrawState(ds: TextPaint) { // nop } }, From f7cbc0102301e981bb30b860b78b641306efa1e8 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 15:56:33 +0300 Subject: [PATCH 02/15] Replace deprecated PreferenceManager with androidx version. --- CHANGES.md | 2 +- .../im/vector/matrix/android/internal/di/FileQualifiers.kt | 4 ++++ .../vector/matrix/android/internal/di/MatrixComponent.kt | 3 +++ .../im/vector/matrix/android/internal/di/MatrixModule.kt | 7 +++++++ .../matrix/android/internal/network/NetworkInfoReceiver.kt | 2 ++ .../debug/java/im/vector/riotx/receivers/DebugReceiver.kt | 2 +- .../src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt | 2 +- vector/src/main/java/im/vector/riotx/VectorApplication.kt | 2 +- .../java/im/vector/riotx/core/ui/views/KeysBackupBanner.kt | 2 +- .../main/java/im/vector/riotx/core/utils/RingtoneUtils.kt | 2 +- .../vector/riotx/features/disclaimer/DisclaimerDialog.kt | 2 +- .../java/im/vector/riotx/features/settings/VectorLocale.kt | 2 +- 12 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ea0e51561b..5e6a773bdb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,7 +18,7 @@ Translations 🗣: - SDK API changes ⚠️: - - + - Increase targetSdkVersion to 29 Build 🧱: - diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/FileQualifiers.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/FileQualifiers.kt index acd6703c77..aa39fc6fe8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/FileQualifiers.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/FileQualifiers.kt @@ -29,3 +29,7 @@ annotation class SessionCacheDirectory @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class CacheDirectory + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class ExternalFilesDirectory diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt index e929016d4f..4d6082d50b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt @@ -56,6 +56,9 @@ internal interface MatrixComponent { @CacheDirectory fun cacheDir(): File + @ExternalFilesDirectory + fun externalFilesDir(): File? + fun olmManager(): OlmManager fun taskExecutor(): TaskExecutor diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt index 0af22dd65a..785aecdf8e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt @@ -57,6 +57,13 @@ internal object MatrixModule { return context.cacheDir } + @JvmStatic + @Provides + @ExternalFilesDirectory + fun providesExternalFilesDir(context: Context): File? { + return context.getExternalFilesDir(null) + } + @JvmStatic @Provides @MatrixScope diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt index e8daf9b79b..1af9dffd07 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt @@ -14,6 +14,8 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") + package im.vector.matrix.android.internal.network import android.content.BroadcastReceiver diff --git a/vector/src/debug/java/im/vector/riotx/receivers/DebugReceiver.kt b/vector/src/debug/java/im/vector/riotx/receivers/DebugReceiver.kt index 887fba364c..914d7923df 100644 --- a/vector/src/debug/java/im/vector/riotx/receivers/DebugReceiver.kt +++ b/vector/src/debug/java/im/vector/riotx/receivers/DebugReceiver.kt @@ -21,7 +21,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.SharedPreferences -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import androidx.core.content.edit import im.vector.riotx.core.utils.lsFiles import timber.log.Timber diff --git a/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt b/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt index 136949d66f..d62aaf0f3d 100755 --- a/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt +++ b/vector/src/gplay/java/im/vector/riotx/push/fcm/FcmHelper.kt @@ -19,7 +19,7 @@ package im.vector.riotx.push.fcm import android.app.Activity import android.content.Context -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import android.widget.Toast import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailability diff --git a/vector/src/main/java/im/vector/riotx/VectorApplication.kt b/vector/src/main/java/im/vector/riotx/VectorApplication.kt index bd85596924..680550e818 100644 --- a/vector/src/main/java/im/vector/riotx/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotx/VectorApplication.kt @@ -171,7 +171,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration. MultiDex.install(this) } - override fun onConfigurationChanged(newConfig: Configuration?) { + override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) vectorConfiguration.onConfigurationChanged() } diff --git a/vector/src/main/java/im/vector/riotx/core/ui/views/KeysBackupBanner.kt b/vector/src/main/java/im/vector/riotx/core/ui/views/KeysBackupBanner.kt index 8d314f9e58..83a4e88ad5 100755 --- a/vector/src/main/java/im/vector/riotx/core/ui/views/KeysBackupBanner.kt +++ b/vector/src/main/java/im/vector/riotx/core/ui/views/KeysBackupBanner.kt @@ -17,7 +17,7 @@ package im.vector.riotx.core.ui.views import android.content.Context -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import android.util.AttributeSet import android.view.View import android.view.ViewGroup 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 1d2b97e27e..5345658207 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 @@ -20,7 +20,7 @@ import android.content.Context import android.media.Ringtone import android.media.RingtoneManager import android.net.Uri -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import androidx.core.content.edit import im.vector.riotx.features.settings.VectorPreferences diff --git a/vector/src/main/java/im/vector/riotx/features/disclaimer/DisclaimerDialog.kt b/vector/src/main/java/im/vector/riotx/features/disclaimer/DisclaimerDialog.kt index ac6b23a109..86b7fd9fc8 100644 --- a/vector/src/main/java/im/vector/riotx/features/disclaimer/DisclaimerDialog.kt +++ b/vector/src/main/java/im/vector/riotx/features/disclaimer/DisclaimerDialog.kt @@ -17,7 +17,7 @@ package im.vector.riotx.features.disclaimer import android.app.Activity -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import android.view.ViewGroup import android.widget.TextView import androidx.appcompat.app.AlertDialog diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt index 805fa53e96..b1bdb6d84a 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt @@ -19,7 +19,7 @@ package im.vector.riotx.features.settings import android.content.Context import android.content.res.Configuration import android.os.Build -import android.preference.PreferenceManager +import androidx.preference.PreferenceManager import androidx.core.content.edit import im.vector.riotx.BuildConfig import im.vector.riotx.R From 4b7da9ae6b4689d759d48eae1e76763eb81b9a69 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 15:57:21 +0300 Subject: [PATCH 03/15] Replace deprecated getExternalStoragePublicDirectory with getExternalFilesDir. --- .../matrix/android/internal/session/DefaultFileService.kt | 6 ++++-- .../im/vector/riotx/features/crypto/keys/KeysExporter.kt | 2 +- .../crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt index 9eaea8cc34..d3f4a4c244 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt @@ -16,7 +16,6 @@ package im.vector.matrix.android.internal.session -import android.os.Environment import arrow.core.Try import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.content.ContentUrlResolver @@ -25,6 +24,7 @@ import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments import im.vector.matrix.android.internal.di.CacheDirectory +import im.vector.matrix.android.internal.di.ExternalFilesDirectory import im.vector.matrix.android.internal.di.SessionCacheDirectory import im.vector.matrix.android.internal.di.Unauthenticated import im.vector.matrix.android.internal.extensions.foldToCallback @@ -44,6 +44,8 @@ import javax.inject.Inject internal class DefaultFileService @Inject constructor( @CacheDirectory private val cacheDirectory: File, + @ExternalFilesDirectory + private val externalFilesDirectory: File?, @SessionCacheDirectory private val sessionCacheDirectory: File, private val contentUrlResolver: ContentUrlResolver, @@ -103,7 +105,7 @@ internal class DefaultFileService @Inject constructor( private fun copyFile(file: File, downloadMode: FileService.DownloadMode): File { return when (downloadMode) { FileService.DownloadMode.TO_EXPORT -> - file.copyTo(File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.name), true) + file.copyTo(File(externalFilesDirectory, file.name), true) FileService.DownloadMode.FOR_EXTERNAL_SHARE -> file.copyTo(File(File(cacheDirectory, "ext_share"), file.name), true) FileService.DownloadMode.FOR_INTERNAL_USE -> diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keys/KeysExporter.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keys/KeysExporter.kt index cae8b50523..b9b75588f1 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keys/KeysExporter.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keys/KeysExporter.kt @@ -40,7 +40,7 @@ class KeysExporter(private val session: Session) { runCatching { val data = awaitCallback { session.cryptoService().exportRoomKeys(password, it) } withContext(Dispatchers.IO) { - val parentDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + val parentDir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) val file = File(parentDir, "riotx-keys-" + System.currentTimeMillis() + ".txt") writeToFile(data, file) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt index a224cfb387..9175d6c081 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt @@ -167,7 +167,7 @@ class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment() GlobalScope.launch(Dispatchers.Main) { Try { withContext(Dispatchers.IO) { - val parentDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + val parentDir = context?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) val file = File(parentDir, "recovery-key-" + System.currentTimeMillis() + ".txt") writeToFile(data, file) From 5816a04a37a7b47ced8579aa6f4dd25d9447a89d Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 15:58:31 +0300 Subject: [PATCH 04/15] Use MediaStore instead of deprecated addCompletedDownload since Android Q. --- .../im/vector/riotx/core/files/FileSaver.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt index 677f7894e8..493f2e22cb 100644 --- a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt +++ b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt @@ -17,7 +17,10 @@ package im.vector.riotx.core.files import android.app.DownloadManager +import android.content.ContentValues import android.content.Context +import android.os.Build +import android.provider.MediaStore import androidx.annotation.WorkerThread import arrow.core.Try import okio.buffer @@ -57,7 +60,21 @@ fun addEntryToDownloadManager(context: Context, val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager? try { - downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val contentValues = ContentValues().apply { + put(MediaStore.Downloads.TITLE, title) + put(MediaStore.Downloads.DISPLAY_NAME, description) + put(MediaStore.Downloads.MIME_TYPE, mimeType) + put(MediaStore.Downloads.SIZE, file.length()) + } + context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri -> + context.contentResolver.openOutputStream(uri)?.use { outputStream -> + outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() }) + } + } + } else { + downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true) + } } catch (e: Exception) { Timber.e(e, "## addEntryToDownloadManager(): Exception") } From e5482d48c06bc400745e043fbbe0018328a1ff26 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 16:02:50 +0300 Subject: [PATCH 05/15] Remove deprecated & unused ImageTools class. --- .../im/vector/riotx/core/images/ImageTools.kt | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 vector/src/main/java/im/vector/riotx/core/images/ImageTools.kt diff --git a/vector/src/main/java/im/vector/riotx/core/images/ImageTools.kt b/vector/src/main/java/im/vector/riotx/core/images/ImageTools.kt deleted file mode 100644 index 84cba7392f..0000000000 --- a/vector/src/main/java/im/vector/riotx/core/images/ImageTools.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2019 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.core.images - -import android.content.Context -import android.net.Uri -import android.provider.MediaStore -import androidx.exifinterface.media.ExifInterface -import timber.log.Timber -import javax.inject.Inject - -class ImageTools @Inject constructor(private val context: Context) { - - /** - * Gets the [ExifInterface] value for the orientation for this local bitmap Uri. - * - * @param uri The URI to find the orientation for. Must be local. - * @return The orientation value, which may be [ExifInterface.ORIENTATION_UNDEFINED]. - */ - fun getOrientationForBitmap(uri: Uri): Int { - var orientation = ExifInterface.ORIENTATION_UNDEFINED - - if (uri.scheme == "content") { - val proj = arrayOf(MediaStore.Images.Media.DATA) - try { - val cursor = context.contentResolver.query(uri, proj, null, null, null) - cursor?.use { - if (it.moveToFirst()) { - val idxData = it.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) - val path = it.getString(idxData) - if (path.isNullOrBlank()) { - Timber.w("Cannot find path in media db for uri $uri") - return orientation - } - val exif = ExifInterface(path) - orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED) - } - } - } catch (e: Exception) { - // eg SecurityException from com.google.android.apps.photos.content.GooglePhotosImageProvider URIs - // eg IOException from trying to parse the returned path as a file when it is an http uri. - Timber.e(e, "Cannot get orientation for bitmap") - } - } else if (uri.scheme == "file") { - try { - val path = uri.path - if (path != null) { - val exif = ExifInterface(path) - orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED) - } - } catch (e: Exception) { - Timber.e(e, "Cannot get EXIF for file uri $uri") - } - } - - return orientation - } -} From 0a77d5014e778d1d5a18c66f2f218609d27ee95f Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 26 Mar 2020 17:19:29 +0300 Subject: [PATCH 06/15] Fix nullability issues. --- .../im/vector/riotx/core/files/FileSaver.kt | 26 +++++++------------ .../core/glide/VectorGlideModelLoader.kt | 2 +- .../core/platform/EllipsizingTextView.kt | 2 +- .../riotx/core/platform/VectorBaseActivity.kt | 2 +- .../vector/riotx/core/services/CallService.kt | 8 +++--- .../im/vector/riotx/core/utils/Debouncer.kt | 7 ++--- .../im/vector/riotx/core/utils/FileUtils.kt | 2 +- .../im/vector/riotx/core/utils/TextUtils.kt | 4 +-- .../preview/AttachmentsPreviewActivity.kt | 2 +- .../setup/KeysBackupSetupActivity.kt | 2 +- .../quads/SharedSecureStorageViewModel.kt | 4 +-- .../VerificationBottomSheetViewModel.kt | 4 ++- .../home/room/detail/RoomDetailFragment.kt | 2 +- .../media/ImageMediaViewerActivity.kt | 9 ++++++- .../media/VideoMediaViewerActivity.kt | 11 +++++--- .../NotificationBroadcastReceiver.kt | 2 +- .../features/rageshake/VectorFileLogger.kt | 2 +- .../roompreview/RoomPreviewActivity.kt | 2 +- .../riotx/features/settings/VectorLocale.kt | 6 ++--- .../features/settings/VectorPreferences.kt | 9 +++---- .../VectorSettingsSecurityPrivacyFragment.kt | 2 +- 21 files changed, 57 insertions(+), 53 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt index 493f2e22cb..1b9eca984c 100644 --- a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt +++ b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt @@ -16,10 +16,8 @@ package im.vector.riotx.core.files -import android.app.DownloadManager import android.content.ContentValues import android.content.Context -import android.os.Build import android.provider.MediaStore import androidx.annotation.WorkerThread import arrow.core.Try @@ -57,23 +55,17 @@ fun addEntryToDownloadManager(context: Context, mimeType: String, title: String = file.name, description: String = file.name) { - val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager? - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val contentValues = ContentValues().apply { - put(MediaStore.Downloads.TITLE, title) - put(MediaStore.Downloads.DISPLAY_NAME, description) - put(MediaStore.Downloads.MIME_TYPE, mimeType) - put(MediaStore.Downloads.SIZE, file.length()) + val contentValues = ContentValues().apply { + put(MediaStore.Downloads.TITLE, title) + put(MediaStore.Downloads.DISPLAY_NAME, description) + put(MediaStore.Downloads.MIME_TYPE, mimeType) + put(MediaStore.Downloads.SIZE, file.length()) + } + context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri -> + context.contentResolver.openOutputStream(uri)?.use { outputStream -> + outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() }) } - context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri -> - context.contentResolver.openOutputStream(uri)?.use { outputStream -> - outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() }) - } - } - } else { - downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true) } } catch (e: Exception) { Timber.e(e, "## addEntryToDownloadManager(): Exception") diff --git a/vector/src/main/java/im/vector/riotx/core/glide/VectorGlideModelLoader.kt b/vector/src/main/java/im/vector/riotx/core/glide/VectorGlideModelLoader.kt index 1a90b0c34f..191ab6d972 100644 --- a/vector/src/main/java/im/vector/riotx/core/glide/VectorGlideModelLoader.kt +++ b/vector/src/main/java/im/vector/riotx/core/glide/VectorGlideModelLoader.kt @@ -95,7 +95,7 @@ class VectorGlideDataFetcher(private val activeSessionHolder: ActiveSessionHolde override fun loadData(priority: Priority, callback: DataFetcher.DataCallback) { Timber.v("Load data: $data") - if (data.isLocalFile()) { + if (data.isLocalFile() && data.url != null) { val initialFile = File(data.url) callback.onDataReady(FileInputStream(initialFile)) return diff --git a/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt b/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt index 2e5786b57d..f451308c36 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt @@ -333,7 +333,7 @@ class EllipsizingTextView @JvmOverloads constructor(context: Context, attrs: Att * @param workingText text to strip end punctuation from * @return Text without end punctuation. */ - fun stripEndPunctuation(workingText: CharSequence?): String { + fun stripEndPunctuation(workingText: CharSequence): String { return mEndPunctPattern!!.matcher(workingText).replaceFirst("") } } diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt index 2649662ee5..ea954ecf27 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt @@ -134,7 +134,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector { restorables.forEach { it.onSaveInstanceState(outState) } } - override fun onRestoreInstanceState(savedInstanceState: Bundle?) { + override fun onRestoreInstanceState(savedInstanceState: Bundle) { restorables.forEach { it.onRestoreInstanceState(savedInstanceState) } super.onRestoreInstanceState(savedInstanceState) } diff --git a/vector/src/main/java/im/vector/riotx/core/services/CallService.kt b/vector/src/main/java/im/vector/riotx/core/services/CallService.kt index f36b289aaa..30ab62d5b2 100644 --- a/vector/src/main/java/im/vector/riotx/core/services/CallService.kt +++ b/vector/src/main/java/im/vector/riotx/core/services/CallService.kt @@ -128,13 +128,13 @@ class CallService : VectorService() { * Display a call in progress notification. */ private fun displayCallInProgressNotification(intent: Intent) { - val callId = intent.getStringExtra(EXTRA_CALL_ID) + val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: "" val notification = notificationUtils.buildPendingCallNotification( intent.getBooleanExtra(EXTRA_IS_VIDEO, false), - intent.getStringExtra(EXTRA_ROOM_NAME), - intent.getStringExtra(EXTRA_ROOM_ID), - intent.getStringExtra(EXTRA_MATRIX_ID), + intent.getStringExtra(EXTRA_ROOM_NAME) ?: "", + intent.getStringExtra(EXTRA_ROOM_ID) ?: "", + intent.getStringExtra(EXTRA_MATRIX_ID) ?: "", callId) startForeground(NOTIFICATION_ID, notification) diff --git a/vector/src/main/java/im/vector/riotx/core/utils/Debouncer.kt b/vector/src/main/java/im/vector/riotx/core/utils/Debouncer.kt index 627d757574..95035f6c96 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/Debouncer.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/Debouncer.kt @@ -37,9 +37,10 @@ class Debouncer(private val handler: Handler) { fun cancel(identifier: String) { if (runnables.containsKey(identifier)) { - val old = runnables[identifier] - handler.removeCallbacks(old) - runnables.remove(identifier) + runnables[identifier]?.let { + handler.removeCallbacks(it) + runnables.remove(identifier) + } } } diff --git a/vector/src/main/java/im/vector/riotx/core/utils/FileUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/FileUtils.kt index 1a19b49872..839356a129 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/FileUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/FileUtils.kt @@ -73,7 +73,7 @@ private fun logAction(file: File): Boolean { */ private fun recursiveActionOnFile(file: File, action: ActionOnFile): Boolean { if (file.isDirectory) { - file.list().forEach { + file.list()?.forEach { val result = recursiveActionOnFile(File(file, it), action) if (!result) { diff --git a/vector/src/main/java/im/vector/riotx/core/utils/TextUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/TextUtils.kt index 75f6893c7c..9519eb1f9d 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/TextUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/TextUtils.kt @@ -35,8 +35,8 @@ object TextUtils { if (value < 1000) return value.toString() // deal with easy case val e = suffixes.floorEntry(value) - val divideBy = e.key - val suffix = e.value + val divideBy = e?.key + val suffix = e?.value val truncated = value / (divideBy!! / 10) // the number part of the output times 10 val hasDecimal = truncated < 100 && truncated / 10.0 != (truncated / 10).toDouble() diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt index 46a90803ca..6c91f70131 100644 --- a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt @@ -43,7 +43,7 @@ class AttachmentsPreviewActivity : VectorBaseActivity(), ToolbarConfigurable { } fun getOutput(intent: Intent): List { - return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT) + return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT) ?: emptyList() } fun getKeepOriginalSize(intent: Intent): Boolean { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt index 924e25a4d7..72f6bf346d 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt @@ -153,7 +153,7 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() { } override fun onFailure(failure: Throwable) { - toast(failure.localizedMessage) + failure.localizedMessage?.let { toast(it) } hideWaitingView() } }) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/quads/SharedSecureStorageViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/quads/SharedSecureStorageViewModel.kt index a9f5d33888..4b27010f8f 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/quads/SharedSecureStorageViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/quads/SharedSecureStorageViewModel.kt @@ -158,8 +158,8 @@ class SharedSecureStorageViewModel @AssistedInject constructor( @JvmStatic override fun create(viewModelContext: ViewModelContext, state: SharedSecureStorageViewState): SharedSecureStorageViewModel? { val activity: SharedSecureStorageActivity = viewModelContext.activity() - val args: SharedSecureStorageActivity.Args = activity.intent.getParcelableExtra(MvRx.KEY_ARG) - return activity.viewModelFactory.create(state, args) + val args: SharedSecureStorageActivity.Args? = activity.intent.getParcelableExtra(MvRx.KEY_ARG) + return args?.let { activity.viewModelFactory.create(state, it) } } } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt index 731f12cca4..f273e41ccb 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -357,7 +357,9 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( } } } catch (failure: Throwable) { - _viewEvents.post(VerificationBottomSheetViewEvents.ModalError(failure.localizedMessage)) + failure.localizedMessage?.let { + _viewEvents.post(VerificationBottomSheetViewEvents.ModalError(it)) + } } } }.exhaustive 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 f58d7be718..0ecc361d04 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 @@ -782,7 +782,7 @@ class RoomDetailFragment @Inject constructor( updateComposerText("") } is RoomDetailViewEvents.SlashCommandResultError -> { - displayCommandError(sendMessageResult.throwable.localizedMessage) + sendMessageResult.throwable.localizedMessage?.let { displayCommandError(it) } } is RoomDetailViewEvents.SlashCommandNotImplemented -> { displayCommandError(getString(R.string.not_implemented)) diff --git a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt index d9da08254f..8ba21468b7 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt @@ -56,10 +56,17 @@ class ImageMediaViewerActivity : VectorBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(im.vector.riotx.R.layout.activity_image_media_viewer) - mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA) + + if (intent.hasExtra(EXTRA_MEDIA_DATA)) { + mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA)!! + } else { + finish() + } + intent.extras?.getString(EXTRA_SHARED_TRANSITION_NAME)?.let { ViewCompat.setTransitionName(imageTransitionView, it) } + if (mediaData.url.isNullOrEmpty()) { supportFinishAfterTransition() return diff --git a/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt index 9c3312f3bb..e92b58c681 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt @@ -37,11 +37,14 @@ class VideoMediaViewerActivity : VectorBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(im.vector.riotx.R.layout.activity_video_media_viewer) - val mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA) - configureToolbar(videoMediaViewerToolbar, mediaData) - imageContentRenderer.render(mediaData.thumbnailMediaData, ImageContentRenderer.Mode.FULL_SIZE, videoMediaViewerThumbnailView) - videoContentRenderer.render(mediaData, videoMediaViewerThumbnailView, videoMediaViewerLoading, videoMediaViewerVideoView, videoMediaViewerErrorView) + if (intent.hasExtra(EXTRA_MEDIA_DATA)) { + val mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA)!! + + configureToolbar(videoMediaViewerToolbar, mediaData) + imageContentRenderer.render(mediaData.thumbnailMediaData, ImageContentRenderer.Mode.FULL_SIZE, videoMediaViewerThumbnailView) + videoContentRenderer.render(mediaData, videoMediaViewerThumbnailView, videoMediaViewerLoading, videoMediaViewerVideoView, videoMediaViewerErrorView) + } } private fun configureToolbar(toolbar: Toolbar, mediaData: VideoContentRenderer.Data) { diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt index 53d69bce2d..04b267fb3a 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt @@ -97,7 +97,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { val message = getReplyMessage(intent) val roomId = intent.getStringExtra(KEY_ROOM_ID) - if (message.isNullOrBlank() || roomId.isBlank()) { + if (message.isNullOrBlank() || roomId.isNullOrBlank()) { // ignore this event // Can this happen? should we update notification? return diff --git a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt index 16e231491a..ce1b44be21 100644 --- a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt +++ b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt @@ -65,7 +65,7 @@ class VectorFileLogger @Inject constructor(val context: Context, private val vec sFileHandler?.formatter = LogFormatter() sLogger.useParentHandlers = false sLogger.level = Level.ALL - sLogger.addHandler(sFileHandler) + sFileHandler?.let { sLogger.addHandler(it) } } } catch (e: Throwable) { Timber.e(e, "Failed to initialize FileLogger") diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt index a7cb8f2f68..3cb442127f 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt @@ -70,7 +70,7 @@ class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable { if (isFirstCreation()) { val args = intent.getParcelableExtra(ARG) - if (args.worldReadable) { + if (args?.worldReadable == true) { // TODO Room preview: Note: M does not recommend to use /events anymore, so for now we just display the room preview // TODO the same way if it was not world readable addFragment(R.id.simpleFragmentContainer, RoomPreviewNoPreviewFragment::class.java, args) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt index b1bdb6d84a..e1a89ab3c4 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt @@ -59,9 +59,9 @@ object VectorLocale { val preferences = PreferenceManager.getDefaultSharedPreferences(context) if (preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) { - applicationLocale = Locale(preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, ""), - preferences.getString(APPLICATION_LOCALE_COUNTRY_KEY, ""), - preferences.getString(APPLICATION_LOCALE_VARIANT_KEY, "") + applicationLocale = Locale(preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, "")!!, + preferences.getString(APPLICATION_LOCALE_COUNTRY_KEY, "")!!, + preferences.getString(APPLICATION_LOCALE_VARIANT_KEY, "")!! ) } else { applicationLocale = Locale.getDefault() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index 9473c26055..faa48d5686 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -29,7 +29,6 @@ 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 javax.inject.Inject class VectorPreferences @Inject constructor(private val context: Context) { @@ -68,7 +67,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { 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_SHOW_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY" + const val SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY" const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY" @@ -427,11 +426,11 @@ class VectorPreferences @Inject constructor(private val context: Context) { val toneUri = getNotificationRingTone() ?: return null try { - val proj = arrayOf(MediaStore.Audio.Media.DATA) + val proj = arrayOf(MediaStore.Audio.Media.DISPLAY_NAME) return context.contentResolver.query(toneUri, proj, null, null, null)?.use { - val columnIndex = it.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA) + val columnIndex = it.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME) it.moveToFirst() - File(it.getString(columnIndex)).nameWithoutExtension + it.getString(columnIndex) } } catch (e: Exception) { Timber.e(e, "## getNotificationRingToneName() failed") 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 4324c79dfd..91b3593cd0 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 @@ -332,7 +332,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } override fun onFailure(failure: Throwable) { - appContext.toast(failure.localizedMessage) + failure.localizedMessage?.let { appContext.toast(it) } hideLoadingView() } }) From dcb6af6c4548422173f9c6fc2be4be08b0f744d6 Mon Sep 17 00:00:00 2001 From: onurays Date: Wed, 8 Apr 2020 12:40:29 +0300 Subject: [PATCH 07/15] .gitignore file added. --- .gitignore | 1 + matrix-sdk-sqldelight/.gitignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 matrix-sdk-sqldelight/.gitignore diff --git a/.gitignore b/.gitignore index 4a264a28d8..1f3f9c7819 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /tmp ktlint +.idea diff --git a/matrix-sdk-sqldelight/.gitignore b/matrix-sdk-sqldelight/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/matrix-sdk-sqldelight/.gitignore @@ -0,0 +1 @@ +/build From 5b1f887760f4f7ef7b587352cd464cb98bbf3f51 Mon Sep 17 00:00:00 2001 From: onurays Date: Wed, 8 Apr 2020 14:10:31 +0300 Subject: [PATCH 08/15] Code review fixes. --- .../android/internal/network/NetworkInfoReceiver.kt | 1 + .../main/java/im/vector/riotx/core/utils/SystemUtils.kt | 4 ++-- .../crypto/keysbackup/setup/KeysBackupSetupActivity.kt | 2 +- .../verification/VerificationBottomSheetViewModel.kt | 9 +++++---- .../features/home/room/detail/RoomDetailFragment.kt | 2 +- .../settings/VectorSettingsSecurityPrivacyFragment.kt | 2 +- vector/src/main/res/values/strings_riotX.xml | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt index 1af9dffd07..645329628b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/NetworkInfoReceiver.kt @@ -14,6 +14,7 @@ * limitations under the License. */ +// This BroadcastReceiver is used only if the build code is below 24. @file:Suppress("DEPRECATION") package im.vector.matrix.android.internal.network diff --git a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt index 39dab81b39..1905542c49 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt @@ -188,6 +188,6 @@ fun Context.toast(resId: Int) { } // Not in KTX anymore -fun Context.toast(message: String) { - Toast.makeText(this, message, Toast.LENGTH_SHORT).show() +fun Context.toast(message: String?) { + Toast.makeText(this, message ?: getString(R.string.generic_exception_error), Toast.LENGTH_SHORT).show() } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt index 72f6bf346d..fbc69505fa 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt @@ -153,7 +153,7 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() { } override fun onFailure(failure: Throwable) { - failure.localizedMessage?.let { toast(it) } + toast(failure.localizedMessage ?: getString(R.string.unexpected_error)) hideWaitingView() } }) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt index e70211dd44..a932d0cc5f 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -46,8 +46,10 @@ import im.vector.matrix.android.api.util.MatrixItem import im.vector.matrix.android.api.util.toMatrixItem import im.vector.matrix.android.internal.crypto.crosssigning.fromBase64 import im.vector.matrix.android.internal.crypto.crosssigning.isVerified +import im.vector.riotx.R import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.platform.VectorViewModel +import im.vector.riotx.core.resources.StringProvider import timber.log.Timber data class VerificationBottomSheetViewState( @@ -71,7 +73,8 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( @Assisted initialState: VerificationBottomSheetViewState, @Assisted val args: VerificationBottomSheet.VerificationArgs, private val session: Session, - private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider) + private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider, + private val stringProvider: StringProvider) : VectorViewModel(initialState), VerificationService.Listener { @@ -362,9 +365,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( } } } catch (failure: Throwable) { - failure.localizedMessage?.let { - _viewEvents.post(VerificationBottomSheetViewEvents.ModalError(it)) - } + _viewEvents.post(VerificationBottomSheetViewEvents.ModalError(failure.localizedMessage ?: stringProvider.getString(R.string.unexpected_error))) } } }.exhaustive 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 0ecc361d04..8c45090c91 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 @@ -782,7 +782,7 @@ class RoomDetailFragment @Inject constructor( updateComposerText("") } is RoomDetailViewEvents.SlashCommandResultError -> { - sendMessageResult.throwable.localizedMessage?.let { displayCommandError(it) } + displayCommandError(sendMessageResult.throwable.localizedMessage ?: getString(R.string.unexpected_error)) } is RoomDetailViewEvents.SlashCommandNotImplemented -> { displayCommandError(getString(R.string.not_implemented)) 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 91b3593cd0..d357c6ae82 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 @@ -332,7 +332,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } override fun onFailure(failure: Throwable) { - failure.localizedMessage?.let { appContext.toast(it) } + appContext.toast(failure.localizedMessage ?: getString(R.string.unexpected_error)) hideLoadingView() } }) diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index ccb4bfa9be..eabc7e5e0d 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -52,7 +52,7 @@ - + An unexpected error occurred From f97e08b4e56905efb31ac4109aee4c135a20b145 Mon Sep 17 00:00:00 2001 From: onurays Date: Tue, 14 Apr 2020 13:12:17 +0300 Subject: [PATCH 09/15] Remove .gitignore which belongs to another PR. --- matrix-sdk-sqldelight/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 matrix-sdk-sqldelight/.gitignore diff --git a/matrix-sdk-sqldelight/.gitignore b/matrix-sdk-sqldelight/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/matrix-sdk-sqldelight/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build From 667b3716534b6aeb590c4504de6f1a93f1fa686d Mon Sep 17 00:00:00 2001 From: onurays Date: Tue, 14 Apr 2020 16:29:11 +0300 Subject: [PATCH 10/15] Continue supporting old APIs. --- .../im/vector/riotx/core/files/FileSaver.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt index 1b9eca984c..f978e20ca9 100644 --- a/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt +++ b/vector/src/main/java/im/vector/riotx/core/files/FileSaver.kt @@ -16,8 +16,10 @@ package im.vector.riotx.core.files +import android.app.DownloadManager import android.content.ContentValues import android.content.Context +import android.os.Build import android.provider.MediaStore import androidx.annotation.WorkerThread import arrow.core.Try @@ -56,16 +58,22 @@ fun addEntryToDownloadManager(context: Context, title: String = file.name, description: String = file.name) { try { - val contentValues = ContentValues().apply { - put(MediaStore.Downloads.TITLE, title) - put(MediaStore.Downloads.DISPLAY_NAME, description) - put(MediaStore.Downloads.MIME_TYPE, mimeType) - put(MediaStore.Downloads.SIZE, file.length()) - } - context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri -> - context.contentResolver.openOutputStream(uri)?.use { outputStream -> - outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() }) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val contentValues = ContentValues().apply { + put(MediaStore.Downloads.TITLE, title) + put(MediaStore.Downloads.DISPLAY_NAME, description) + put(MediaStore.Downloads.MIME_TYPE, mimeType) + put(MediaStore.Downloads.SIZE, file.length()) } + context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri -> + context.contentResolver.openOutputStream(uri)?.use { outputStream -> + outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() }) + } + } + } else { + val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager? + @Suppress("DEPRECATION") + downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true) } } catch (e: Exception) { Timber.e(e, "## addEntryToDownloadManager(): Exception") From 6639f89a6802126ec74fd594198a727f7158f2a9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 15 Apr 2020 12:53:08 +0200 Subject: [PATCH 11/15] Simpler code --- .../im/vector/matrix/android/internal/util/Debouncer.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt index ba966b18a2..575551da1b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/Debouncer.kt @@ -23,12 +23,9 @@ internal class Debouncer(private val handler: Handler) { private val runnables = HashMap() fun debounce(identifier: String, r: Runnable, millis: Long): Boolean { - if (runnables.containsKey(identifier)) { - // debounce - runnables[identifier]?.let { - handler.removeCallbacks(it) - } - } + // debounce + runnables[identifier]?.let { runnable -> handler.removeCallbacks(runnable) } + insertRunnable(identifier, r, millis) return true } From 24d0cdef1f2973ad4e72cf535515b1a38c5ffb99 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 15 Apr 2020 12:53:28 +0200 Subject: [PATCH 12/15] Add missing changes of SDK version and build tools --- .travis.yml | 4 ++-- tools/release/sign_apk.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b9e9f9946..85bddac7f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,10 +23,10 @@ android: - platform-tools # The BuildTools version used by your project - - build-tools-28.0.3 + - build-tools-29.0.3 # The SDK version used to compile your project - - android-28 + - android-29 before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock diff --git a/tools/release/sign_apk.sh b/tools/release/sign_apk.sh index 7f421c15f4..866510ba13 100755 --- a/tools/release/sign_apk.sh +++ b/tools/release/sign_apk.sh @@ -17,7 +17,7 @@ PARAM_KEYSTORE_PATH=$1 PARAM_APK=$2 # Other params -BUILD_TOOLS_VERSION="28.0.3" +BUILD_TOOLS_VERSION="29.0.3" MIN_SDK_VERSION=19 echo "Signing APK with build-tools version ${BUILD_TOOLS_VERSION} for min SDK version ${MIN_SDK_VERSION}..." From 6dc517584fcbd63cc612cd26d0a43ea92dd6730e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 15 Apr 2020 12:56:33 +0200 Subject: [PATCH 13/15] Fix merge issue --- CHANGES.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e8d68d0181..240203b2c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,6 @@ Features ✨: Improvements 🙌: - Verification DM / Handle concurrent .start after .ready (#794) - Reimplementation of multiple attachment picker - - CrossSigning / Update Shield Logic for DM (#963) - - Xsigning | Complete security new session design update (#1135) - Cross-Signing | Update Shield Logic for DM (#963) - Cross-Signing | Complete security new session design update (#1135) - Cross-Signing | Setup key backup as part of SSSS bootstrapping (#1201) From e26a0bc9ae9b6e63b45345e95405ed0b3e3527d5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 15 Apr 2020 12:57:15 +0200 Subject: [PATCH 14/15] Add Android SDK version --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 240203b2c9..a1748f3623 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,7 +34,7 @@ SDK API changes ⚠️: - Increase targetSdkVersion to 29 Build 🧱: - - + - Compile with Android SDK 29 (Android Q) Other changes: - Increase File Logger capacities ( + use dev log preferences) From 6751d88ade168a6739a0899e1de9dc6b7cdfa6ac Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 15 Apr 2020 13:00:03 +0200 Subject: [PATCH 15/15] Remove .idea exclusion --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1f3f9c7819..4a264a28d8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ /tmp ktlint -.idea