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

Feature/upgrade dependencies #574

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java openjdk-17.0.2
java zulu-17.40.19
63 changes: 21 additions & 42 deletions android/src/main/kotlin/com/twidere/twiderex/TwidereXActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
package com.twidere.twiderex

import android.Manifest
import android.content.ContentResolver.SCHEME_ANDROID_RESOURCE
import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -52,15 +50,11 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.ImageLoaderBuilder
import com.seiko.imageloader.LocalImageLoader
import com.seiko.imageloader.cache.disk.DiskCacheBuilder
import com.seiko.imageloader.cache.memory.MemoryCacheBuilder
import com.seiko.imageloader.component.keyer.Keyer
import com.seiko.imageloader.request.Options
import com.seiko.imageloader.cache.memory.maxSizePercent
import com.seiko.imageloader.component.setupDefaultComponents
import com.twidere.twiderex.action.LocalStatusActions
import com.twidere.twiderex.action.StatusActions
import com.twidere.twiderex.component.LocalWindowInsetsController
Expand All @@ -87,8 +81,10 @@ import com.twidere.twiderex.ui.LocalIsActiveNetworkMetered
import com.twidere.twiderex.utils.BrowserLoginDeepLinksChannel
import com.twidere.twiderex.utils.LocalPlatformResolver
import com.twidere.twiderex.utils.PlatformResolver
import kotlinx.coroutines.launch
import moe.tlaster.kfilepicker.FilePicker
import moe.tlaster.precompose.lifecycle.PreComposeActivity
import moe.tlaster.precompose.lifecycle.repeatOnLifecycle
import moe.tlaster.precompose.lifecycle.setContent
import moe.tlaster.precompose.navigation.Navigator
import okio.Path.Companion.toPath
Expand Down Expand Up @@ -194,46 +190,29 @@ class TwidereXActivity : PreComposeActivity(), KoinComponent {
}

private fun generateImageLoader(storageService: StorageProvider): ImageLoader {
return ImageLoaderBuilder(this)
.commonConfig()
.memoryCache {
MemoryCacheBuilder(this)
// Set the max size to 25% of the app's available memory.
.maxSizePercent(0.25)
.build()
return ImageLoader {
commonConfig()
components {
setupDefaultComponents(applicationContext)
}
.diskCache {
DiskCacheBuilder()
.directory(storageService.cacheDir.toPath().resolve("image_cache"))
.maxSizeBytes(512L * 1024 * 1024) // 512MB
.build()
interceptor {
memoryCacheConfig {
maxSizePercent(applicationContext, 0.25)
}
diskCacheConfig {
directory(storageService.cacheDir.toPath().resolve("image_cache"))
maxSizeBytes(512L * 1024 * 1024) // 512MB
}
}
.components {
add(
// TODO remove after library upgrade
// fix resource cache, resId will be change
// @return android.resource://com.twidere.twiderex/2131755047-ic_heart-16
object : Keyer {
override fun key(data: Any, options: Options): String? {
val androidUri = when {
data is String && data.startsWith(SCHEME_ANDROID_RESOURCE) -> data
data is com.eygraber.uri.Uri && data.scheme == SCHEME_ANDROID_RESOURCE -> data.toString()
else -> return null
}
val id = androidUri.substringAfterLast('/', "").toIntOrNull() ?: return null
val entryName = resources.getResourceEntryName(id)
return "$data-$entryName-${resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK}"
}
},
)
}
.build()
}
}

private fun onDeeplink(it: Uri) {
if (BrowserLoginDeepLinksChannel.canHandle(it.toString())) {
lifecycleScope.launchWhenResumed {
BrowserLoginDeepLinksChannel.send(it.toString())
lifecycleScope.launch {
repeatOnLifecycle {
BrowserLoginDeepLinksChannel.send(it.toString())
}
}
} else {
navController.navigate(it.toString())
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Versions {
}

object Java {
const val jvmTarget = "11"
const val jvmTarget = "17"
val java = JavaVersion.VERSION_17
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VersionsCheckPlugin : Plugin<Project> {
}

private fun String.isNonStable(): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { toUpperCase(Locale.US).contains(it) }
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { uppercase(Locale.US).contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(this)
return isStable.not()
Expand Down
12 changes: 7 additions & 5 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ kotlin {
implementation(projects.services)
api(libs.bundles.compose)
implementation(libs.bundles.kotlinx)
implementation(libs.bundles.reftrofit2)
implementation(libs.bundles.ktor)
implementation(libs.bundles.androidx.common)
implementation(libs.sqldelight.coroutines.extensions)
implementation(libs.square.okhttp)
implementation(libs.jodaTime)
api(libs.square.okio)
api(libs.koin.core)
api(libs.mokoResources)
Expand All @@ -56,7 +57,7 @@ kotlin {
dependencies {
implementation(libs.koin.test)
implementation(libs.kotlinx.coroutines.test)
implementation("io.mockk:mockk:1.13.3")
implementation("io.mockk:mockk:1.13.4")
}
}
val androidMain by getting {
Expand All @@ -69,17 +70,18 @@ kotlin {
implementation(libs.koin.androidx.workmanager)
implementation(libs.compose.accompanist.permissions)
implementation(libs.androidx.work.rumtime.ktx)
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:9a70eae6f1")
}
}
val androidAndroidTest by getting {
val androidInstrumentedTest by getting {
dependsOn(commonTest)
dependencies {
implementation(libs.bundles.test.android)
implementation(libs.sqldelight.android.driver)
implementation(libs.room.test)
}
}
val androidTest by getting {
val androidUnitTest by getting {
dependencies {
implementation(libs.sqldelight.sqlite.driver)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package com.twidere.twiderex.initializer

import android.app.NotificationChannel
import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationChannelGroupCompat
Expand Down Expand Up @@ -56,7 +57,7 @@ class NotificationChannelInitializer : Initializer<NotificationChannelInitialize
}

notificationManagerCompat.notificationChannelsCompat.forEach {
if (it.id !in addedChannels && it.group == null) {
if (it.id !in addedChannels && it.group == null && it.id != NotificationChannel.DEFAULT_CHANNEL_ID) {
notificationManagerCompat.deleteNotificationChannel(it.id)
}
}
Expand Down Expand Up @@ -105,7 +106,7 @@ class NotificationChannelInitializer : Initializer<NotificationChannelInitialize

// Delete all channels and groups of non-existing accounts
notificationManagerCompat.notificationChannelsCompat.forEach {
if (it.id !in addedChannels && it.group != null) {
if (it.id !in addedChannels && it.group != null && it.id != NotificationChannel.DEFAULT_CHANNEL_ID) {
notificationManagerCompat.deleteNotificationChannel(it.id)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import android.text.Html
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.seiko.imageloader.ImageLoaderBuilder
import com.seiko.imageloader.request.ComposeImageResult
import com.seiko.imageloader.request.ImageRequestBuilder
import com.seiko.imageloader.imageLoader
import com.seiko.imageloader.model.ImageRequest
import com.seiko.imageloader.model.ImageResult
import com.twidere.common.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -103,11 +103,10 @@ actual class AppNotificationManager(
)
}
appNotification.largeIcon?.let {
val imageLoader = ImageLoaderBuilder(context).build()
val request = ImageRequestBuilder().data(it).build()
val result = imageLoader.execute(request)
if (result is ComposeImageResult) {
builder.setLargeIcon(result.image)
val request = ImageRequest(it)
val result = context.imageLoader.execute(request)
if (result is ImageResult.Bitmap) {
builder.setLargeIcon(result.bitmap)
}
}
notificationManagerCompat.notify(notificationId, builder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.graphics.painter.Painter
import com.seiko.imageloader.ImageLoaderBuilder
import com.seiko.imageloader.ImageLoaderConfigBuilder
import com.seiko.imageloader.ImageRequestState
import com.seiko.imageloader.component.fetcher.Fetcher
import com.seiko.imageloader.component.fetcher.KtorUrlFetcher
import com.seiko.imageloader.intercept.Interceptor
import com.seiko.imageloader.intercept.BlurInterceptor
import com.seiko.imageloader.model.ImageRequest
import com.seiko.imageloader.model.blur
import com.seiko.imageloader.rememberAsyncImagePainter
import com.seiko.imageloader.request.ImageRequestBuilder
import com.seiko.imageloader.request.Options
import com.twidere.services.http.authorization.Authorization
import com.twidere.services.http.config.HttpConfig
import com.twidere.services.http.proxy
Expand All @@ -42,7 +41,6 @@ import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.request.header
import io.ktor.http.Url
import okhttp3.Request

@Composable
Expand All @@ -53,14 +51,16 @@ internal fun rememberNetworkImagePainter(
effects: ImageEffects,
onImageStateChanged: (NetworkImageState) -> Unit
): Painter {
val request = remember(data, effects) {
ImageRequestBuilder()
.data(data)
.addInterceptor(BlurInterceptor(effects))
.components {
add(ProxyKtorUrlFetcher.Factory(authorization, httpConfig))
val request = remember(data, effects.blur) {
ImageRequest {
data(data)
effects.blur?.let {
blur(it.blurRadius)
}
.build()
components {
add(proxyKtorUrlFetcher(data, authorization, httpConfig))
}
}
}
val painter = rememberAsyncImagePainter(request)
LaunchedEffect(painter) {
Expand All @@ -81,50 +81,38 @@ internal fun rememberNetworkImagePainter(
return painter
}

fun ImageLoaderBuilder.commonConfig(): ImageLoaderBuilder {
return this
fun ImageLoaderConfigBuilder.commonConfig() {
interceptor {
addInterceptor(BlurInterceptor())
}
}

expect class BlurInterceptor(effects: ImageEffects) : Interceptor

private class ProxyKtorUrlFetcher(
httpUrl: Url,
httpClient: Lazy<HttpClient>
) : KtorUrlFetcher(httpUrl, httpClient) {
class Factory(
private val authorization: Authorization,
private val httpConfig: HttpConfig,
) : Fetcher.Factory {
override fun create(data: Any, options: Options): Fetcher? {
if (data is Url) return KtorUrlFetcher(
data,
lazy {
val engine = OkHttp.create {
config {
if (httpConfig.proxyConfig.enable &&
httpConfig.proxyConfig.server.isNotEmpty()
) {
proxy(httpConfig.proxyConfig)
}
}
}
HttpClient(engine) {
defaultRequest {
if (authorization.hasAuthorization) {
header(
"Authorization",
authorization.getAuthorizationHeader(
Request.Builder()
.url(data.toString())
.build()
)
)
}
}
}
}
)
return null
private fun proxyKtorUrlFetcher(
data: Any,
authorization: Authorization,
httpConfig: HttpConfig,
) = KtorUrlFetcher.Factory {
val engine = OkHttp.create {
config {
if (httpConfig.proxyConfig.enable &&
httpConfig.proxyConfig.server.isNotEmpty()
) {
proxy(httpConfig.proxyConfig)
}
}
}
HttpClient(engine) {
defaultRequest {
if (authorization.hasAuthorization) {
header(
"Authorization",
authorization.getAuthorizationHeader(
Request.Builder()
.url(data.toString())
.build()
)
)
}
}
}
}
Loading