Skip to content

Commit

Permalink
Merge pull request #53 from ChochaNaresh/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ChochaNaresh authored May 2, 2024
2 parents 39a4bb9 + 3fd5320 commit 6f9d638
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 32 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This library is designed to simplify the process of selecting and retrieving med
[![Build Workflow](https://github.com/ChochaNaresh/FilePicker/actions/workflows/android.yml/badge.svg)](https://github.com/ChochaNaresh/FilePicker/actions?query=workflow%3AAndroid)
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
![Language](https://img.shields.io/badge/language-Kotlin-orange.svg)
![Language](https://img.shields.io/badge/Kotlin-1.9.10-blue)
![Language](https://img.shields.io/badge/Kotlin-1.9.23-blue)

### How to use
**How to add dependencies**
Expand All @@ -23,8 +23,7 @@ allprojects {
```groovy
dependencies {
// ...
implementation 'com.github.ChochaNaresh:FilePicker:$libVersion' // deprecated
implementation 'io.github.chochanaresh:filepicker:$libVersion' // update
implementation 'io.github.chochanaresh:filepicker:$libVersion'
// ...
}
```
Expand All @@ -41,8 +40,23 @@ allprojects {
```kotlin
dependencies {
// ...
implementation("com.github.ChochaNaresh:FilePicker:$libVersion") // deprecated
implementation ("io.github.chochanaresh:filepicker:$libVersion") // update
implementation ("io.github.chochanaresh:filepicker:$libVersion")
// ...
}
```
**libs.versions.toml**
```toml
[versions]
filepicker = "$libVersion"

[libraries]
filepicker = { group = "io.github.chochanaresh", name = "filepicker", version.ref = "filepicker" }
````

```kotlin
dependencies {
// ...
implementation(libs.filepicker)
// ...
}
```
Expand Down Expand Up @@ -208,6 +222,8 @@ addImageCapture(
popUpText = "Camera",
mFolder = File(),// set custom folder with write file permission
fileName = "image.jpg",
// It is not working correctly. However, it will Work on the same devices.
isUseRearCamera = true, // setting camera facing
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
Expand All @@ -227,6 +243,8 @@ addImageCapture(
null, // Title for pop item
null, // set custom folder with write file permission
null, // set custom File name
// It is not working correctly. However, it will Work on the same devices.
isUseRearCamera = true, // setting camera facing
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application").version("8.3.0").apply(false)
id("com.android.library").version("8.3.0").apply(false)
kotlin("android").version("1.9.10").apply(false)
id("com.android.application").version("8.4.0").apply(false)
id("com.android.library").version("8.4.0").apply(false)
kotlin("android").version("1.9.23").apply(false)
id("io.gitlab.arturbosch.detekt").version("1.23.1").apply(false)
id("com.vanniktech.maven.publish").version("0.25.3")
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}
10 changes: 5 additions & 5 deletions filepickerlibrary/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ android {
dependencies {

// core
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")

// timber
Expand All @@ -103,7 +103,7 @@ dependencies {

androidTestImplementation("com.google.truth:truth:1.1.5")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.3.0")
androidTestImplementation("androidx.arch.core:core-testing:2.2.0")
}

Expand All @@ -119,7 +119,7 @@ detekt {
}

mavenPublishing {
coordinates("io.github.chochanaresh", "filepicker", "0.2.4")
coordinates("io.github.chochanaresh", "filepicker", "0.2.5")

pom {
name.set("filepicker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ data class ImageCaptureConfig(
override val popUpText: String? = null,
val mFolder: File? = null,
val fileName: String? = null,
/**
* It is not working correctly. However, it will Work on the same devices.
*/
val isUseRearCamera: Boolean? = null,
override val askPermissionTitle: String? = null,
override val askPermissionMessage: String? = null,
override val settingPermissionTitle: String? = null,
Expand Down Expand Up @@ -70,6 +74,9 @@ data class PickMediaConfig(
@DrawableRes override val popUpIcon: Int? = null,
override val popUpText: String? = null,
val allowMultiple: Boolean? = null,
/**
* MaxFiles work after SDK 33 or above versions
*/
val maxFiles: Int? = null,
val mPickMediaType: PickMediaType? = null,
override val askPermissionTitle: String? = null,
Expand Down Expand Up @@ -99,6 +106,9 @@ data class DocumentFilePickerConfig(
@DrawableRes override val popUpIcon: Int? = null,
override val popUpText: String? = null,
val allowMultiple: Boolean? = null,
/**
* MaxFiles work after SDK 33 or above versions
*/
val maxFiles: Int? = null,
val mMimeTypes: List<String>? = null,
override val askPermissionTitle: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class FilePicker private constructor() {
popUpIcon = mImageCaptureConfig?.popUpIcon ?: R.drawable.ic_camera,
popUpText = mImageCaptureConfig?.popUpText ?: "Camera",
mFolder = mImageCaptureConfig?.mFolder,
fileName = mImageCaptureConfig?.fileName ?: Const.DefaultPaths.defaultImageFile(),
fileName = mImageCaptureConfig?.fileName
?: Const.DefaultPaths.defaultImageFile(),
askPermissionTitle = mImageCaptureConfig?.askPermissionTitle,
askPermissionMessage = mImageCaptureConfig?.askPermissionMessage,
settingPermissionTitle = mImageCaptureConfig?.settingPermissionTitle,
Expand All @@ -66,7 +67,8 @@ class FilePicker private constructor() {
popUpIcon = mVideoCaptureConfig?.popUpIcon ?: R.drawable.ic_video,
popUpText = mVideoCaptureConfig?.popUpText ?: "Video",
mFolder = mVideoCaptureConfig?.mFolder,
fileName = mVideoCaptureConfig?.fileName ?: Const.DefaultPaths.defaultVideoFile(),
fileName = mVideoCaptureConfig?.fileName
?: Const.DefaultPaths.defaultVideoFile(),
maxSeconds = mVideoCaptureConfig?.maxSeconds,
maxSizeLimit = mVideoCaptureConfig?.maxSizeLimit,
isHighQuality = mVideoCaptureConfig?.isHighQuality,
Expand All @@ -92,7 +94,8 @@ class FilePicker private constructor() {
} else {
Int.MAX_VALUE
},
mPickMediaType = mPickMediaConfig?.mPickMediaType ?: PickMediaType.ImageAndVideo,
mPickMediaType = mPickMediaConfig?.mPickMediaType
?: PickMediaType.ImageAndVideo,
askPermissionTitle = mPickMediaConfig?.askPermissionTitle,
askPermissionMessage = mPickMediaConfig?.askPermissionMessage,
settingPermissionTitle = mPickMediaConfig?.settingPermissionTitle,
Expand Down Expand Up @@ -121,7 +124,7 @@ class FilePicker private constructor() {
settingPermissionTitle = mDocumentFilePickerConfig?.settingPermissionTitle,
settingPermissionMessage = mDocumentFilePickerConfig?.settingPermissionMessage,

),
),
)
return this
}
Expand All @@ -134,7 +137,9 @@ class FilePicker private constructor() {
popUpIcon = mImageCaptureConfig?.popUpIcon ?: R.drawable.ic_camera,
popUpText = mImageCaptureConfig?.popUpText ?: "Camera",
mFolder = mImageCaptureConfig?.mFolder,
fileName = mImageCaptureConfig?.fileName ?: Const.DefaultPaths.defaultImageFile(),
fileName = mImageCaptureConfig?.fileName
?: Const.DefaultPaths.defaultImageFile(),
isUseRearCamera = mImageCaptureConfig?.isUseRearCamera ?: true,
askPermissionTitle = mImageCaptureConfig?.askPermissionTitle,
askPermissionMessage = mImageCaptureConfig?.askPermissionMessage,
settingPermissionTitle = mImageCaptureConfig?.settingPermissionTitle,
Expand All @@ -150,7 +155,8 @@ class FilePicker private constructor() {
popUpIcon = mVideoCaptureConfig?.popUpIcon ?: R.drawable.ic_video,
popUpText = mVideoCaptureConfig?.popUpText ?: "Video",
mFolder = mVideoCaptureConfig?.mFolder,
fileName = mVideoCaptureConfig?.fileName ?: Const.DefaultPaths.defaultVideoFile(),
fileName = mVideoCaptureConfig?.fileName
?: Const.DefaultPaths.defaultVideoFile(),
maxSeconds = mVideoCaptureConfig?.maxSeconds,
maxSizeLimit = mVideoCaptureConfig?.maxSizeLimit,
isHighQuality = mVideoCaptureConfig?.isHighQuality,
Expand All @@ -175,7 +181,8 @@ class FilePicker private constructor() {
} else {
Int.MAX_VALUE
},
mPickMediaType = mPickMediaConfig?.mPickMediaType ?: PickMediaType.ImageAndVideo,
mPickMediaType = mPickMediaConfig?.mPickMediaType
?: PickMediaType.ImageAndVideo,
askPermissionTitle = mPickMediaConfig?.askPermissionTitle,
askPermissionMessage = mPickMediaConfig?.askPermissionMessage,
settingPermissionTitle = mPickMediaConfig?.settingPermissionTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ internal class ImageCaptureActivity : AppCompatActivity() {
)
createFileGetUri(imageFile!!)
}
imageFileUri?.let { imageCapture.launch(getImageCaptureIntent(it)) }
imageFileUri?.let {
imageCapture.launch(
getImageCaptureIntent(
it,
mImageCaptureConfig?.isUseRearCamera ?: true
)
)
}
}

private fun showAskDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.nareshchocha.filepickerlibrary.R
import com.nareshchocha.filepickerlibrary.models.DocumentFilePickerConfig
import com.nareshchocha.filepickerlibrary.models.PickMediaConfig
import com.nareshchocha.filepickerlibrary.utilities.appConst.Const
import java.security.AccessController.getContext


internal fun Context.showMyDialog(
Expand Down Expand Up @@ -49,10 +48,24 @@ internal fun Context.showMyDialog(
alertDialog.show()
}

internal fun Context.getImageCaptureIntent(outputFileUri: Uri): Intent {
internal fun Context.getImageCaptureIntent(
outputFileUri: Uri,
useRearCamera: Boolean
): Intent {
return Intent(MediaStore.ACTION_IMAGE_CAPTURE).also {
it.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
it.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri)
if (useRearCamera) {
it.putExtra("android.intent.extras.LENS_FACING_BACK", 1)
it.putExtra("android.intent.extras.LENS_FACING_FRONT", 0)
it.putExtra("android.intent.extras.CAMERA_FACING", 0)
it.putExtra("android.intent.extra.USE_FRONT_CAMERA", false)
} else {
it.putExtra("android.intent.extras.LENS_FACING_FRONT", 1)
it.putExtra("android.intent.extras.LENS_FACING_BACK", 0)
it.putExtra("android.intent.extras.CAMERA_FACING", 1)
it.putExtra("android.intent.extra.USE_FRONT_CAMERA", true)
}
}
}

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 @@
#Mon May 01 11:06:20 IST 2023
#Thu May 02 11:41:33 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 4 additions & 5 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ android {

dependencies {
// core
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.core:core-ktx:1.13.1")

// File Picker
implementation(project(":filepickerlibrary"))
//implementation("io.github.chochanaresh:filepicker:0.2.0")

// timber
implementation("com.jakewharton.timber:timber:5.0.1")
Expand All @@ -112,6 +111,6 @@ dependencies {

androidTestImplementation("com.google.truth:truth:1.1.5")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.3.0")
androidTestImplementation("androidx.arch.core:core-testing:2.2.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
null,
null,
null,
true,
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.nareshchocha.filepicker.adapter.MediaAdapter
import com.nareshchocha.filepicker.databinding.ActivityMainBinding
import com.nareshchocha.filepickerlibrary.models.DocumentFilePickerConfig
import com.nareshchocha.filepickerlibrary.models.ImageCaptureConfig
import com.nareshchocha.filepickerlibrary.models.PickMediaConfig
import com.nareshchocha.filepickerlibrary.models.PickMediaType
import com.nareshchocha.filepickerlibrary.models.PopUpConfig
Expand All @@ -30,7 +31,7 @@ class MainActivity : AppCompatActivity() {
binding.mbtCaptureImage.setOnClickListener {
captureImageResultLauncher.launch(
FilePicker.Builder(this)
.imageCaptureBuild(),
.imageCaptureBuild(ImageCaptureConfig(isUseRearCamera = false)),
)
}
binding.mbtCaptureVideo.setOnClickListener {
Expand Down

0 comments on commit 6f9d638

Please sign in to comment.