-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Gutenberg] Audio block - Consolidated & Normal Media Picker Integration #13612
[Gutenberg] Audio block - Consolidated & Normal Media Picker Integration #13612
Conversation
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
You can test the changes on this Pull Request by downloading the APK here. |
be8e680
to
6b389c4
Compare
@@ -212,6 +212,32 @@ class MediaPickerLauncher @Inject constructor( | |||
} | |||
} | |||
|
|||
fun showAudioFilePicker(activity: Activity, canMultiselect: Boolean = false) { | |||
if (consolidatedMediaPickerFeatureConfig.isEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this approach is fine. What I did here was I duplicated the showFilePicker
method because I need the allowTypes
to be different for the file and audio pickers. At first, I thought of making this property a default one in the method params but this doesn't work with Java. Is this behavior okay? Or should I do some form of method override? Let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I didn't bother to bring the Normal Picker behavior up to speed here because it seems like the consolidated media picker will be the only one in use for the near future so I thought I would waste time building it out and there's a high possibility we won't do a rollback. Was that the right judgment call? ? I did make modifications in the past to support the File Block's file selection behavior on the normal and consolidated picker hence my question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would consider doing here is creating a private fun that incorporates the common code and that accepts (activity, canMultiselect, allowedTypes)
then the publicly exposed methods (showFilePicker, showAudioFilePicker) can call this private fun passing the desired allowedTypes (I would not expose the allowedTypes as public fun params though so the calling function should not worry about it). This in a way also ease the second item:
Also, I didn't bother to bring the Normal Picker behavior up to speed here because it seems like the consolidated media picker will be the only one in use for the near future so I thought I would waste time building it out and there's a high possibility we won't do a rollback.
I think the rationale here was as you mention to allow an easy rollback (doing it by remote) in case of any issues with the consolidated media picker. To allow this we need to have the standard media picker fallback in place. I agree it's pretty unlikely we should rollback since the media picker has been released in 16.2 already, but until we do not remove this duplicated
approach (probably in other couple of release or so) I would keep this consistent. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great insight @develric I am going to do this implementation and then share my findings with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jd-alexander 👋 ! I checked the code and it looks good overall. I left a couple of comments for you to review. Let me know wdyt 🙇 .
This said, if I'm not wrong I see the Audio block is not in the APK from this PR; I tried to build the GB from sources adding wp.BUILD_GUTENBERG_FROM_SOURCE=true
to my gradle.properties but I think I have some missing piece in my local setup to build GB locally (getting every kind of errors 😄 ). I think I need to spend some time to get my setup good for local GB building or maybe there is another way we can have the CI built APK have audio block enabled? Let's sync when you come online on this in case I'm missing anything, thanks 🙇♂️..
@@ -212,6 +212,32 @@ class MediaPickerLauncher @Inject constructor( | |||
} | |||
} | |||
|
|||
fun showAudioFilePicker(activity: Activity, canMultiselect: Boolean = false) { | |||
if (consolidatedMediaPickerFeatureConfig.isEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would consider doing here is creating a private fun that incorporates the common code and that accepts (activity, canMultiselect, allowedTypes)
then the publicly exposed methods (showFilePicker, showAudioFilePicker) can call this private fun passing the desired allowedTypes (I would not expose the allowedTypes as public fun params though so the calling function should not worry about it). This in a way also ease the second item:
Also, I didn't bother to bring the Normal Picker behavior up to speed here because it seems like the consolidated media picker will be the only one in use for the near future so I thought I would waste time building it out and there's a high possibility we won't do a rollback.
I think the rationale here was as you mention to allow an easy rollback (doing it by remote) in case of any issues with the consolidated media picker. To allow this we need to have the standard media picker fallback in place. I agree it's pretty unlikely we should rollback since the media picker has been released in 16.2 already, but until we do not remove this duplicated
approach (probably in other couple of release or so) I would keep this consistent. wdyt?
int chooseAudioFileResourceId = | ||
getResources().getIdentifier("photo_picker_choose_file", "string", packageName); | ||
|
||
otherMediaOptions.add(new MediaOption(MEDIA_SOURCE_AUDIO_FILE, getString(chooseAudioFileResourceId))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it comes to GB, GlueCode etc I'm still on the learning path 😄 , so not sure the following is worth or can have any constraint, but was wondering given the only difference seems to be the MEDIA_SOURCE_FILE
vs MEDIA_SOURCE_AUDIO_FILE
parameter, should we try to extract here also the common code with initOtherMediaFileOptions
? wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea @develric Thanks! I am going to look into doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumping the milestone in light of wordpress-mobile/gutenberg-mobile#2854 (comment) |
Refactored the prepareIntent methods since behavior was shared between them all.
45a3ade
to
7815032
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing an APK since the ci built APK seems to not contain the audio block for me (maybe some flag we should take care of, ci built APK are really handy when reviewing 😄 ).
Code looks good overall, good job 👍 . I left a couple of comment inline for your review 🙇 . I also tested using your APK. Choosing from WP Media lib works as expected both with new and old media picker, but I found the following. Let me know 😊
- unless the apk did not rebuild correctly or I'm missing something, I still cannot pick mp3 and wav audio files from the device internal storage (like mp3 and wav are grayed out); ogg seems to work. This is true in GB and media picker also. It can be a different task from this PR, but actually for the Media Lib I don't remember which was the expected behaviour (cc @planarvoid ), should we have a dedicated
Choose audio from device
menu or leverageChoose file from device
? @jd-alexander let me know if you can reproduce or you need me to make some additional check for that 🙇♂️. (I was using a Business plan test site if this matters) - don't think it's related to this PR but I'm mentioning to cross check with you. I think currently I cannot play the uploaded audio file from inside the editor right? So I tried to open a preview of the post I was editing and I get the audio player with the file I uploaded. If I then try to play that file and exit the preview, the audio is still playing and I need to kill the app to stop it. If this happens to you also maybe we should open a GH issue for it.
PS: approved the fluxc companion PR if you want to tag and relink it here 👍 .
} else if ((mBrowserType.isSingleImagePicker() || mBrowserType.isSingleMediaPicker() || mBrowserType | ||
.isSingleFilePicker()) && !isLongClick) { | ||
.isSingleFilePicker()) || mBrowserType | ||
.isSingleAudioFilePicker() && !isLongClick) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect the parenthesis here are not what we want? I would put them to group all the ||
before the && !isLongClick
. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds about right. Thanks 3309187
if (multiSelect) { | ||
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); | ||
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiSelect); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I would rather keep the true
, it's like more obvious we actually want the only possible value to be true (in fact we check for if (multiselect)
and we don't want to have a false value there (but rather no value at all) when we don't want to multiselect. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, good spotting that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Resolved here 1e5aa6d
No problem 🙇
I appreciate it :)
Which file app are you utilizing? Could you create a video recording of your screen so I can see exactly what is happening?
Yes, if you could reproduce this it would be great as I am learning about the consolidated media picker project as I go through the code.
Good question! This behavior will probably be in an updated version of the Audio block.
I am going to check this out. Thanks for reporting!
Thanks much! |
Hey @jd-alexander 👋 . I tried to dig a bit forcing some behaviour with the debugger, what I can say is:
Maybe we should further dig the ways we are opening the system picker (at least for audio) also on other devices. I see we are setting the following:
so basically relaying on the EXTRA_MIME_TYPES to filter out the unwanted mime types. In my case with the above I get some audio files grayed out but cannot understand with which logic (maybe something in the files but they are basically the test files we are using in the Pixel Emu also) I get the same results if I keep the EXTRA_MIME_TYPES but set type as but in this case I guess we are potentially not filtering out not supported audio mime types that's why we set the EXTRA_MIME_TYPES. Googling quickly I see that there can be also the possibility to put multiple sets in the type like Unfortunately it seems I still cannot build GB with my setup, so not easy to check things, but since we have still some time before the end of the sprint maybe we should spend a bit more time to check how we can broaden device support when coming to picking from system picker (at least for audio). For example in this PR we are using type */* but thinking to it maybe an audio/* would be more correct (at least in the editor)? Are we releasing the audio block with this PR or this is an interstitial PR? We can probably address this in a separate PR but let's keep in touch on slack to decide how to proceed 🙇 |
…picker_integration
Thanks for digging into this @develric and I agree that we will have to play with the params below that are being passed to the intent to achieve behavior that's compatible with all file pickers.
Yes, this is an intermediary PR, so there are several other PRs depending on it that need to be merged in so it would be good to get these PRs merged in, and then we can create an issue and address the improvements we need separately. Thanks much for the thorough review and actually spotting this on a different device configuration. |
…picker_integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work and improvements here @jd-alexander 🙇 . Let's make sure to open a ticket to further dig those intent parameters for system pickers support before final release of audio block (let me know if you want me to open it). This said LGTM and good job 👍 .
Thanks again @develric I created an issue to track the intent params issue here so we can continue looking into it. |
gutenberg
: WordPress/gutenberg#27401gutenberg-mobile
PR: wordpress-mobile/gutenberg-mobile#2854WPiOS
PR: wordpress-mobile/WordPress-iOS#15420FluxCAndroid
wordpress-mobile/WordPress-FluxC-Android#1823Solution
This solution seeks to address the ability to add an audio file to the Audio Block from the device or WordPress media library utilizing the media picker components that are present within the codebase. A similar implementation was created for the File Block. This PR integrates the menu options from the Audio block with the consolidated media picker.
The primary changes are:
introducing a
SINGLE_AUDIO_FILE_PICKER
type in theMediaBrowserType
so the behavior that's specific to the Audio Block can be constrained by this picker type.The GutenbergEditor's WP Media Library
AudioButtonClicked
behavior was wired to the WP Media Library and local file source behavior that opens the pickers.showFilePicker
was duplicated and ashowAudioFilePicker
variant was created to manage the device file picker for audio.Prerequisite For All Testing
Ensure you are utilizing a site that is on a premium plan as free plans aren't able to upload audio files.
To test:
Consolidated Media Picker
Picking local files.
Normal Media Picker
Picking local files.
Consolidated Media Picker
Picking WP media picker files.
Normal Media Picker
Picking WP media picker files.
File Block - Consolidated and Normal Media Picker
Verify that the File Block's behavior of being able to select any type of file either locally or from the WordPress Media Library is intact and no regressions have occurred since most of its behavior is shared with the Audio block.
PR submission checklist:
RELEASE-NOTES.txt
if necessary.