Skip to content

Commit

Permalink
[commonize] #496 Commonize :app:image-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Jul 28, 2024
1 parent a67ce3c commit 9c0f3fa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 79 deletions.
79 changes: 3 additions & 76 deletions app/shared/image-viewer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,103 +1,30 @@
@file:Suppress("UnstableApiUsage")
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.compose")
id("org.jetbrains.compose")
// 注意! 前几个插件顺序非常重要, 调整后可能导致 compose multiplatform resources 生成错误
`flatten-source-sets`
`ani-mpp-lib-targets`
`ani-compose-hmpp`

kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.atomicfu")
}

extra.set("ani.jvm.target", 17)

kotlin {
androidTarget()
jvm("desktop")

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}

sourceSets {
// Workaround for MPP compose bug, don't change
removeIf { it.name == "androidAndroidTestRelease" }
removeIf { it.name == "androidTestFixtures" }
removeIf { it.name == "androidTestFixturesDebug" }
removeIf { it.name == "androidTestFixturesRelease" }
}
}

compose.resources {
packageOfResClass = "me.him188.ani.app.image.viewer"
generateResClass = always
}

composeCompiler {
enableStrongSkippingMode = true
}


kotlin {
sourceSets.commonMain.dependencies {
api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.serialization.json)
implementation(libs.atomicfu) // room runtime

// Compose
api(compose.foundation)
api(compose.animation)
api(compose.ui)
api(compose.material3)
api(compose.materialIconsExtended)
api(compose.runtime)
implementation(compose.components.resources)
}

sourceSets.androidMain.dependencies {
api(libs.kotlinx.coroutines.android)

api(libs.androidx.compose.ui.tooling.preview)
api(libs.androidx.compose.material3)
}

}

// compose bug
tasks.named("generateComposeResClass") {
dependsOn("generateResourceAccessorsForAndroidUnitTest")
}
tasks.withType(KotlinCompilationTask::class) {
dependsOn("generateComposeResClass")
dependsOn("generateResourceAccessorsForAndroidRelease")
dependsOn("generateResourceAccessorsForAndroidUnitTest")
dependsOn("generateResourceAccessorsForAndroidUnitTestRelease")
dependsOn("generateResourceAccessorsForAndroidUnitTestDebug")
dependsOn("generateResourceAccessorsForAndroidDebug")
}

android {
namespace = "me.him188.ani"
compileSdk = getIntProperty("android.compile.sdk")
defaultConfig {
minSdk = getIntProperty("android.min.sdk")
}
buildTypes.getByName("release") {
isMinifyEnabled = false // shared 不能 minify, 否则构建 app 会失败
isShrinkResources = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
*sharedAndroidProguardRules(),
)
}
buildFeatures {
compose = true
}
namespace = "me.him188.ani.image.viewer"
}
1 change: 1 addition & 0 deletions app/shared/image-viewer/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.mpp.applyDefaultHierarchyTemplate=false
1 change: 0 additions & 1 deletion app/shared/image-viewer/src/commonMain/kotlin/package.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.him188.ani.utils.platform.currentTimeMillis
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.absoluteValue
Expand Down Expand Up @@ -259,7 +260,7 @@ private suspend fun PointerInputScope.detectTransformGestures(
var lockedToPanZoom = false

awaitFirstDown(requireUnconsumed = false)
val t0 = System.currentTimeMillis()
val t0 = currentTimeMillis()
var releasedEvent: PointerEvent? = null
var moveCount = 0
// 这里开始事件
Expand Down Expand Up @@ -312,7 +313,7 @@ private suspend fun PointerInputScope.detectTransformGestures(
}
} while (!canceled && event.changes.fastAny { it.pressed })

var t1 = System.currentTimeMillis()
var t1 = currentTimeMillis()
val dt = t1 - t0
val dlt = t1 - lastReleaseTime

Expand Down

0 comments on commit 9c0f3fa

Please sign in to comment.