Skip to content

Commit

Permalink
added showMediaPicker for file and audio.
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-alexander committed Jan 7, 2021
1 parent b73c139 commit ff71990
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class RequestCodes {
public static final int VIDEO_LIBRARY = 2200;
public static final int MEDIA_LIBRARY = 2210;
public static final int FILE_LIBRARY = 2220;
public static final int AUDIO_LIBRARY = 2230;
public static final int TAKE_VIDEO = 2300;
public static final int CROP_PHOTO = 2400;
public static final int PICTURE_LIBRARY_OR_CAPTURE = 2500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.ui.photopicker

import android.app.Activity
import android.content.Intent
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import org.wordpress.android.R
import org.wordpress.android.R.string
Expand Down Expand Up @@ -184,57 +185,60 @@ class MediaPickerLauncher @Inject constructor(
}

fun showFilePicker(activity: Activity, canMultiselect: Boolean = true) {
if (consolidatedMediaPickerFeatureConfig.isEnabled()) {
val allowedTypes = mutableSetOf(IMAGE, VIDEO, AUDIO, DOCUMENT)
val mediaPickerSetup = MediaPickerSetup(
primaryDataSource = DEVICE,
availableDataSources = setOf(),
canMultiselect = canMultiselect,
requiresStoragePermissions = true,
allowedTypes = allowedTypes,
cameraSetup = HIDDEN,
systemPickerEnabled = true,
editingEnabled = true,
queueResults = false,
defaultSearchView = false,
title = R.string.photo_picker_choose_file
)
val intent = MediaPickerActivity.buildIntent(
activity,
mediaPickerSetup
)
activity.startActivityForResult(
intent,
RequestCodes.FILE_LIBRARY
)
} else {
WPMediaUtils.launchFileLibrary(activity, canMultiselect)
}
showMediaPicker(
activity,
canMultiselect,
mutableSetOf(IMAGE, VIDEO, AUDIO, DOCUMENT),
R.string.photo_picker_choose_file,
RequestCodes.FILE_LIBRARY
)
}

fun showAudioFilePicker(activity: Activity, canMultiselect: Boolean = false) {
showMediaPicker(
activity,
canMultiselect,
mutableSetOf(AUDIO),
R.string.photo_picker_choose_file,
RequestCodes.AUDIO_LIBRARY
)
}

private fun showMediaPicker(
activity: Activity,
canMultiselect: Boolean = false,
allowedTypes: Set<MediaType>,
@StringRes title: Int,
requestCode: Int
) {
if (consolidatedMediaPickerFeatureConfig.isEnabled()) {
val mediaPickerSetup = MediaPickerSetup(
primaryDataSource = DEVICE,
availableDataSources = setOf(),
canMultiselect = canMultiselect,
requiresStoragePermissions = true,
allowedTypes = mutableSetOf(AUDIO),
allowedTypes = allowedTypes,
cameraSetup = HIDDEN,
systemPickerEnabled = true,
editingEnabled = true,
queueResults = false,
defaultSearchView = false,
title = R.string.photo_picker_choose_file
title = title
)
val intent = MediaPickerActivity.buildIntent(
activity,
mediaPickerSetup
)
activity.startActivityForResult(
intent,
RequestCodes.FILE_LIBRARY
requestCode
)
} else {
if (requestCode == RequestCodes.FILE_LIBRARY) {
WPMediaUtils.launchFileLibrary(activity, canMultiselect)
} else {
WPMediaUtils.launchAudioFileLibrary(activity, canMultiselect)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<string name="wp_media_title">WordPress media</string>
<string name="pick_photo">Select photo</string>
<string name="pick_video">Select video</string>
<string name="pick_audio">Select audio</string>
<string name="pick_media">Add image or video</string>
<string name="pick_file">Add file</string>
<string name="capture_or_pick_photo">Capture or select photo</string>
Expand Down

0 comments on commit ff71990

Please sign in to comment.