small code improvements / code cleanup (#4502)

just some smaller things I noticed recently, I hope it is ok if I bunch
them up like this
This commit is contained in:
Konrad Pozniak 2024-06-12 17:17:21 +02:00 committed by GitHub
commit 79c29caaf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 29 deletions

View file

@ -48,6 +48,7 @@ import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.entity.HashTag
import com.keylesspalace.tusky.entity.Status.Mention
import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.settings.PrefKeys
import java.net.URI
import java.net.URISyntaxException
@ -84,7 +85,7 @@ fun setClickableText(
setClickableText(span, this, mentions, tags, listener)
}
}
view.movementMethod = NoTrailingSpaceLinkMovementMethod.getInstance()
view.movementMethod = NoTrailingSpaceLinkMovementMethod
}
@VisibleForTesting
@ -170,7 +171,7 @@ fun setClickableText(
@VisibleForTesting
fun getTagName(text: CharSequence, tags: List<HashTag>?): String? {
val scrapedName = normalizeToASCII(text.subSequence(1, text.length)).toString()
val scrapedName = normalizeToASCII(text.subSequence(1, text.length))
return when (tags) {
null -> scrapedName
else -> tags.firstOrNull { it.name.equals(scrapedName, true) }?.name
@ -275,7 +276,7 @@ fun setClickableMentions(view: TextView, mentions: List<Mention>?, listener: Lin
start = end
}
}
view.movementMethod = NoTrailingSpaceLinkMovementMethod.getInstance()
view.movementMethod = NoTrailingSpaceLinkMovementMethod
}
fun createClickableText(text: String, link: String): CharSequence {
@ -294,7 +295,7 @@ fun Context.openLink(url: String) {
val uri = url.toUri().normalizeScheme()
val useCustomTabs = PreferenceManager.getDefaultSharedPreferences(
this
).getBoolean("customTabs", false)
).getBoolean(PrefKeys.CUSTOM_TABS, false)
if (useCustomTabs) {
openLinkInCustomTab(uri, this)
@ -441,6 +442,4 @@ object NoTrailingSpaceLinkMovementMethod : LinkMovementMethod() {
return super.onTouchEvent(widget, buffer, event)
}
fun getInstance() = NoTrailingSpaceLinkMovementMethod
}