Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small code improvements / code cleanup #4502

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
11 changes: 5 additions & 6 deletions app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -84,7 +85,7 @@ fun setClickableText(
setClickableText(span, this, mentions, tags, listener)
}
}
view.movementMethod = NoTrailingSpaceLinkMovementMethod.getInstance()
view.movementMethod = NoTrailingSpaceLinkMovementMethod
}

@VisibleForTesting
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -441,6 +442,4 @@ object NoTrailingSpaceLinkMovementMethod : LinkMovementMethod() {

return super.onTouchEvent(widget, buffer, event)
}

fun getInstance() = NoTrailingSpaceLinkMovementMethod
}
7 changes: 0 additions & 7 deletions app/src/main/java/com/keylesspalace/tusky/util/ListUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>?)
Expand Down
Loading