mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
General kotlinification.
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
parent
2cf63ea92a
commit
5ab975cc5c
@ -66,7 +66,7 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
|
||||
if (':' in userId) {
|
||||
try {
|
||||
synchronized(notReadyToRetryHS) {
|
||||
res = !notReadyToRetryHS.contains(userId.substring(userId.lastIndexOf(":") + 1))
|
||||
res = !notReadyToRetryHS.contains(userId.substringAfterLast(':'))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## canRetryKeysDownload() failed")
|
||||
|
@ -216,7 +216,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
||||
sendMessageToDevices(requestMessage, request.recipients, request.requestId, object : MatrixCallback<Unit> {
|
||||
private fun onDone(state: OutgoingRoomKeyRequest.RequestState) {
|
||||
if (request.state !== OutgoingRoomKeyRequest.RequestState.UNSENT) {
|
||||
Timber.v("## sendOutgoingRoomKeyRequest() : Cannot update room key request from UNSENT as it was already updated to " + request.state)
|
||||
Timber.v("## sendOutgoingRoomKeyRequest() : Cannot update room key request from UNSENT as it was already updated to ${request.state}")
|
||||
} else {
|
||||
request.state = state
|
||||
cryptoStore.updateOutgoingRoomKeyRequest(request)
|
||||
|
@ -342,10 +342,8 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
||||
private fun addTransaction(tx: VerificationTransaction) {
|
||||
tx.otherUserId.let { otherUserId ->
|
||||
synchronized(txMap) {
|
||||
if (txMap[otherUserId] == null) {
|
||||
txMap[otherUserId] = HashMap()
|
||||
}
|
||||
txMap[otherUserId]?.set(tx.transactionId, tx)
|
||||
val txInnerMap = txMap.getOrPut(otherUserId) { HashMap() }
|
||||
txInnerMap[tx.transactionId] = tx
|
||||
dispatchTxAdded(tx)
|
||||
tx.addListener(this)
|
||||
}
|
||||
|
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package im.vector.riotx.core.linkify
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Better support for geo URi
|
||||
*/
|
||||
@ -26,7 +24,7 @@ object VectorAutoLinkPatterns {
|
||||
private const val LAT_OR_LONG_OR_ALT_NUMBER = "-?\\d+(?:\\.\\d+)?"
|
||||
private const val COORDINATE_SYSTEM = ";crs=[\\w-]+"
|
||||
|
||||
val GEO_URI: Pattern = Pattern.compile("(?:geo:)?" +
|
||||
val GEO_URI: Regex = Regex("(?:geo:)?" +
|
||||
"(" + LAT_OR_LONG_OR_ALT_NUMBER + ")" +
|
||||
"," +
|
||||
"(" + LAT_OR_LONG_OR_ALT_NUMBER + ")" +
|
||||
@ -35,5 +33,5 @@ object VectorAutoLinkPatterns {
|
||||
"(?:" + ";u=\\d+(?:\\.\\d+)?" + ")?" + // uncertainty in meters
|
||||
"(?:" +
|
||||
";[\\w-]+=(?:[\\w-_.!~*'()]|%[\\da-f][\\da-f])+" + // dafuk
|
||||
")*", Pattern.CASE_INSENSITIVE)
|
||||
")*", RegexOption.IGNORE_CASE)
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ object VectorLinkify {
|
||||
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
|
||||
}
|
||||
|
||||
LinkifyCompat.addLinks(spannable, VectorAutoLinkPatterns.GEO_URI, "geo:", arrayOf("geo:"), geoMatchFilter, null)
|
||||
LinkifyCompat.addLinks(spannable, VectorAutoLinkPatterns.GEO_URI.toPattern(), "geo:", arrayOf("geo:"), geoMatchFilter, null)
|
||||
spannable.forEachSpanIndexed { _, urlSpan, start, end ->
|
||||
spannable.removeSpan(urlSpan)
|
||||
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
|
||||
|
@ -24,6 +24,7 @@ import im.vector.riotx.core.resources.LocaleProvider
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
||||
private const val DEFAULT_PUSHER_FILE_TAG = "mobile"
|
||||
|
||||
@ -36,7 +37,7 @@ class PushersManager @Inject constructor(
|
||||
|
||||
fun registerPusherWithFcmKey(pushKey: String): UUID {
|
||||
val currentSession = activeSessionHolder.getActiveSession()
|
||||
var profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + Math.abs(currentSession.myUserId.hashCode())
|
||||
val profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + abs(currentSession.myUserId.hashCode())
|
||||
|
||||
return currentSession.addHttpPusher(
|
||||
pushKey,
|
||||
|
@ -59,9 +59,10 @@ fun initKnownEmojiHashSet(context: Context, done: (() -> Unit)? = null) {
|
||||
val jsonAdapter = moshi.adapter(EmojiDataSource.EmojiData::class.java)
|
||||
val inputAsString = input.bufferedReader().use { it.readText() }
|
||||
val source = jsonAdapter.fromJson(inputAsString)
|
||||
knownEmojiSet = HashSet<String>()
|
||||
source?.emojis?.values?.forEach {
|
||||
knownEmojiSet?.add(it.emojiString())
|
||||
knownEmojiSet = HashSet<String>().also {
|
||||
source?.emojis?.mapTo(it) { (_, value) ->
|
||||
value.emojiString()
|
||||
}
|
||||
}
|
||||
done?.invoke()
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class ViewEditHistoryEpoxyController(private val context: Context,
|
||||
val body = cContent.second?.let { eventHtmlRenderer.render(it) }
|
||||
?: cContent.first
|
||||
|
||||
val nextEvent = if (index + 1 <= sourceEvents.lastIndex) sourceEvents[index + 1] else null
|
||||
val nextEvent = sourceEvents.getOrNull(index + 1)
|
||||
|
||||
var spannedDiff: Spannable? = null
|
||||
if (nextEvent != null && cContent.second == null /*No diff for html*/) {
|
||||
|
@ -130,24 +130,16 @@ object ThemeUtils {
|
||||
*/
|
||||
@ColorInt
|
||||
fun getColor(c: Context, @AttrRes colorAttribute: Int): Int {
|
||||
if (mColorByAttr.containsKey(colorAttribute)) {
|
||||
return mColorByAttr[colorAttribute] as Int
|
||||
return mColorByAttr.getOrPut(colorAttribute) {
|
||||
try {
|
||||
val color = TypedValue()
|
||||
c.theme.resolveAttribute(colorAttribute, color, true)
|
||||
color.data
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Unable to get color")
|
||||
ContextCompat.getColor(c, android.R.color.holo_red_dark)
|
||||
}
|
||||
}
|
||||
|
||||
var matchedColor: Int
|
||||
|
||||
try {
|
||||
val color = TypedValue()
|
||||
c.theme.resolveAttribute(colorAttribute, color, true)
|
||||
matchedColor = color.data
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Unable to get color")
|
||||
matchedColor = ContextCompat.getColor(c, android.R.color.holo_red_dark)
|
||||
}
|
||||
|
||||
mColorByAttr[colorAttribute] = matchedColor
|
||||
|
||||
return matchedColor
|
||||
}
|
||||
|
||||
fun getAttribute(c: Context, @AttrRes attribute: Int): TypedValue? {
|
||||
|
Loading…
Reference in New Issue
Block a user