Skip to content

Commit

Permalink
Merge pull request #8 from NicosNicolaou16/version2.3.0
Browse files Browse the repository at this point in the history
Version 2.3.0
  • Loading branch information
NicosNicolaou16 authored Dec 7, 2024
2 parents 8eeb8ea + 8ada9ce commit c44f963
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

2 changes: 1 addition & 1 deletion ImagePickerAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ afterEvaluate {
register<MavenPublication>("release") {
groupId = "com.github.NicosNicolaou16"
artifactId = "ImagePickerAndroid"
version = "2.2.1"
version = "2.3.0"
from(components["release"])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.provider.MediaStore
import android.provider.Settings
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.IntRange
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.nicos.imagepickerandroid.utils.image_helper_methods.ImageHelperMethods
Expand Down Expand Up @@ -284,14 +286,38 @@ data class ImagePicker(
if (permissionsHelper?.isPermissionGranted(it) == true)
takeAPhotoWithCameraResultLauncher?.launch(this)
else {
permissionsHelper?.activityResultLauncherPermissionActivity?.launch(Manifest.permission.CAMERA)
if (ActivityCompat.shouldShowRequestPermissionRationale(
it,
Manifest.permission.CAMERA
)
) {
it.startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", it.packageName, null)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
} else {
permissionsHelper?.activityResultLauncherPermissionActivity?.launch(Manifest.permission.CAMERA)

}
}
}
fragment?.let {
if (permissionsHelper?.isPermissionGranted(it) == true)
takeAPhotoWithCameraResultLauncher?.launch(this)
else {
permissionsHelper?.activityResultLauncherPermissionFragment?.launch(Manifest.permission.CAMERA)
if (ActivityCompat.shouldShowRequestPermissionRationale(
it.requireActivity(),
Manifest.permission.CAMERA
)
) {
it.startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", it.context?.packageName, null)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
} else {
permissionsHelper?.activityResultLauncherPermissionFragment?.launch(Manifest.permission.CAMERA)

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package com.nicos.imagepickerandroid.image_picker

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.provider.Settings
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.IntRange
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale
import com.nicos.imagepickerandroid.utils.image_helper_methods.ImageHelperMethods
import com.nicos.imagepickerandroid.utils.image_helper_methods.ScaleBitmapModel
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -289,17 +301,26 @@ fun CameraPermission() {
permissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted ->
if (isGranted) {
takeCameraImage?.launch(null)
}
if (isGranted) takeCameraImage?.launch(null)
}
}

/**
* This method is calling from listener to pick single image from camera
* */
fun takeSingleCameraImage() {
permissionLauncher?.launch(Manifest.permission.CAMERA)
fun takeSingleCameraImage(context: Context) {
if (shouldShowRequestPermissionRationale(
context as Activity,
Manifest.permission.CAMERA
)
) {
context.startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", context.packageName, null)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
} else {
permissionLauncher?.launch(Manifest.permission.CAMERA)
}
}

/**
Expand Down Expand Up @@ -347,8 +368,19 @@ fun TakeSingleCameraImageWithBase64Value(
/**
* This method is calling from listener to pick single image from camera with base64 values
* */
fun takeSingleCameraImageWithBase64Value() {
takeCameraImageWithBase64Value?.launch(null)
fun takeSingleCameraImageWithBase64Value(context: Context) {
if (shouldShowRequestPermissionRationale(
context as Activity,
Manifest.permission.CAMERA
)
) {
context.startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", context.packageName, null)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
} else {
takeCameraImageWithBase64Value?.launch(null)
}
}

/**
Expand Down
62 changes: 39 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
# Image Picker Android

This library built to give to other developers an easy way to implement the image picker in Android
application with latest Android technologies. Its supports Activity, Fragment with XML and Jetpack Compose.<br />
Support me and I will appreciate if you provide me your feedback(s).<br />
Note: The example project doesn't contain all the examples for all methods.

The library contain/features:

- Picker for single image from gallery
- Picker for multiple images from gallery (up to 9 images)
- Take single image from camera (handled permission)
- Video Picker
- Support for the base64 value and scale (resize) are only for image
- All the previous features supported on Jetpack Compose too
- New updates coming soon and tell me your suggestions...
This library is built to provide other developers with an easy way to implement an image picker in
Android applications using the latest Android technologies. It supports Activities, Fragments with
XML, and Jetpack Compose.
Support me, and I would appreciate any feedback you provide. <br />
Note: The example project does not include examples for all methods.

The library contains/features:

- Picker for a single image from the gallery.
- Picker for multiple images from the gallery (up to 9 images).
- Camera picker for a single image (with permission handling - manage the scenario where camera
permission is permanently denied by directing the user to the app settings to modify the
permission).
- Video picker.
- Retrieve the base64 value.
- Image scaling (resize) – available only for images.
- All of the above features are also supported in Jetpack Compose.
- New updates coming soon! Feel free to share your suggestions.

Reasons to use this library

- It supports both Activity and Fragment with XML, as well as Jetpack Compose, ensuring compatibility with various Android development approaches.
- The library provides a user-friendly way to integrate image picking functionalities, saving time and effort.
- It offers advanced features like base64 encoding support and image scaling, enhancing your app's image handling capabilities.

### Versioning

Gradle Version 8.7.2 <br />
Gradle Version 8.7.3 <br />
Kotlin Version 2.1.0 <br />
JDK Version 17 <br />
Minimum SDK 24 <br />
Expand All @@ -26,16 +36,22 @@ Build Tool Version 35 <br />

## IMPORTANT NOTE

THE BETA RELEASES MAYBE CONTAIN MAJOR/MINOR CHANGES
THE BETA RELEASES MAY CONTAIN MAJOR OR MINOR CHANGES. <br /> <br />

> [!IMPORTANT]
> Breaking changes for the version 2.3.0 <br /> <br />
> `takeSingleCameraImage()` changed to `takeSingleCameraImage(context = context)` <br /> <br />
> `takeSingleCameraImageWithBase64Value()` changed to
`takeSingleCameraImageWithBase64Value(context = context)`

## Basic Configuration
## Basic Configuration (Gradle Dependencies)

[![](https://jitpack.io/v/NicosNicolaou16/ImagePickerAndroid.svg)](https://jitpack.io/#NicosNicolaou16/ImagePickerAndroid)

### Groovy

```Groovy
implementation 'com.github.NicosNicolaou16:ImagePickerAndroid:2.2.1'
implementation 'com.github.NicosNicolaou16:ImagePickerAndroid:2.3.0'
```

```Groovy
Expand All @@ -49,7 +65,7 @@ allprojects {
### Kotlin DSL

```Kotlin
implementation("com.github.NicosNicolaou16:ImagePickerAndroid:2.2.1")
implementation("com.github.NicosNicolaou16:ImagePickerAndroid:2.3.0")
```

```Kotlin
Expand All @@ -67,7 +83,7 @@ dependencyResolutionManagement {
```toml
[versions]
# other versions here...
imagePickerAndroid = "2.2.1"
imagePickerAndroid = "2.3.0"

[libraries]
# other libraries here...
Expand All @@ -88,7 +104,7 @@ dependencyResolutionManagement {
}
```

## Standard Configuration
## Standard Configuration (XML)

### Step 1 - Get Instance

Expand Down Expand Up @@ -264,9 +280,9 @@ pickMultipleImages()

pickMultipleImagesWithBase64Values()

takeSingleCameraImage()
takeSingleCameraImage(context = context)

takeCameraImageWithBase64Value()
takeSingleCameraImageWithBase64Value(context = context)

pickSingleVideo()
```
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.7.2" apply false
id("com.android.library") version "8.7.2" apply false
id("com.android.application") version "8.7.3" apply false
id("com.android.library") version "8.7.3" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}
6 changes: 3 additions & 3 deletions imagepickerandroidcompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ android {
dependencies {
implementation(project(":ImagePickerAndroid"))
implementation("androidx.core:core-ktx:1.15.0")
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.0.21"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.1.0"))
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
implementation("androidx.activity:activity-compose:1.9.3")
implementation(platform("androidx.compose:compose-bom:2024.11.00"))
Expand All @@ -66,6 +66,6 @@ dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.5")
implementation("androidx.media3:media3-exoplayer:1.4.1")
implementation("androidx.media3:media3-ui:1.4.1")
implementation("androidx.media3:media3-exoplayer:1.5.0")
implementation("androidx.media3:media3-ui:1.5.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fun ImagePicker() {
style = TextStyle(textAlign = TextAlign.Center)
)
}
Button(modifier = Modifier.size(150.dp, 50.dp), onClick = { takeSingleCameraImage() }) {
Button(modifier = Modifier.size(150.dp, 50.dp), onClick = { takeSingleCameraImage(context = context) }) {
Text(
text = stringResource(R.string.take_camera_images),
style = TextStyle(textAlign = TextAlign.Center)
Expand Down

0 comments on commit c44f963

Please sign in to comment.