-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Gutenberg - Audio Block Processor #13575
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
82da0a4
Created the AudioBlockProcessor
jd-alexander feb2d45
Created AUDIO MediaBlockType.
jd-alexander 98c344e
BlockProcessorFactory is made aware of the AudioBlockProcessor
jd-alexander c7ef4ec
Created tests for the AudioBlockProcessor
jd-alexander 5a62c43
Merge branch 'gutenberg/audio_block_consolidated_media_picker_integra…
jd-alexander f90b0de
Updated ref.
jd-alexander 6307381
Added newline to the AudioBlockProcessor
jd-alexander 9cef87c
Added audio block to the patterns that check if gb media is in post body
jd-alexander 1cc92ef
Added unit tests for the Audio block's isMediaInGutenberg
jd-alexander cdda729
Update WordPress/src/main/java/org/wordpress/android/ui/posts/mediaup…
jd-alexander 4d658fc
Merge branch 'develop' into gutenberg/audio-block-processor
jd-alexander 035a094
synced submodules with develop so no changes contained in diff.
jd-alexander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ava/org/wordpress/android/ui/posts/mediauploadcompletionprocessors/AudioBlockProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.wordpress.android.ui.posts.mediauploadcompletionprocessors | ||
|
|
||
| import com.google.gson.JsonObject | ||
| import org.jsoup.nodes.Document | ||
| import org.wordpress.android.util.helpers.MediaFile | ||
|
|
||
| class AudioBlockProcessor(localId: String?, mediaFile: MediaFile?) : BlockProcessor(localId, mediaFile) { | ||
| override fun processBlockContentDocument(document: Document?): Boolean { | ||
| val audioElements = document?.select(AUDIO_TAG) | ||
|
|
||
| audioElements?.let { elements -> | ||
| for (element in elements) { | ||
| // replaces the src attribute's local url with the remote counterpart. | ||
| element.attr(SRC_ATTRIBUTE, mRemoteUrl) | ||
| } | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| override fun processBlockJsonAttributes(jsonAttributes: JsonObject?): Boolean { | ||
| val id = jsonAttributes?.get(FileBlockProcessor.ID_ATTRIBUTE) | ||
|
|
||
| return if (id != null && !id.isJsonNull && id.asString == mLocalId) { | ||
| jsonAttributes.apply { | ||
| addProperty(ID_ATTRIBUTE, Integer.parseInt(mRemoteId)) | ||
| } | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val AUDIO_TAG = "audio" | ||
| const val SRC_ATTRIBUTE = "src" | ||
| const val ID_ATTRIBUTE = "id" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...org/wordpress/android/ui/posts/mediauploadcompletionprocessors/AudioBlockProcessorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.wordpress.android.ui.posts.mediauploadcompletionprocessors | ||
|
|
||
| import com.nhaarman.mockitokotlin2.mock | ||
| import com.nhaarman.mockitokotlin2.whenever | ||
| import org.assertj.core.api.Assertions | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.wordpress.android.util.helpers.MediaFile | ||
|
|
||
| class AudioBlockProcessorTest { | ||
| private val mediaFile: MediaFile = mock() | ||
| private lateinit var processor: AudioBlockProcessor | ||
|
|
||
| @Before | ||
| fun before() { | ||
| whenever(mediaFile.mediaId).thenReturn(TestContent.remoteMediaId) | ||
| whenever(mediaFile.fileURL).thenReturn(TestContent.remoteAudioUrl) | ||
| processor = AudioBlockProcessor(TestContent.localMediaId, mediaFile) | ||
| } | ||
|
|
||
| @Test | ||
| fun `processBlock replaces id and src in matching block`() { | ||
| val processedBlock = processor.processBlock(TestContent.oldAudioBlock) | ||
| Assertions.assertThat(processedBlock).isEqualTo(TestContent.newAudioBlock) | ||
| } | ||
|
|
||
| @Test | ||
| fun `processBlock leaves non-matching block unchanged`() { | ||
| val nonMatchingId = "123" | ||
| val processor = AudioBlockProcessor(nonMatchingId, mediaFile) | ||
| val processedBlock = processor.processBlock(TestContent.oldFileBlock) | ||
| Assertions.assertThat(processedBlock).isEqualTo(TestContent.oldFileBlock) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.