diff --git a/CHANGES.md b/CHANGES.md index 46d2409dbb..0ae711dfc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,7 +27,7 @@ Other changes: - Use `retrofit2.Call.awaitResponse` extension provided by Retrofit 2. (#1526) - Fix minor typo in contribution guide (#1512) - Fix self-assignment of callback in `DefaultRoomPushRuleService#setRoomNotificationState` (#1520) - - Random housekeeping clean-ups indicated by Lint (#1520) + - Random housekeeping clean-ups indicated by Lint (#1520, #1541) Changes in RiotX 0.22.0 (2020-06-15) =================================================== diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt index 35ad8ff4e1..4eda7c60c8 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt @@ -241,14 +241,14 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { val eventWireContent = event.content.toContent() assertNotNull(eventWireContent) - assertNull(eventWireContent.get("body")) - assertEquals(MXCRYPTO_ALGORITHM_MEGOLM, eventWireContent.get("algorithm")) + assertNull(eventWireContent["body"]) + assertEquals(MXCRYPTO_ALGORITHM_MEGOLM, eventWireContent["algorithm"]) - assertNotNull(eventWireContent.get("ciphertext")) - assertNotNull(eventWireContent.get("session_id")) - assertNotNull(eventWireContent.get("sender_key")) + assertNotNull(eventWireContent["ciphertext"]) + assertNotNull(eventWireContent["session_id"]) + assertNotNull(eventWireContent["sender_key"]) - assertEquals(senderSession.sessionParams.deviceId, eventWireContent.get("device_id")) + assertEquals(senderSession.sessionParams.deviceId, eventWireContent["device_id"]) assertNotNull(event.eventId) assertEquals(roomId, event.roomId) @@ -257,7 +257,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { val eventContent = event.toContent() assertNotNull(eventContent) - assertEquals(clearMessage, eventContent.get("body")) + assertEquals(clearMessage, eventContent["body"]) assertEquals(senderSession.myUserId, event.senderId) } diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt index cbd175f53f..d93b151ded 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt @@ -144,7 +144,7 @@ class QuadSTests : InstrumentedTest { val secretAccountData = assertAccountData(aliceSession, "secret.of.life") - val encryptedContent = secretAccountData.content.get("encrypted") as? Map<*, *> + val encryptedContent = secretAccountData.content["encrypted"] as? Map<*, *> assertNotNull("Element should be encrypted", encryptedContent) assertNotNull("Secret should be encrypted with default key", encryptedContent?.get(keyId)) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/EventMatchCondition.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/EventMatchCondition.kt index a6d7e48b9d..ca13155542 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/EventMatchCondition.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/EventMatchCondition.kt @@ -87,14 +87,13 @@ class EventMatchCondition( // Very simple glob to regexp converter private fun simpleGlobToRegExp(glob: String): String { var out = "" // "^" - for (i in 0 until glob.length) { - val c = glob[i] - when (c) { + for (element in glob) { + when (element) { '*' -> out += ".*" '?' -> out += '.'.toString() '.' -> out += "\\." '\\' -> out += "\\\\" - else -> out += c + else -> out += element } } out += "" // '$'.toString() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASDefaultVerificationTransaction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASDefaultVerificationTransaction.kt index 7048d790a0..db97ba1052 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASDefaultVerificationTransaction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASDefaultVerificationTransaction.kt @@ -273,7 +273,7 @@ internal abstract class SASDefaultVerificationTransaction( if (keyIDNoPrefix == otherCrossSigningMasterKeyPublic) { // Check the signature val mac = macUsingAgreedMethod(otherCrossSigningMasterKeyPublic, baseInfo + it) - if (mac != theirMacSafe.mac.get(it)) { + if (mac != theirMacSafe.mac[it]) { // WRONG! Timber.e("## SAS Verification: mac mismatch for MasterKey with id $keyIDNoPrefix") cancel(CancelCode.MismatchedKeys) diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt index b0ae0e4cda..a2026475d0 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt @@ -62,9 +62,9 @@ class ContactPicker(override val requestCode: Int) : Picker() - var emailList = mutableListOf() + val photoUri = cursor.getString(photoUriColumn) + val phoneNumberList = mutableListOf() + val emailList = mutableListOf() getRawContactId(context.contentResolver, contactId)?.let { rawContactId -> val selection = ContactsContract.Data.RAW_CONTACT_ID + " = ?" diff --git a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt index 57e5c6381f..b2e02d564c 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt @@ -40,14 +40,14 @@ class DefaultErrorFormatter @Inject constructor( null -> null is IdentityServiceError -> identityServerError(throwable) is Failure.NetworkConnection -> { - when { - throwable.ioException is SocketTimeoutException -> + when (throwable.ioException) { + is SocketTimeoutException -> stringProvider.getString(R.string.error_network_timeout) - throwable.ioException is UnknownHostException -> + is UnknownHostException -> // Invalid homeserver? // TODO Check network state, airplane mode, etc. stringProvider.getString(R.string.login_error_unknown_host) - else -> + else -> stringProvider.getString(R.string.error_no_network) } } diff --git a/vector/src/main/java/im/vector/riotx/core/preference/VectorEditTextPreference.kt b/vector/src/main/java/im/vector/riotx/core/preference/VectorEditTextPreference.kt index 90246dbb92..e2c61118a7 100644 --- a/vector/src/main/java/im/vector/riotx/core/preference/VectorEditTextPreference.kt +++ b/vector/src/main/java/im/vector/riotx/core/preference/VectorEditTextPreference.kt @@ -45,7 +45,7 @@ class VectorEditTextPreference : EditTextPreference { override fun onBindViewHolder(holder: PreferenceViewHolder) { // display the title in multi-line to avoid ellipsis. try { - holder.itemView.findViewById(android.R.id.title)?.setSingleLine(false) + holder.itemView.findViewById(android.R.id.title)?.isSingleLine = false } catch (e: Exception) { Timber.e(e, "onBindView") } diff --git a/vector/src/main/java/im/vector/riotx/core/preference/VectorPreference.kt b/vector/src/main/java/im/vector/riotx/core/preference/VectorPreference.kt index 396bf3054f..048625ded6 100755 --- a/vector/src/main/java/im/vector/riotx/core/preference/VectorPreference.kt +++ b/vector/src/main/java/im/vector/riotx/core/preference/VectorPreference.kt @@ -87,7 +87,7 @@ open class VectorPreference : Preference { val title = itemView.findViewById(android.R.id.title) val summary = itemView.findViewById(android.R.id.summary) if (title != null) { - title.setSingleLine(false) + title.isSingleLine = false title.setTypeface(null, mTypeface) } diff --git a/vector/src/main/java/im/vector/riotx/core/preference/VectorSwitchPreference.kt b/vector/src/main/java/im/vector/riotx/core/preference/VectorSwitchPreference.kt index e6292d102b..9a2064d741 100644 --- a/vector/src/main/java/im/vector/riotx/core/preference/VectorSwitchPreference.kt +++ b/vector/src/main/java/im/vector/riotx/core/preference/VectorSwitchPreference.kt @@ -43,7 +43,7 @@ class VectorSwitchPreference : SwitchPreference { override fun onBindViewHolder(holder: PreferenceViewHolder) { // display the title in multi-line to avoid ellipsis. - holder.itemView.findViewById(android.R.id.title)?.setSingleLine(false) + holder.itemView.findViewById(android.R.id.title)?.isSingleLine = false super.onBindViewHolder(holder) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt index 33e18595a0..4616cb4b25 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt @@ -33,6 +33,7 @@ import com.airbnb.epoxy.EpoxyTouchHelperCallback import com.airbnb.epoxy.EpoxyViewHolder import timber.log.Timber import kotlin.math.abs +import kotlin.math.min class RoomMessageTouchHelperCallback(private val context: Context, @DrawableRes actionIcon: Int, @@ -92,7 +93,7 @@ class RoomMessageTouchHelperCallback(private val context: Context, setTouchListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) } val size = triggerDistance - if (Math.abs(viewHolder.itemView.translationX) < size || dX > this.dX /*going back*/) { + if (abs(viewHolder.itemView.translationX) < size || dX > this.dX /*going back*/) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) this.dX = dX startTracking = true @@ -127,9 +128,9 @@ class RoomMessageTouchHelperCallback(private val context: Context, private fun drawReplyButton(canvas: Canvas, itemView: View) { // Timber.v("drawReplyButton") - val translationX = Math.abs(itemView.translationX) + val translationX = abs(itemView.translationX) val newTime = System.currentTimeMillis() - val dt = Math.min(17, newTime - lastReplyButtonAnimationTime) + val dt = min(17, newTime - lastReplyButtonAnimationTime) lastReplyButtonAnimationTime = newTime val showing = translationX >= minShowDistance if (showing) { @@ -163,10 +164,10 @@ class RoomMessageTouchHelperCallback(private val context: Context, } else { 1.2f - 0.2f * ((replyButtonProgress - 0.8f) / 0.2f) } - alpha = Math.min(255f, 255 * (replyButtonProgress / 0.8f)).toInt() + alpha = min(255f, 255 * (replyButtonProgress / 0.8f)).toInt() } else { scale = replyButtonProgress - alpha = Math.min(255f, 255 * replyButtonProgress).toInt() + alpha = min(255f, 255 * replyButtonProgress).toInt() } imageDrawable.alpha = alpha diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/PollResultLineView.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/PollResultLineView.kt index a0ad3466f7..c52b863658 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/PollResultLineView.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/PollResultLineView.kt @@ -64,8 +64,8 @@ class PollResultLineView @JvmOverloads constructor( set(value) { field = value // Text in main color - labelTextView.setTypeface(labelTextView.getTypeface(), if (value) Typeface.BOLD else Typeface.NORMAL) - percentTextView.setTypeface(percentTextView.getTypeface(), if (value) Typeface.BOLD else Typeface.NORMAL) + labelTextView.setTypeface(labelTextView.typeface, if (value) Typeface.BOLD else Typeface.NORMAL) + percentTextView.setTypeface(percentTextView.typeface, if (value) Typeface.BOLD else Typeface.NORMAL) } init { diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt b/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt index 292b17ce9f..a0dc4a4ae5 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt @@ -22,6 +22,8 @@ import android.graphics.Paint import android.util.AttributeSet import android.util.Property import android.view.View +import kotlin.math.cos +import kotlin.math.sin /** * This view will draw dots floating around the center of it's view @@ -84,16 +86,16 @@ class DotsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? private fun drawOuterDotsFrame(canvas: Canvas) { for (i in 0 until DOTS_COUNT) { - val cX = (centerX + currentRadius1 * Math.cos(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() - val cY = (centerY + currentRadius1 * Math.sin(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() + val cX = (centerX + currentRadius1 * cos(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() + val cY = (centerY + currentRadius1 * sin(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() canvas.drawCircle(cX, cY, currentDotSize1, circlePaints[i % circlePaints.size]) } } private fun drawInnerDotsFrame(canvas: Canvas) { for (i in 0 until DOTS_COUNT) { - val cX = (centerX + currentRadius2 * Math.cos((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() - val cY = (centerY + currentRadius2 * Math.sin((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() + val cX = (centerX + currentRadius2 * cos((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() + val cY = (centerY + currentRadius2 * sin((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() canvas.drawCircle(cX, cY, currentDotSize2, circlePaints[(i + 1) % circlePaints.size]) } } 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 76065b63ea..dc8c17b08b 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 @@ -337,7 +337,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( * @param aMyDeviceInfo the device info */ private fun refreshCryptographyPreference(devices: List) { - showDeviceListPref.isEnabled = devices.size > 0 + showDeviceListPref.isEnabled = devices.isNotEmpty() showDeviceListPref.summary = resources.getQuantityString(R.plurals.settings_active_sessions_count, devices.size, devices.size) // val userId = session.myUserId // val deviceId = session.sessionParams.deviceId diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/webview/WebviewPermissionUtils.kt b/vector/src/main/java/im/vector/riotx/features/widgets/webview/WebviewPermissionUtils.kt index 32f6a906e2..fa0f4e0a97 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/webview/WebviewPermissionUtils.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/webview/WebviewPermissionUtils.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.fragments.roomwidgets +package im.vector.riotx.features.widgets.webview import android.annotation.SuppressLint import android.content.Context diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/webview/WidgetWebView.kt b/vector/src/main/java/im/vector/riotx/features/widgets/webview/WidgetWebView.kt index 68cbe76531..499f42e0f6 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/webview/WidgetWebView.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/webview/WidgetWebView.kt @@ -24,7 +24,6 @@ import android.webkit.PermissionRequest import android.webkit.WebChromeClient import android.webkit.WebSettings import android.webkit.WebView -import im.vector.fragments.roomwidgets.WebviewPermissionUtils import im.vector.riotx.R import im.vector.riotx.features.themes.ThemeUtils import im.vector.riotx.features.webview.VectorWebViewClient