Skip to content

Commit

Permalink
更新依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujiang2 committed Dec 6, 2021
1 parent f9fd5b7 commit 1a2cf71
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 43 deletions.
12 changes: 5 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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')
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/com/zj/test/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
16 changes: 8 additions & 8 deletions banner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"
Expand All @@ -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"
}
13 changes: 8 additions & 5 deletions banner/src/main/java/com/zj/banner/BannerPager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +34,7 @@ private const val TAG = "BannerPager"
* [Indicator] 即可。
* @param onBannerClick Banner 点击事件的回调
*/
@OptIn(ExperimentalPagerApi::class)
@OptIn(ExperimentalPagerApi::class, ExperimentalCoilApi::class)
@Composable
fun <T : BaseBannerBean> BannerPager(
modifier: Modifier = Modifier,
Expand All @@ -46,18 +47,20 @@ fun <T : BaseBannerBean> 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
) {
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions banner/src/main/java/com/zj/banner/ui/BannerCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,6 +21,7 @@ import com.zj.banner.utils.ImageLoader
* @param contentScale 纵横比缩放
* @param onBannerClick Banner 图片点击事件
*/
@ExperimentalCoilApi
@Composable
fun <T : BaseBannerBean> BannerCard(
bean: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions banner/src/main/java/com/zj/banner/utils/ImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -20,6 +22,7 @@ private const val TAG = "ImageLoader"
* @param modifier 修饰符
* @param contentScale 使用可选的scale参数来确定要使用的纵横比缩放
*/
@ExperimentalCoilApi
@Composable
fun ImageLoader(
data: Any?,
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://jitpack.io' }
}
}
Expand Down

0 comments on commit 1a2cf71

Please sign in to comment.