Skip to content

Commit

Permalink
1、移除 accompanist pager,替换为 compose pager
Browse files Browse the repository at this point in the history
2、升级 compose-bom 到 2023.04.00、kotlinCompiler 到 1.4.4
3、升级 accompanist 到 0.30.0
4、升级 activity-compose 到 1.7.0
5、升级 coil 到 2.3.0
  • Loading branch information
leavesCZY committed Apr 7, 2023
1 parent 472cd34 commit 0b47962
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- 适配到 Android 13
- 完全用 Kotlin & Jetpack Compose 实现
- 支持精细自定义主题,默认提供了 日间 和 夜间 两套主题
- 支持精细自定义主题,默认提供日夜间两套主题
- 支持精准筛选图片类型,只显示想要的图片类型
- 支持详细获取图片信息,一共包含 uri、displayName、mimeType、width、height、orientation、size、path、bucketId、bucketDisplayName 十个属性值
- 支持开启拍照功能,一共包含 NothingCaptureStrategy、FileProviderCaptureStrategy、MediaStoreCaptureStrategy、SmartCaptureStrategy 四种拍照策略,可以自由选择是否要申请权限
Expand All @@ -15,9 +15,8 @@
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](https://user-images.githubusercontent.com/30774063/221350097-6ef7343a-379a-4715-a86f-ea9e67674560.jpg) | ![](https://user-images.githubusercontent.com/30774063/221350113-251f2e7a-27dc-434b-b578-95e79267aae3.jpg) | ![](https://user-images.githubusercontent.com/30774063/221350303-07c065da-de5b-4550-ad89-92a1bfffba4d.jpg) |


实现思路请看:[Jetpack Compose 实现一个图片选择框架](https://juejin.cn/post/7108420791502372895)

Apk 下载体验请看:[Releases](https://github.com/leavesCZY/Matisse/releases)

接入指南请看:[Wiki](https://github.com/leavesCZY/Matisse/wiki/%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97)
接入指南请看:[Wiki](https://github.com/leavesCZY/Matisse/wiki/%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97)
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ android {

dependencies {
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.4"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation "com.google.android.material:material:1.8.0"
implementation "io.coil-kt:coil-compose:2.2.2"
implementation "io.coil-kt:coil-gif:2.2.2"
def coilVersion = "2.3.0"
implementation "io.coil-kt:coil-gif:$coilVersion"
implementation "io.coil-kt:coil-compose:$coilVersion"
implementation project(path: ":matisse")
}
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选取数量"
android:text="数量"
android:textAllCaps="false" />

<RadioGroup
android:id="@+id/radioGroupMaxSelectable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:orientation="horizontal">

<com.google.android.material.radiobutton.MaterialRadioButton
Expand Down Expand Up @@ -72,20 +73,21 @@
android:id="@+id/radioGroupSupportGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:orientation="horizontal">

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/rbSupportGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="支持" />
android:text="包含" />

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/rbNoSupportGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="不支持" />
android:text="不包含" />

</RadioGroup>

Expand All @@ -108,6 +110,7 @@
android:id="@+id/radioGroupEnableCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:orientation="vertical">

<com.google.android.material.radiobutton.MaterialRadioButton
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "org.jetbrains.kotlin.android" version "1.7.20" apply false
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
}

task clean(type: Delete) {
Expand Down
17 changes: 8 additions & 9 deletions matisse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion "1.3.2"
kotlinCompilerExtensionVersion "1.4.4"
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += [
"-Xopt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-Xopt-in=com.google.accompanist.pager.ExperimentalPagerApi",
"-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi",
]
}
namespace "github.leavesczy.matisse"
}

dependencies {
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.4"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.activity:activity-compose:1.6.1"
def composeBom = platform("androidx.compose:compose-bom:2023.01.00")
implementation "androidx.activity:activity-compose:1.7.0"
def composeBom = platform("androidx.compose:compose-bom:2023.04.00")
implementation composeBom
androidTestImplementation composeBom
implementation "androidx.compose.material3:material3"
implementation "androidx.compose.material:material-icons-extended"
def accompanistVersion = "0.28.0"
def accompanistVersion = "0.30.0"
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion"
implementation "com.google.accompanist:accompanist-pager:$accompanistVersion"
def coilVersion = "2.2.2"
def coilVersion = "2.3.0"
implementation "io.coil-kt:coil-gif:$coilVersion"
implementation "io.coil-kt:coil-compose:$coilVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal class MatisseViewModel(application: Application, private val matisse: M
visible = true,
initialPage = 0,
selectedResources = selectedResources,
previewResources = selectedResources,
previewResources = selectedResources
)
}
}
Expand Down Expand Up @@ -232,11 +232,7 @@ internal class MatisseViewModel(application: Application, private val matisse: M

fun dismissPreviewPage() {
if (matissePreviewViewState.visible) {
matissePreviewViewState = matissePreviewViewState.copy(
visible = false,
selectedResources = emptyList(),
previewResources = emptyList()
)
matissePreviewViewState = matissePreviewViewState.copy(visible = false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
Expand All @@ -23,9 +26,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.PagerState
import com.google.accompanist.pager.rememberPagerState
import github.leavesczy.matisse.R
import github.leavesczy.matisse.internal.logic.MatisseViewModel
import github.leavesczy.matisse.internal.utils.clickableNoRipple
Expand Down Expand Up @@ -79,20 +79,22 @@ internal fun MatissePreviewPage(viewModel: MatisseViewModel) {
.clickableNoRipple {
controllerVisible = !controllerVisible
},
count = previewResources.size,
state = pagerState,
pageCount = previewResources.size,
pageSpacing = 20.dp,
verticalAlignment = Alignment.CenterVertically,
key = { index ->
previewResources[index].key
}
) { pageIndex ->
val mediaResource = previewResources[pageIndex]
AsyncImage(
modifier = Modifier
.align(alignment = Alignment.Center)
.verticalScroll(state = rememberScrollState())
.fillMaxWidth(),
.fillMaxSize()
.verticalScroll(state = rememberScrollState()),
model = mediaResource.uri,
contentScale = ContentScale.FillWidth,
alignment = Alignment.Center,
contentDescription = mediaResource.displayName
)
}
Expand Down

0 comments on commit 0b47962

Please sign in to comment.