Skip to content

Commit 08b5d45

Browse files
authored
Merge pull request #65 from Dhaval2404/feature/v1.7
v1.7 Released
2 parents f6a7fa2 + a0d1524 commit 08b5d45

File tree

19 files changed

+204
-80
lines changed

19 files changed

+204
-80
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.7] - 2020-03-23
10+
### Changed
11+
* Added option to limit MIME types while choosing a gallery image (Special Thanks to [Marchuck](https://github.com/Marchuck))
12+
* Introduced ImageProviderInterceptor, Can be used for analytics (Special Thanks to [Marchuck](https://github.com/Marchuck))
13+
* Fixed FileProvider of the library clashes with the FileProvider of the app [#51](https://github.com/Dhaval2404/ImagePicker/issues/51) (Special Thanks to [OyaCanli](https://github.com/OyaCanli))
14+
* Added option to set Storage Directory [#52](https://github.com/Dhaval2404/ImagePicker/issues/52)
15+
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))
16+
917
## [1.6] - 2020-01-06
1018
### Changed
1119
* Improved UI/UX of sample app
@@ -51,7 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5159
* Handle Runtime Permission for Camera and Storage
5260
* Retrive Image Result as File, File Path as String or Uri object
5361

54-
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v1.6...HEAD
62+
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7...HEAD
63+
[1.7]: https://github.com/Dhaval2404/ImagePicker/compare/v1.6...v1.7
5564
[1.6]: https://github.com/Dhaval2404/ImagePicker/compare/v1.5...v1.6
5665
[1.5]: https://github.com/Dhaval2404/ImagePicker/compare/v1.4...v1.5
5766
[1.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.3...v1.4

README.md

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,62 +176,104 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
176176
ImagePicker.with(this)
177177
.crop() //Crop image and let user choose aspect ratio.
178178
.start()
179-
179+
```
180180
* Crop image with fixed Aspect Ratio
181-
181+
182182
```kotlin
183183
ImagePicker.with(this)
184184
.crop(16f, 9f) //Crop image with 16:9 aspect ratio
185185
.start()
186-
187-
```
186+
```
188187
* Crop square image(e.g for profile)
189-
188+
190189
```kotlin
191190
ImagePicker.with(this)
192-
.cropSquare() //Crop square image, its same as crop(1f, 1f)
193-
.start()
191+
.cropSquare() //Crop square image, its same as crop(1f, 1f)
192+
.start()
194193
```
195194
* Compress image size(e.g image should be maximum 1 MB)
196-
195+
197196
```kotlin
198197
ImagePicker.with(this)
199198
.compress(1024) //Final image size will be less than 1 MB
200199
.start()
201200
```
202201
* Set Resize image resolution
203-
202+
204203
```kotlin
205204
ImagePicker.with(this)
206-
.maxResultSize(620, 620) //Final image resolution will be less than 620 x 620
205+
.maxResultSize(620, 620) //Final image resolution will be less than 620 x 620
207206
.start()
208207
```
208+
* Intercept ImageProvider, Can be used for analytics
209+
210+
```kotlin
211+
ImagePicker.with(this)
212+
.setImageProviderInterceptor { imageProvider -> //Intercept ImageProvider
213+
Log.d("ImagePicker", "Selected ImageProvider: "+imageProvider.name)
214+
}
215+
.start()
216+
```
217+
218+
* Specify Directory to store captured, cropped or compressed images
219+
220+
```kotlin
221+
ImagePicker.with(this)
222+
//Provide directory path to save images
223+
.saveDir(File(Environment.getExternalStorageDirectory(), "ImagePicker"))
224+
// .saveDir(Environment.getExternalStorageDirectory())
225+
// .saveDir(getExternalFilesDir(null)!!)
226+
.start()
227+
```
228+
229+
* Limit MIME types while choosing a gallery image
230+
231+
```kotlin
232+
ImagePicker.with(this)
233+
.galleryMimeTypes( //Exclude gif images
234+
mimeTypes = arrayOf(
235+
"image/png",
236+
"image/jpg",
237+
"image/jpeg"
238+
)
239+
)
240+
.start()
241+
```
242+
209243
* You can also specify the request code with ImagePicker
210-
244+
211245
```kotlin
212246
ImagePicker.with(this)
213-
.maxResultSize(620, 620)
247+
.maxResultSize(620, 620)
214248
.start(101) //Here 101 is request code, you may use this in onActivityResult
215-
```
216-
249+
```
250+
217251
* Add Following parameters in your **colors.xml** file, If you want to customize uCrop Activity.
218-
252+
219253
```xml
220254
<resources>
221255
<!-- Here you can add color of your choice -->
222256
<color name="ucrop_color_toolbar">@color/teal_500</color>
223257
<color name="ucrop_color_statusbar">@color/teal_700</color>
224258
<color name="ucrop_color_widget_active">@color/teal_500</color>
225-
</resources>
259+
</resources>
226260
```
227-
261+
228262
# 💥Compatibility
229-
263+
230264
* Library - Android Kitkat 4.4+ (API 19)
231265
* Sample - Android Kitkat 4.4+ (API 19)
232-
266+
233267
# ✔️Changelog
234268
269+
### Version: 1.7
270+
271+
* Added option to limit MIME types while choosing a gallery image (Special Thanks to [Marchuck](https://github.com/Marchuck))
272+
* Introduced ImageProviderInterceptor, Can be used for analytics (Special Thanks to [Marchuck](https://github.com/Marchuck))
273+
* Fixed FileProvider of the library clashes with the FileProvider of the app [#51](https://github.com/Dhaval2404/ImagePicker/issues/51) (Special Thanks to [OyaCanli](https://github.com/OyaCanli))
274+
* Added option to set Storage Directory [#52](https://github.com/Dhaval2404/ImagePicker/issues/52)
275+
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))
276+
235277
### Version: 1.6
236278
237279
* Improved UI/UX of sample app
@@ -244,7 +286,6 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
244286
* Fixed app crash issue, due to Camera Permission in manifest [#34](https://github.com/Dhaval2404/ImagePicker/issues/34)
245287
* Added Option for Dynamic Crop Ratio. Let User choose aspect ratio [#36](https://github.com/Dhaval2404/ImagePicker/issues/36) (Special Thanks to [Dor-Sloim](https://github.com/Dor-Sloim))
246288
247-
248289
### Version: 1.4
249290
250291
* Optimized Uri to File Conversion (Inspired by [Flutter ImagePicker](https://github.com/flutter/plugins/tree/master/packages/image_picker))

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.41'
4+
ext.kotlin_version = '1.3.61'
55
repositories {
66
google()
77
jcenter()
88
maven { url "https://jitpack.io" }
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.3'
11+
classpath 'com.android.tools.build:gradle:3.6.1'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313

1414
//jcenter plugins

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip

imagepicker/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
defaultConfig {
1414
minSdkVersion 19
1515
targetSdkVersion 28
16-
versionCode 7
17-
versionName "1.6"
16+
versionCode 8
17+
versionName "1.7"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
}
@@ -44,17 +44,17 @@ dependencies {
4444
implementation fileTree(dir: 'libs', include: ['*.jar'])
4545
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4646

47-
implementation 'androidx.core:core-ktx:1.1.0'
47+
implementation 'androidx.core:core-ktx:1.2.0'
4848
implementation 'androidx.appcompat:appcompat:1.1.0'
4949
implementation "androidx.exifinterface:exifinterface:1.1.0"
5050

5151
//More Info: https://github.com/Yalantis/uCrop
5252
implementation 'com.github.yalantis:ucrop:2.2.4'
5353

5454
//More Info: https://github.com/florent37/InlineActivityResult
55-
compileOnly 'com.github.florent37:inline-activity-result-kotlin:1.0.1'
55+
compileOnly 'com.github.florent37:inline-activity-result-kotlin:1.0.3'
5656

57-
testImplementation 'junit:junit:4.12'
57+
testImplementation 'junit:junit:4.13'
5858
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
5959
androidTestImplementation 'androidx.test:core:1.2.0'
6060
}
@@ -72,7 +72,7 @@ ext {
7272
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
7373
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'
7474

75-
libraryVersion = '1.6'
75+
libraryVersion = '1.7'
7676
//If you are uploading new library try : gradlew install
7777
//If you are updating existing library then execute: gradlew bintrayUpload
7878
//In both the case don't forgot to put bintray credentials in local.properties file.

imagepicker/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
1717

1818
<provider
19-
android:name="androidx.core.content.FileProvider"
20-
android:authorities="${applicationId}.provider"
19+
android:name="com.github.dhaval2404.imagepicker.ImagePickerFileProvider"
20+
android:authorities="@string/image_picker_provider_authority"
2121
android:exported="false"
2222
android:grantUriPermissions="true">
2323

imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/ImagePicker.kt

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import android.widget.Toast
77
import androidx.appcompat.app.AppCompatActivity
88
import androidx.fragment.app.Fragment
99
import com.github.dhaval2404.imagepicker.constant.ImageProvider
10-
import com.github.dhaval2404.imagepicker.constant.ImageProvider.BOTH
11-
import com.github.dhaval2404.imagepicker.constant.ImageProvider.CAMERA
12-
import com.github.dhaval2404.imagepicker.constant.ImageProvider.GALLERY
1310
import com.github.dhaval2404.imagepicker.listener.ResultListener
1411
import com.github.dhaval2404.imagepicker.util.DialogHelper
1512
import com.github.florent37.inlineactivityresult.kotlin.startForResult
@@ -36,10 +33,11 @@ open class ImagePicker {
3633
internal const val EXTRA_CROP_Y = "extra.crop_y"
3734
internal const val EXTRA_MAX_WIDTH = "extra.max_width"
3835
internal const val EXTRA_MAX_HEIGHT = "extra.max_height"
36+
internal const val EXTRA_SAVE_DIRECTORY = "extra.save_directory"
3937

4038
internal const val EXTRA_ERROR = "extra.error"
4139
internal const val EXTRA_FILE_PATH = "extra.file_path"
42-
internal const val EXTRA_GALLERY_MIME_TYPES = "extra.gallery.mime.types"
40+
internal const val EXTRA_MIME_TYPES = "extra.mime_types"
4341

4442
/**
4543
* Use this to use ImagePicker in Activity Class
@@ -95,9 +93,9 @@ open class ImagePicker {
9593
private var fragment: Fragment? = null
9694

9795
// Image Provider
98-
private var imageProvider = BOTH
96+
private var imageProvider = ImageProvider.BOTH
9997

100-
//mime types restrictions for gallery. by default all mime types are valid
98+
// Mime types restrictions for gallery. by default all mime types are valid
10199
private var mimeTypes: Array<String> = emptyArray()
102100

103101
/*
@@ -120,6 +118,15 @@ open class ImagePicker {
120118

121119
private var imageProviderInterceptor: ((ImageProvider) -> Unit)? = null
122120

121+
/**
122+
* File Directory
123+
*
124+
* Camera, Crop, Compress Image Will be store in this directory.
125+
*
126+
* If null, Image will be stored in {@see [Environment.DIRECTORY_DCIM]}
127+
*/
128+
private var saveDir: String? = null
129+
123130
/**
124131
* Call this while picking image for fragment.
125132
*/
@@ -140,7 +147,7 @@ open class ImagePicker {
140147
*/
141148
// @Deprecated("Please use provider(ImageProvider.CAMERA) instead")
142149
fun cameraOnly(): Builder {
143-
this.imageProvider = CAMERA
150+
this.imageProvider = ImageProvider.CAMERA
144151
return this
145152
}
146153

@@ -149,12 +156,12 @@ open class ImagePicker {
149156
*/
150157
// @Deprecated("Please use provider(ImageProvider.GALLERY) instead")
151158
fun galleryOnly(): Builder {
152-
this.imageProvider = GALLERY
159+
this.imageProvider = ImageProvider.GALLERY
153160
return this
154161
}
155162

156163
/**
157-
* restrict mime types during gallery fetching, for instance if you do not want GIF images,
164+
* Restrict mime types during gallery fetching, for instance if you do not want GIF images,
158165
* you can use arrayOf("image/png","image/jpeg","image/jpg")
159166
* by default array is empty, which indicates no additional restrictions, just images
160167
* @param mimeTypes
@@ -212,8 +219,33 @@ open class ImagePicker {
212219
return this
213220
}
214221

215-
fun setImageProviderInterceptor(imageProviderInterceptor: (ImageProvider) -> Unit): Builder {
216-
this.imageProviderInterceptor = imageProviderInterceptor
222+
/**
223+
* Provide Directory to store Captured/Modified images
224+
*
225+
* @param path Folder Directory
226+
*/
227+
fun saveDir(path: String): Builder {
228+
this.saveDir = path
229+
return this
230+
}
231+
232+
/**
233+
* Provide Directory to store Captured/Modified images
234+
*
235+
* @param file Folder Directory
236+
*/
237+
fun saveDir(file: File): Builder {
238+
this.saveDir = file.absolutePath
239+
return this
240+
}
241+
242+
/**
243+
* Intercept Selected ImageProvider, Useful for Analytics
244+
*
245+
* @param interceptor ImageProvider Interceptor
246+
*/
247+
fun setImageProviderInterceptor(interceptor: (ImageProvider) -> Unit): Builder {
248+
this.imageProviderInterceptor = interceptor
217249
return this
218250
}
219251

@@ -228,7 +260,7 @@ open class ImagePicker {
228260
* Start Image Picker Activity
229261
*/
230262
fun start(reqCode: Int) {
231-
if (imageProvider == BOTH) {
263+
if (imageProvider == ImageProvider.BOTH) {
232264
// Pick Image Provider if not specified
233265
showImageProviderDialog(reqCode)
234266
} else {
@@ -240,7 +272,7 @@ open class ImagePicker {
240272
* Start Image Picker Activity
241273
*/
242274
fun start(completionHandler: ((resultCode: Int, data: Intent?) -> Unit)? = null) {
243-
if (imageProvider == BOTH) {
275+
if (imageProvider == ImageProvider.BOTH) {
244276
// Pick Image Provider if not specified
245277
showImageProviderDialog(completionHandler)
246278
} else {
@@ -287,18 +319,18 @@ open class ImagePicker {
287319
private fun getBundle(): Bundle {
288320
return Bundle().apply {
289321
putSerializable(EXTRA_IMAGE_PROVIDER, imageProvider)
290-
291-
putStringArray(EXTRA_GALLERY_MIME_TYPES, mimeTypes)
322+
putStringArray(EXTRA_MIME_TYPES, mimeTypes)
292323

293324
putBoolean(EXTRA_CROP, crop)
294-
295325
putFloat(EXTRA_CROP_X, cropX)
296326
putFloat(EXTRA_CROP_Y, cropY)
297327

298328
putInt(EXTRA_MAX_WIDTH, maxWidth)
299329
putInt(EXTRA_MAX_HEIGHT, maxHeight)
300330

301331
putLong(EXTRA_IMAGE_MAX_SIZE, maxSize)
332+
333+
putString(EXTRA_SAVE_DIRECTORY, saveDir)
302334
}
303335
}
304336

@@ -326,12 +358,8 @@ open class ImagePicker {
326358
}
327359
} catch (e: Exception) {
328360
if (e is ClassNotFoundException) {
329-
Toast.makeText(
330-
if (fragment != null) fragment!!.context else activity,
331-
"InlineActivityResult library not installed falling back to default method, please install " +
332-
"it from https://github.com/florent37/InlineActivityResult if you want to get inline activity results.",
333-
Toast.LENGTH_LONG
334-
).show()
361+
Toast.makeText(if (fragment != null) fragment!!.context else activity, "InlineActivityResult library not installed falling back to default method, please install " +
362+
"it from https://github.com/florent37/InlineActivityResult if you want to get inline activity results.", Toast.LENGTH_LONG).show()
335363
startActivity(REQUEST_CODE)
336364
}
337365
}

0 commit comments

Comments
 (0)