@@ -73,11 +73,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
73
73
setStyle() // set style for UI
74
74
handleSelectedAssets(config)
75
75
76
- val chooseMode = when (config.mediaType) {
77
- MediaType .VIDEO -> SelectMimeType .ofVideo()
78
- MediaType .IMAGE -> SelectMimeType .ofImage()
79
- else -> SelectMimeType .ofAll()
80
- }
76
+ val chooseMode = getChooseMode(config.mediaType)
81
77
82
78
val maxSelect = config.maxSelect?.toInt() ? : 20
83
79
val maxVideo = config.maxVideo?.toInt() ? : 20
@@ -96,7 +92,6 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
96
92
.setImageEngine(imageEngine)
97
93
.setSelectedData(dataList)
98
94
.setSelectorUIStyle(style)
99
-
100
95
.apply {
101
96
if (isCrop) {
102
97
setCropOption(config.crop)
@@ -116,13 +111,24 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
116
111
setFilterMaxFileSize(it)
117
112
}
118
113
119
-
120
114
isDisplayCamera(config.camera != null )
121
115
122
116
config.camera?.let {
123
- setCameraInterceptListener(CameraEngine (appContext, it))
117
+ val cameraConfig = NitroCameraConfig (
118
+ mediaType = MediaType .ALL ,
119
+ presentation = Presentation .FULLSCREENMODAL ,
120
+ language = Language .SYSTEM ,
121
+ crop = null ,
122
+ isSaveSystemAlbum = false ,
123
+ color = config.primaryColor,
124
+ cameraDevice = it.cameraDevice,
125
+ videoMaximumDuration = it.videoMaximumDuration
126
+ )
127
+
128
+ setCameraInterceptListener(CameraEngine (appContext, cameraConfig))
124
129
}
125
130
}
131
+ .setVideoThumbnailListener(VideoThumbnailEngine (getVideoThumbnailDir()))
126
132
.setImageSpanCount(config.numberOfColumn?.toInt() ? : 3 )
127
133
.setMaxSelectNum(maxSelect)
128
134
.isDirectReturnSingle(true )
@@ -301,7 +307,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
301
307
.setLanguage(getLanguage(config.language))
302
308
.setSelectorUIStyle(previewStyle)
303
309
.isPreviewFullScreenMode(true )
304
- .isAutoVideoPlay(true )
310
+ .isAutoVideoPlay(config.videoAutoPlay == true )
305
311
.setVideoPlayerEngine(ExoPlayerEngine ())
306
312
.isVideoPauseResumePlay(true )
307
313
.setCustomLoadingListener(getCustomLoadingListener())
@@ -312,6 +318,70 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
312
318
return OnCustomLoadingListener { context -> LoadingDialog (context) }
313
319
}
314
320
321
+ @ReactMethod
322
+ fun openCamera (
323
+ config : NitroCameraConfig ,
324
+ resolved : (result: CameraResult ) -> Unit ,
325
+ rejected : (reject: Double ) -> Unit
326
+ ) {
327
+ val activity = currentActivity
328
+ val chooseMode = getChooseMode(config.mediaType)
329
+
330
+ PictureSelector
331
+ .create(activity)
332
+ .openCamera(chooseMode)
333
+ .setLanguage(getLanguage(config.language))
334
+ .setCameraInterceptListener(CameraEngine (appContext, config))
335
+ .isQuickCapture(true )
336
+ .isOriginalControl(true )
337
+ .setVideoThumbnailListener(VideoThumbnailEngine (getVideoThumbnailDir()))
338
+ .apply {
339
+ if (config.crop != null ) {
340
+ setCropEngine(CropEngine (cropOption))
341
+ }
342
+ }
343
+ .forResultActivity(object : OnResultCallbackListener <LocalMedia ?> {
344
+ override fun onResult (results : java.util.ArrayList <LocalMedia ?>? ) {
345
+ results?.first()?.let {
346
+ val result = getResult(it)
347
+
348
+ resolved(
349
+ CameraResult (
350
+ path = result.path,
351
+ type = result.type,
352
+ width = result.width,
353
+ height = result.height,
354
+ duration = result.duration,
355
+ thumbnail = result.thumbnail,
356
+ fileName = result.fileName
357
+ )
358
+ )
359
+ }
360
+ }
361
+
362
+ override fun onCancel () {
363
+ // rejected(0.0)
364
+ }
365
+ })
366
+ }
367
+
368
+ private fun getChooseMode (mediaType : MediaType ): Int {
369
+ return when (mediaType) {
370
+ MediaType .VIDEO -> SelectMimeType .ofVideo()
371
+ MediaType .IMAGE -> SelectMimeType .ofImage()
372
+ else -> SelectMimeType .ofAll()
373
+ }
374
+ }
375
+
376
+ private fun getVideoThumbnailDir (): String {
377
+ val externalFilesDir: File ? = appContext.getExternalFilesDir(" " )
378
+ val customFile = File (externalFilesDir?.absolutePath, " Thumbnail" )
379
+ if (! customFile.exists()) {
380
+ customFile.mkdirs()
381
+ }
382
+ return customFile.absolutePath + File .separator
383
+ }
384
+
315
385
316
386
private fun getLanguage (language : Language ): Int {
317
387
return when (language) {
@@ -511,19 +581,23 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
511
581
if (item.mimeType.startsWith(" video/" )) ResultType .VIDEO else ResultType .IMAGE
512
582
513
583
var path = item.path
514
-
515
584
var width: Double = item.width.toDouble()
516
585
var height: Double = item.height.toDouble()
517
586
587
+ val thumbnail = item.videoThumbnailPath?.let {
588
+ if (! it.startsWith(" file://" )) " file://$it " else it
589
+ }
590
+
518
591
if (item.isCut) {
519
592
path = " file://${item.cutPath} "
520
593
width = item.cropImageWidth.toDouble()
521
594
height = item.cropImageHeight.toDouble()
522
595
}
523
596
597
+ if (! path.startsWith(" file://" ) && ! path.startsWith(" content://" ) && type == ResultType .IMAGE )
598
+ path = " file://$path "
599
+
524
600
val media = Result (
525
- path,
526
- fileName = item.fileName,
527
601
localIdentifier = item.id.toString(),
528
602
width,
529
603
height,
@@ -533,10 +607,12 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
533
607
realPath = item.realPath,
534
608
parentFolderName = item.parentFolderName,
535
609
creationDate = item.dateAddedTime.toDouble(),
610
+ crop = item.isCut,
611
+ path,
536
612
type,
537
- duration = item.duration.toDouble() ,
538
- thumbnail = item.videoThumbnailPath ,
539
- crop = item.isCut
613
+ fileName = item.fileName ,
614
+ thumbnail = thumbnail ,
615
+ duration = item.duration.toDouble()
540
616
)
541
617
542
618
return media
0 commit comments