Skip to content

Commit

Permalink
feat: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoanglam committed Nov 3, 2023
1 parent 7f1b1cc commit 12346c1
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions .idea/modules.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
classpath 'com.android.tools.build:gradle:8.1.2'
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
6 changes: 2 additions & 4 deletions example/build.gradle
Expand Up @@ -2,12 +2,10 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 34
buildToolsVersion "34.0.0"

defaultConfig {
applicationId "com.imagepicker.example"
minSdkVersion 23
compileSdk 34
targetSdkVersion 34
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -37,7 +35,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'com.github.bumptech.glide:glide:4.15.1'
implementation project(path: ':imagepicker')
}
8 changes: 4 additions & 4 deletions example/src/main/java/com/imagepicker/example/MainActivity.kt
Expand Up @@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity() {

private fun start() {
val folderMode = binding.folderModeSwitch.isChecked
val multiSelectMode = binding.multiSelectModeSwitch.isChecked
val singleSelectMode = binding.singleSelectModeSwitch.isChecked
val cameraMode = binding.cameraModeSwitch.isChecked
val showCamera = binding.showCameraSwitch.isChecked
val selectAllEnabled = binding.showSelectAllSwitch.isChecked
Expand All @@ -72,7 +72,7 @@ class MainActivity : AppCompatActivity() {

val config = ImagePickerConfig(
isCameraMode = cameraMode,
isMultiSelectMode = multiSelectMode,
isSingleSelectMode = singleSelectMode,
isFolderMode = folderMode,
isShowCamera = showCamera,
isSelectAllEnabled = selectAllEnabled,
Expand Down Expand Up @@ -120,7 +120,7 @@ class MainActivity : AppCompatActivity() {

private fun launchFragment() {
val folderMode = binding.folderModeSwitch.isChecked
val multiSelectMode = binding.multiSelectModeSwitch.isChecked
val singleSelectMode = binding.singleSelectModeSwitch.isChecked
val cameraMode = binding.cameraModeSwitch.isChecked
val showCamera = binding.showCameraSwitch.isChecked
val selectAllEnabled = binding.showSelectAllSwitch.isChecked
Expand All @@ -130,7 +130,7 @@ class MainActivity : AppCompatActivity() {

val config = ImagePickerConfig(
isCameraMode = cameraMode,
isMultiSelectMode = multiSelectMode,
isSingleSelectMode = singleSelectMode,
isFolderMode = folderMode,
isShowCamera = showCamera,
isSelectAllEnabled = selectAllEnabled,
Expand Down
8 changes: 4 additions & 4 deletions example/src/main/res/layout/activity_main.xml
Expand Up @@ -29,13 +29,13 @@
android:text="Folder Mode" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/multiSelectModeSwitch"
android:id="@+id/singleSelectModeSwitch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:checked="false"
android:gravity="right"
android:text="Multiple Mode" />
android:text="Single Mode" />
</LinearLayout>

<LinearLayout
Expand Down Expand Up @@ -117,7 +117,7 @@
android:layout_weight="1"
android:checked="true"
android:gravity="right"
android:text="Enable Image Transition" />
android:text="Image Transition" />
</LinearLayout>

<Button
Expand Down
13 changes: 6 additions & 7 deletions imagepicker/build.gradle
Expand Up @@ -4,10 +4,9 @@ apply plugin: 'kotlin-parcelize'
apply plugin: 'maven-publish'

android {
compileSdkVersion 34

defaultConfig {
minSdkVersion 21
compileSdk 34
targetSdkVersion 34
}

Expand Down Expand Up @@ -41,13 +40,13 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation "androidx.activity:activity-ktx:1.8.0-alpha06"
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation "androidx.activity:activity-ktx:1.8.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.core:core-ktx:1.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.bumptech.glide:glide:4.15.1'
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ fun Context.getHexColorFromResId(resId: Int): String {
@Parcelize
class ImagePickerConfig(
var isCameraMode: Boolean = false,
var isMultiSelectMode: Boolean = true,
var isSingleSelectMode: Boolean = false,
var isFolderMode: Boolean = true,
var isShowCamera: Boolean = true,
var isAlwaysShowDoneButton: Boolean = true,
Expand Down
Expand Up @@ -86,7 +86,7 @@ class ImagePickerAdapter(
override fun onBindViewHolder(viewHolder: ImageViewHolder, position: Int) {
val image = images[position]
val selectedIndex = ImageHelper.findImageIndex(image, selectedImages)
val isSelected = config.isMultiSelectMode && selectedIndex != -1
val isSelected = !config.isSingleSelectMode && selectedIndex != -1

GlideHelper.loadImage(viewHolder.image, image.uri)
setupItemForeground(viewHolder.image, isSelected)
Expand Down Expand Up @@ -120,7 +120,9 @@ class ImagePickerAdapter(
}

private fun selectOrRemoveImage(image: Image, position: Int) {
if (config.isMultiSelectMode) {
if (config.isSingleSelectMode) {
imageSelectListener.onSingleModeImageSelected(image)
} else {
val selectedIndex = ImageHelper.findImageIndex(image, selectedImages)
if (selectedIndex != -1) {
selectedImages.removeAt(selectedIndex)
Expand All @@ -139,8 +141,6 @@ class ImagePickerAdapter(
}
}
imageSelectListener.onSelectedImagesChanged(selectedImages)
} else {
imageSelectListener.onSingleModeImageSelected(image)
}
}

Expand Down
Expand Up @@ -57,6 +57,11 @@ class ImagePickerActivity : AppCompatActivity(), OnFolderClickListener, OnImageS
config,
object : OnImageReadyListener {
override fun onImageReady(images: ArrayList<Image>) {
if (config.isSingleSelectMode || images.isNotEmpty()) {
onSingleModeImageSelected(images.first())
return
}

fetchDataWithPermission()
}

Expand Down Expand Up @@ -246,7 +251,7 @@ class ImagePickerActivity : AppCompatActivity(), OnFolderClickListener, OnImageS
private fun configSelectAllButtons(
bucketId: Long?, images: ArrayList<Image>?, selectedImages: ArrayList<Image>?
) {
if (!config.isMultiSelectMode) return
if (config.isSingleSelectMode) return

val state = ImageHelper.getBucketSelectionState(
images, selectedImages, bucketId
Expand Down
Expand Up @@ -89,13 +89,13 @@ class ImagePickerViewModel(application: Application) : AndroidViewModel(applicat

while (cursor.moveToNext()) {
val id = cursor.getLong(idColumn)
val name = cursor.getString(nameColumn)
val name = cursor.getStringOrNull(nameColumn) ?: ""
val bucketId = cursor.getLong(bucketIdColumn)
val bucketName = cursor.getStringOrNull(bucketNameColumn) ?: ""

val uri = ContentUris.withAppendedId(imageCollectionUri, id)

val image = Image(uri, name, bucketId, bucketName)
val image = Image(uri, name.toString(), bucketId, bucketName)
images.add(image)
}
cursor.close()
Expand Down

0 comments on commit 12346c1

Please sign in to comment.