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
parent 8d65feadd6
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

@ -17,6 +17,7 @@ package com.keylesspalace.tusky.components.login
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.util.Log
@ -199,17 +200,15 @@ class LoginActivity : BaseActivity() {
) {
// To authorize this app and log in it's necessary to redirect to the domain given,
// login there, and the server will redirect back to the app with its response.
val uri = HttpUrl.Builder()
val uri = Uri.Builder()
.scheme("https")
.host(domain)
.addPathSegments(MastodonApi.ENDPOINT_AUTHORIZE)
.addQueryParameter("client_id", clientId)
.addQueryParameter("redirect_uri", oauthRedirectUri)
.addQueryParameter("response_type", "code")
.addQueryParameter("scope", OAUTH_SCOPES)
.authority(domain)
.path(MastodonApi.ENDPOINT_AUTHORIZE)
.appendQueryParameter("client_id", clientId)
.appendQueryParameter("redirect_uri", oauthRedirectUri)
.appendQueryParameter("response_type", "code")
.appendQueryParameter("scope", OAUTH_SCOPES)
.build()
.toString()
.toUri()
if (openInWebView) {
doWebViewAuth.launch(LoginData(domain, uri, oauthRedirectUri.toUri()))

View File

@ -22,7 +22,6 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import at.connyduck.calladapter.networkresult.fold
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.entity.ScheduledStatus
import com.keylesspalace.tusky.network.MastodonApi
import dagger.hilt.android.lifecycle.HiltViewModel
@ -31,8 +30,7 @@ import kotlinx.coroutines.launch
@HiltViewModel
class ScheduledStatusViewModel @Inject constructor(
val mastodonApi: MastodonApi,
val eventHub: EventHub
val mastodonApi: MastodonApi
) : ViewModel() {
private val pagingSourceFactory = ScheduledStatusPagingSourceFactory(mastodonApi)

View File

@ -13,8 +13,6 @@
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
@file:OptIn(ExperimentalStdlibApi::class)
package com.keylesspalace.tusky.components.timeline
import com.keylesspalace.tusky.db.entity.HomeTimelineData

View File

@ -21,6 +21,6 @@ val unicodeToASCIIMap = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČ
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz".toList()
).toMap()
fun normalizeToASCII(text: CharSequence): CharSequence {
fun normalizeToASCII(text: CharSequence): String {
return String(text.map { unicodeToASCIIMap[it] ?: it }.toCharArray())
}

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
}

View File

@ -24,13 +24,6 @@ fun <T, C : MutableCollection<in T>> Iterable<T>.removeDuplicatesTo(destination:
return filterTo(destination, HashSet<T>()::add)
}
/**
* Copies elements to a new list, removing duplicates and preserving original order.
*/
fun <T> Iterable<T>.removeDuplicates(): List<T> {
return removeDuplicatesTo(ArrayList())
}
inline fun <T> List<T>.withoutFirstWhich(predicate: (T) -> Boolean): List<T> {
val index = indexOfFirst(predicate)
if (index == -1) {

View File

@ -65,7 +65,7 @@ class EditProfileViewModel @Inject constructor(
private val mastodonApi: MastodonApi,
private val eventHub: EventHub,
private val application: Application,
private val instanceInfoRepo: InstanceInfoRepository
instanceInfoRepo: InstanceInfoRepository
) : ViewModel() {
private val _profileData = MutableStateFlow(null as Resource<Account>?)