Skip to content
Open

2.4 #90

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

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

2 changes: 2 additions & 0 deletions app/src/main/java/com/ssimagepicker/app/PickerOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class PickerOptions(
val openCropOptions: Boolean,
val openSystemPicker: Boolean,
val compressImage: Boolean,
val freeSizeCrop: Boolean,
var aspectRatio: AspectRatio?
) : Parcelable {
companion object {
Expand All @@ -40,6 +41,7 @@ data class PickerOptions(
openCropOptions = false,
openSystemPicker = false,
compressImage = false,
freeSizeCrop = false,
aspectRatio = null
)
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/ssimagepicker/app/ui/DemoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ class DemoFragment : Fragment(), View.OnClickListener,
private fun openImagePicker() {
imagePicker
.title("My Picker")
.multipleSelection(pickerOptions.allowMultipleSelection, pickerOptions.maxPickCount)
.showCountInToolBar(pickerOptions.showCountInToolBar)
.showCountInToolBar(pickerOptions.showCountInToolBar)
.showFolder(pickerOptions.showFolders)
.cameraIcon(pickerOptions.showCameraIconInGallery)
.doneIcon(pickerOptions.isDoneIcon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ssimagepicker.app.ui
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.ssimagepicker.app.R
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/ssimagepicker/app/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener,
openPickerOptions()
}
R.id.open_picker_button -> {
pickerOptions = pickerOptions.copy(compressImage = true)
openImagePicker()
}
R.id.open_sheet_button -> {
Expand Down Expand Up @@ -120,8 +121,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener,
.showFolder(pickerOptions.showFolders)
.cameraIcon(pickerOptions.showCameraIconInGallery)
.doneIcon(pickerOptions.isDoneIcon)
.allowCropping(pickerOptions.openCropOptions)
.compressImage(pickerOptions.compressImage)
.compressImage(true)
.allowCropping(false)
.maxImageSize(pickerOptions.maxPickSizeMB)
.extension(pickerOptions.pickExtension)
.aspectRatio(pickerOptions.aspectRatio)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class PickerOptionsBottomSheet : BottomSheetDialogFragment(), View.OnClickListen
openCropOptions = binding.openCropSwitch.isChecked,
openSystemPicker = binding.systemPickerSwitch.isChecked,
compressImage = binding.compressImageSwitch.isChecked,
freeSizeCrop = false,
aspectRatio = null
)
dismiss()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/activity_button"
style="@style/ButtonSelectorStyle"
android:layout_marginTop="@dimen/_6sdp"
android:layout_marginTop="@dimen/_96sdp"
android:onClick="@{clickHandler::onClick}"
android:text="@string/activity_demo"
android:layout_marginStart="@dimen/_12sdp"
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/values-v35/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomSSImagePicker" parent="SSImagePicker">
<item name="ssToolbarBackIcon">@drawable/ic_arrow_back_ios</item>
<item name="ssToolbarDoneTextAppearance">@style/CustomDoneTextAppearance</item>
<item name="ssPickerGridCountLandscape">3</item>
<item name="ssImageSelectIcon">@drawable/ic_baseline_check_circle</item>
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
</style>

<style name="SSImagePickerApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
<!-- Customize your theme here. -->
</style>

</resources>
12 changes: 0 additions & 12 deletions app/src/main/res/xml/file_path.xml

This file was deleted.

2 changes: 1 addition & 1 deletion imagepickerlibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
android:theme="@style/CustomUCrop" />
</application>
<queries>
<intent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ internal suspend fun Context.getImagesList(
}
}





/**
* Extension function to convert Megabyte to Byte
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ class ImagePicker private constructor(
return this
}

/**
* Whether to free size crop option or not.
* The cropping option are only available if the single selection is set or the picture is picked via camera.
*/
fun allowFreeSizeCropping(enable: Boolean): ImagePicker {
pickerConfigManager.getPickerConfig().freeStyleCrop = enable
return this
}

/**
* Whether to open new photo picker for android 11+ or not.
* If the system picker is set to open the all other options except multi selection, max count and pick extension are ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal data class PickerConfig(
var openSystemPicker: Boolean = false,
var compressImage: Boolean = false,
var compressQuality: Int = 75,
var freeStyleCrop: Boolean = false,
var aspectRatio: AspectRatio? = null
) : Parcelable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.util.Log
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -40,7 +41,6 @@ import com.app.imagepickerlibrary.registerActivityResult
import com.app.imagepickerlibrary.replaceFragment
import com.app.imagepickerlibrary.ui.fragment.FolderFragment
import com.app.imagepickerlibrary.ui.fragment.ImageFragment
import com.app.imagepickerlibrary.util.isAtLeast13
import com.app.imagepickerlibrary.viewmodel.ImagePickerViewModel
import com.yalantis.ucrop.UCrop
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -209,6 +209,18 @@ class ImagePickerActivity : AppCompatActivity(), View.OnClickListener {
) == PackageManager.PERMISSION_GRANTED
}

val pickMedia = registerForActivityResult(PickVisualMedia()) { uri ->
// Callback is invoked after the user selects a media item or closes the
// photo picker.
if (uri != null) {
checkForCropping(uri)
viewModel.fetchImagesFromMediaStore()
Log.d("PhotoPicker", "Selected URI: $uri")
} else {
Log.d("PhotoPicker", "No media selected")
}
}

private fun askPermission(vararg permission: String) {
permissionResult.launch(arrayOf(*permission))
}
Expand Down Expand Up @@ -274,11 +286,15 @@ class ImagePickerActivity : AppCompatActivity(), View.OnClickListener {
}
return UCrop.Options().apply {
setFreeStyleCropEnabled(pickerConfig.openCropOptions)
setHideBottomControls(!pickerConfig.openCropOptions)
setFreeStyleCropEnabled(pickerConfig.freeStyleCrop)
setHideBottomControls(true)
setToolbarColor(getColorAttribute(R.attr.ssUCropToolbarColor))
setStatusBarColor(getColorAttribute(R.attr.ssUCropStatusBarColor))
setToolbarWidgetColor(getColorAttribute(R.attr.ssUCropToolbarWidgetColor))
setActiveControlsWidgetColor(getColorAttribute(R.attr.ssUCropActiveControlWidgetColor))
if (pickerConfig.freeStyleCrop.not()) {
withAspectRatio(1f, 1f)
}
if (pickerConfig.compressImage) {
setCompressionQuality(pickerConfig.compressQuality)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ internal fun isAtLeast13(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
}

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
internal fun isAtLeast14(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE
}

/**
* Utility function to check if system picker is available or not on Android 11+.
* The function is provided by google to check whether the photo picker is available or not
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.app.imagepickerlibrary.viewmodel

import android.app.Application
import android.net.Uri
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.app.imagepickerlibrary.getFileUri
Expand All @@ -11,6 +12,7 @@ import com.app.imagepickerlibrary.model.Image
import com.app.imagepickerlibrary.model.PickerConfig
import com.app.imagepickerlibrary.model.Result
import com.app.imagepickerlibrary.util.compress
import com.app.imagepickerlibrary.util.isAtLeast14
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -57,10 +59,15 @@ internal class ImagePickerViewModel(application: Application) : AndroidViewModel
}

private suspend fun fetchImageList(): List<Image> {
val config = pickerConfig.value
val (selection, selectionArgs) = config.generateSelectionArguments()
val context = (getApplication() as Application).applicationContext
return context.getImagesList(selection, selectionArgs)
if (isAtLeast14()) {
return context.getImagesList(null, null)
} else {
val config = pickerConfig.value
val (selection, selectionArgs) = config.generateSelectionArguments()
return context.getImagesList(selection, selectionArgs)
}

}

fun getFoldersFromImages(images: List<Image>) {
Expand Down
5 changes: 5 additions & 0 deletions imagepickerlibrary/src/main/res/values-v35/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomUCrop" parent="Theme.AppCompat.Light.NoActionBar">
</style>
</resources>
4 changes: 4 additions & 0 deletions imagepickerlibrary/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@
<item name="android:gravity">center</item>
<item name="android:padding">@dimen/_14sdp</item>
</style>

<style name="CustomUCrop" parent="Theme.AppCompat.Light.NoActionBar">

</style>
</resources>