From 1a2cf718d5e19bc1c190d7428e7eb67866cae8d7 Mon Sep 17 00:00:00 2001 From: zhujiang2 Date: Mon, 6 Dec 2021 09:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 ++++---- app/src/main/java/com/zj/test/MainActivity.kt | 29 ++++++++++--------- banner/build.gradle | 16 +++++----- .../main/java/com/zj/banner/BannerPager.kt | 13 +++++---- .../main/java/com/zj/banner/ui/BannerCard.kt | 2 ++ .../zj/banner/ui/indicator/NumberIndicator.kt | 2 +- .../java/com/zj/banner/utils/ImageLoader.kt | 10 +++++-- build.gradle | 8 ++--- gradle/wrapper/gradle-wrapper.properties | 4 +-- settings.gradle | 1 - 10 files changed, 54 insertions(+), 43 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a21dca3..acbc519 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,13 +4,12 @@ plugins { } android { - compileSdk 30 - buildToolsVersion "30.0.3" + compileSdk 31 defaultConfig { applicationId "com.zj.test" - minSdk 21 - targetSdk 30 + minSdk 24 + targetSdk 31 versionCode 1 versionName "1.0" @@ -37,19 +36,18 @@ android { } composeOptions { kotlinCompilerExtensionVersion compose_version - kotlinCompilerVersion '1.5.21' } } dependencies { - implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.material:material:$compose_version" implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' - implementation 'androidx.activity:activity-compose:1.3.1' + implementation 'androidx.activity:activity-compose:1.4.0' implementation "androidx.compose.runtime:runtime-livedata:$compose_version" //implementation 'com.github.zhujiang521:Banner:1.3.3' implementation project(path: ':banner') diff --git a/app/src/main/java/com/zj/test/MainActivity.kt b/app/src/main/java/com/zj/test/MainActivity.kt index 9643f66..0749323 100644 --- a/app/src/main/java/com/zj/test/MainActivity.kt +++ b/app/src/main/java/com/zj/test/MainActivity.kt @@ -31,20 +31,23 @@ class MainActivity : ComponentActivity(), SensorEventListener { super.onCreate(savedInstanceState) transparentStatusBar() setAndroidNativeLightStatusBar() - mSensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager - // 陀螺仪传感器 - mMagneticSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) - - mSensorManager.registerListener(this, mMagneticSensor, SensorManager.SENSOR_DELAY_GAME) - +// mSensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager +// // 陀螺仪传感器 +// mMagneticSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) +// +// mSensorManager.registerListener(this, mMagneticSensor, SensorManager.SENSOR_DELAY_GAME) +// +// setContent { +// BannerTheme { +// val xState by viewModel.xState.observeAsState(0f) +// val yState by viewModel.yState.observeAsState(0f) +// Surface(color = MaterialTheme.colors.background) { +// ThreeDImage(xState, yState) +// } +// } +// } setContent { - BannerTheme { - val xState by viewModel.xState.observeAsState(0f) - val yState by viewModel.yState.observeAsState(0f) - Surface(color = MaterialTheme.colors.background) { - ThreeDImage(xState, yState) - } - } + BannerTest() } } diff --git a/banner/build.gradle b/banner/build.gradle index 3e42e41..e392f18 100644 --- a/banner/build.gradle +++ b/banner/build.gradle @@ -17,7 +17,7 @@ afterEvaluate { // You can then customize attributes of the publication as shown below. groupId = 'com.zj.banner' artifactId = 'banner' - version = '1.0.0' + version = '1.1.0' } // // Creates a Maven publication called “debug”. // debug(MavenPublication) { @@ -33,12 +33,11 @@ afterEvaluate { } android { - compileSdk 30 - buildToolsVersion "30.0.3" + compileSdk 31 defaultConfig { - minSdk 21 - targetSdk 30 + minSdk 24 + targetSdk 31 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -63,14 +62,15 @@ android { } composeOptions { kotlinCompilerExtensionVersion compose_version - kotlinCompilerVersion '1.4.31' } } dependencies { implementation "androidx.compose.material:material:$compose_version" - def accompanist_version = "0.12.0" + + def accompanist_coil_version = "0.15.0" + def accompanist_version = "0.21.4-beta" api "com.google.accompanist:accompanist-pager:$accompanist_version" - api "com.google.accompanist:accompanist-coil:$accompanist_version" + api "com.google.accompanist:accompanist-coil:$accompanist_coil_version" api "com.google.accompanist:accompanist-insets:$accompanist_version" } \ No newline at end of file diff --git a/banner/src/main/java/com/zj/banner/BannerPager.kt b/banner/src/main/java/com/zj/banner/BannerPager.kt index 1577bc7..23b51f7 100644 --- a/banner/src/main/java/com/zj/banner/BannerPager.kt +++ b/banner/src/main/java/com/zj/banner/BannerPager.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier +import coil.annotation.ExperimentalCoilApi import com.google.accompanist.pager.ExperimentalPagerApi import com.google.accompanist.pager.HorizontalPager import com.google.accompanist.pager.PagerState @@ -33,7 +34,7 @@ private const val TAG = "BannerPager" * [Indicator] 即可。 * @param onBannerClick Banner 点击事件的回调 */ -@OptIn(ExperimentalPagerApi::class) +@OptIn(ExperimentalPagerApi::class, ExperimentalCoilApi::class) @Composable fun BannerPager( modifier: Modifier = Modifier, @@ -46,18 +47,20 @@ fun BannerPager( throw NullPointerException("items is not null") } - val pagerState = rememberPagerState(pageCount = items.size) + val pagerState = rememberPagerState() if (config.repeat) { StartBanner(pagerState, config.intervalTime) } Box(modifier = modifier.height(config.bannerHeight)) { - HorizontalPager(state = pagerState) { page -> + HorizontalPager(count = items.size, state = pagerState) { page -> val item = items[page] BannerCard( bean = item, - modifier = Modifier.fillMaxSize().padding(config.bannerImagePadding), + modifier = Modifier + .fillMaxSize() + .padding(config.bannerImagePadding), shape = config.shape, contentScale = config.contentScale ) { @@ -74,7 +77,7 @@ var mTimer: Timer? = null var mTimerTask: TimerTask? = null -@OptIn(ExperimentalPagerApi::class) +@ExperimentalPagerApi @Composable fun StartBanner(pagerState: PagerState, intervalTime: Long) { val coroutineScope = rememberCoroutineScope() diff --git a/banner/src/main/java/com/zj/banner/ui/BannerCard.kt b/banner/src/main/java/com/zj/banner/ui/BannerCard.kt index 7cad5e2..e794a72 100644 --- a/banner/src/main/java/com/zj/banner/ui/BannerCard.kt +++ b/banner/src/main/java/com/zj/banner/ui/BannerCard.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp +import coil.annotation.ExperimentalCoilApi import com.zj.banner.model.BaseBannerBean import com.zj.banner.utils.ImageLoader @@ -20,6 +21,7 @@ import com.zj.banner.utils.ImageLoader * @param contentScale 纵横比缩放 * @param onBannerClick Banner 图片点击事件 */ +@ExperimentalCoilApi @Composable fun BannerCard( bean: T, diff --git a/banner/src/main/java/com/zj/banner/ui/indicator/NumberIndicator.kt b/banner/src/main/java/com/zj/banner/ui/indicator/NumberIndicator.kt index d8e4901..2c9e8a4 100644 --- a/banner/src/main/java/com/zj/banner/ui/indicator/NumberIndicator.kt +++ b/banner/src/main/java/com/zj/banner/ui/indicator/NumberIndicator.kt @@ -37,7 +37,7 @@ class NumberIndicator( override var gravity: Int = BottomRight, ) : Indicator() { - @OptIn(ExperimentalPagerApi::class) + @ExperimentalPagerApi @Composable override fun DrawIndicator(pagerState: PagerState) { val alignment: Alignment = when (gravity) { diff --git a/banner/src/main/java/com/zj/banner/utils/ImageLoader.kt b/banner/src/main/java/com/zj/banner/utils/ImageLoader.kt index 1a8ae1e..34055f7 100644 --- a/banner/src/main/java/com/zj/banner/utils/ImageLoader.kt +++ b/banner/src/main/java/com/zj/banner/utils/ImageLoader.kt @@ -9,7 +9,9 @@ import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource -import com.google.accompanist.coil.rememberCoilPainter +import coil.annotation.ExperimentalCoilApi +import coil.compose.LocalImageLoader +import coil.compose.rememberImagePainter private const val TAG = "ImageLoader" @@ -20,6 +22,7 @@ private const val TAG = "ImageLoader" * @param modifier 修饰符 * @param contentScale 使用可选的scale参数来确定要使用的纵横比缩放 */ +@ExperimentalCoilApi @Composable fun ImageLoader( data: Any?, @@ -30,7 +33,10 @@ fun ImageLoader( is String -> { val painter = if (data.contains("https://") || data.contains("http://")) { Log.d(TAG, "PostCardPopular: 加载网络图片") - rememberCoilPainter(data) + rememberImagePainter( + data = data, + imageLoader = LocalImageLoader.current, + ) } else { Log.d(TAG, "PostCardPopular: 加载本地图片") val bitmap = BitmapFactory.decodeFile(data) diff --git a/build.gradle b/build.gradle index 04a38a5..2d89749 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,17 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { - compose_version = '1.0.1' + compose_version = '1.1.0-beta04' + kotlin_version = '1.6.0' } repositories { google() mavenCentral() - maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:7.0.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" + classpath 'com.android.tools.build:gradle:7.0.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 663abec..6d61131 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Jul 18 09:35:20 CST 2021 +#Mon Dec 06 09:26:31 CST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index da0d02d..4fe8b38 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,6 @@ dependencyResolutionManagement { repositories { google() mavenCentral() - maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://jitpack.io' } } }