@@ -73,11 +73,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
7373 setStyle() // set style for UI
7474 handleSelectedAssets(config)
7575
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)
8177
8278 val maxSelect = config.maxSelect?.toInt() ? : 20
8379 val maxVideo = config.maxVideo?.toInt() ? : 20
@@ -96,7 +92,6 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
9692 .setImageEngine(imageEngine)
9793 .setSelectedData(dataList)
9894 .setSelectorUIStyle(style)
99-
10095 .apply {
10196 if (isCrop) {
10297 setCropOption(config.crop)
@@ -116,13 +111,24 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
116111 setFilterMaxFileSize(it)
117112 }
118113
119-
120114 isDisplayCamera(config.camera != null )
121115
122116 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))
124129 }
125130 }
131+ .setVideoThumbnailListener(VideoThumbnailEngine (getVideoThumbnailDir()))
126132 .setImageSpanCount(config.numberOfColumn?.toInt() ? : 3 )
127133 .setMaxSelectNum(maxSelect)
128134 .isDirectReturnSingle(true )
@@ -301,7 +307,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
301307 .setLanguage(getLanguage(config.language))
302308 .setSelectorUIStyle(previewStyle)
303309 .isPreviewFullScreenMode(true )
304- .isAutoVideoPlay(true )
310+ .isAutoVideoPlay(config.videoAutoPlay == true )
305311 .setVideoPlayerEngine(ExoPlayerEngine ())
306312 .isVideoPauseResumePlay(true )
307313 .setCustomLoadingListener(getCustomLoadingListener())
@@ -312,6 +318,70 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
312318 return OnCustomLoadingListener { context -> LoadingDialog (context) }
313319 }
314320
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+
315385
316386 private fun getLanguage (language : Language ): Int {
317387 return when (language) {
@@ -511,19 +581,23 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
511581 if (item.mimeType.startsWith(" video/" )) ResultType .VIDEO else ResultType .IMAGE
512582
513583 var path = item.path
514-
515584 var width: Double = item.width.toDouble()
516585 var height: Double = item.height.toDouble()
517586
587+ val thumbnail = item.videoThumbnailPath?.let {
588+ if (! it.startsWith(" file://" )) " file://$it " else it
589+ }
590+
518591 if (item.isCut) {
519592 path = " file://${item.cutPath} "
520593 width = item.cropImageWidth.toDouble()
521594 height = item.cropImageHeight.toDouble()
522595 }
523596
597+ if (! path.startsWith(" file://" ) && ! path.startsWith(" content://" ) && type == ResultType .IMAGE )
598+ path = " file://$path "
599+
524600 val media = Result (
525- path,
526- fileName = item.fileName,
527601 localIdentifier = item.id.toString(),
528602 width,
529603 height,
@@ -533,10 +607,12 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
533607 realPath = item.realPath,
534608 parentFolderName = item.parentFolderName,
535609 creationDate = item.dateAddedTime.toDouble(),
610+ crop = item.isCut,
611+ path,
536612 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()
540616 )
541617
542618 return media
0 commit comments