-
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
Mobile stories block - part 2: (on "done" editing clicked) #12982
Merged
mzorz
merged 81 commits into
feature/jetpack-stories-block-base
from
try/jetpack-stories-block-on-done
Oct 14, 2020
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
c21e3e3
passing blockId, mediaFiles and state in result
mzorz b9212ef
connect onActivityResult in EditPostActivity to call GutenbergEditorF…
mzorz acf2ef8
refactor to reuse block mediaFiles building
mzorz cd42ffb
connected the DONE button to pass the updated content story block bac…
mzorz edfe5af
fixed merge conflict
mzorz 4873009
Merge branch 'try/jetpack-stories-block' into try/jetpack-stories-blo…
mzorz aacfac7
fixed merge conflict, moving call within failedLoadingOrReCreatingSto…
mzorz 50769fa
Merge branch 'try/jetpack-stories-block' into try/jetpack-stories-blo…
mzorz 9ef826d
fixed lint warnings
mzorz d7884c8
modified the bridge to have instances of EditorMedialListener so thes…
mzorz 7f5453b
udpated stories lib hash
mzorz 1e41de1
added all listeners to handle Story Save progress when editing a Stor…
mzorz e532633
updated stories library commit hash
mzorz 2a74a35
removed unused param constant key
mzorz b545212
added FrameSaveXyz status EventBus events for Story frame flattened m…
mzorz baaad61
using StorySaveMediaListener and removed redundant interface StoryEdi…
mzorz a2e5aaa
using made-up temporaryIds out of StoryIndex-FrameIndex to paint save…
mzorz e5adabf
made changes to support String mediaIds as opposed to ints, so we can…
mzorz 3db3235
using StoryRepositoryWrapper so it's injectable and lets StoryMediaSa…
mzorz d2af486
updated gutenberg-mobile commit hash, also passing overall story save…
mzorz 5874a48
added progress calculation and progress calls
mzorz fcef7a8
implemented new onStorySaveResult gutenberg bridge method
mzorz edbc1e7
udpated commit hash for gutenberg mobile with stories block update
mzorz 83a977e
added StoryFrameMediaModelCreatedEvent event to signal Gutenberg of t…
mzorz a2f0111
updated gutenberg hash, fixed media upload succesful mediaID and remo…
mzorz e0a108d
making sure to pass the Post's localId so it's loaded back in the bri…
mzorz 12b2563
avoid IOBException by making sure the list is non-emtpy
mzorz 77d27cf
only save a post in the bridge if we are not editing it - if we are e…
mzorz 6114c61
fixed bug, was using the 'alt' field to look for a temporary id, shou…
mzorz 0b016d6
fixed comment
mzorz 23fcff5
refactored and added method StoriesPrefs.replaceLocalMediaIdKeyedSlid…
mzorz a8bfdb3
enclosed one check for media !=null needed by all other checks
mzorz b0ccacd
moved else if, wasn't ever going to run otherwise
mzorz ce59912
added call to updateAndSavePostAsync after adding a remote media to t…
mzorz 9749799
fixed line length
mzorz fcfb771
updated stories lib hash to keep up with camera preview launch fix
mzorz 3b6095c
updated gutenberg-mobile hash, commented lines
mzorz 9bc74f3
using StoryRepositoryWrapper
mzorz 7fedb76
updated stories cmomit hash with bugfixes
mzorz d9978b9
updated stories lib hash - fixed lint warnings
mzorz 2ec71f9
removed old comment
mzorz e9dc830
add support for editing an existing uploaded Story and adding a frame…
mzorz 4e005ae
implemented git onFrameRemove() listener method and cleaning StoriesP…
mzorz 144e3ce
updated commit hash for stories library
mzorz 64cc559
safeguard against a Story being corrupt (for example a crash when sav…
mzorz de7a2ba
updated gutenberg mobile commit hash
mzorz 7c04d20
fixed lint warnings
mzorz 0d554b4
updated mobile gutenberg commit hash
mzorz 35f2f55
updated commit hash for gutenberg mobile with fix in gutenberg mobile…
mzorz 8c0a245
updated gutenberg-mobile and jetpack story block commit hash
mzorz 27c628a
fixed merge conflict
mzorz 34509cb
added explicit null check
mzorz 85a10af
updated commit hash for mobile-gutenberg
mzorz 05eef82
fixed merge conflicts with base branch
mzorz 240aebb
changed method signature for kotlin's Any
mzorz a6dee81
moved FrameSaveListener methods to StoriesEventListener lifecycle obs…
mzorz ecbdeb8
Merge branch 'try/jetpack-stories-block' into try/jetpack-stories-blo…
mzorz 36a025f
fixed merge conflicts
mzorz 1e5e84d
fixed method signature
mzorz 4ca77a1
updated from base branch
mzorz 8a4bc32
updated gutenberg-mobile hash
mzorz 8905d3f
updated gutenberg-mobile hash
mzorz 670fb08
updated gutenberg mobile hash
mzorz f3c949e
using new method names for gutetnberg-mobile bridge
mzorz 69b1aa2
updated gutenberg-mobile commit hash
mzorz f7c9657
renamed bridge methods to more generic onMediaFilesEditorLoadRequestL…
mzorz 864317f
updated gutenberg-mobile commit hash with bridge method renames
mzorz 88fdf9d
updated commit hash for gutenberg-mobile and stories-android, minor l…
mzorz 338208d
Merge branch 'try/jetpack-stories-block-on-done' into try/jetpack-sto…
mzorz 745a1c7
updated gutenberg-mobile commit hash
mzorz d065c92
using eventBusWrapper
mzorz 29f27c8
Update WordPress/src/main/java/org/wordpress/android/ui/posts/editor/…
mzorz 5505f7d
Update WordPress/src/main/java/org/wordpress/android/ui/stories/SaveS…
mzorz 8b9885f
stripped String type from method name, as it can be inferred from the…
mzorz f0c509d
Update WordPress/src/main/java/org/wordpress/android/ui/stories/Story…
mzorz 8def90f
Update WordPress/src/main/java/org/wordpress/android/ui/stories/media…
mzorz eff3b28
renamed to shorten name
mzorz 873a364
updated gutenberg-mobile commit hash
mzorz bb63fc3
updated commit hash for gutenberg-mobile
mzorz 5349075
Merge pull request #13101 from wordpress-mobile/try/jetpack-stories-b…
mzorz 640183e
updated commit hash after merge
mzorz 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 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 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
159 changes: 159 additions & 0 deletions
159
WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StoriesEventListener.kt
This file contains 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,159 @@ | ||
package org.wordpress.android.ui.posts.editor | ||
|
||
import android.net.Uri | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.Lifecycle.State.CREATED | ||
import androidx.lifecycle.LifecycleObserver | ||
import androidx.lifecycle.OnLifecycleEvent | ||
import com.wordpress.stories.compose.frame.StorySaveEvents.FrameSaveCompleted | ||
import com.wordpress.stories.compose.frame.StorySaveEvents.FrameSaveFailed | ||
import com.wordpress.stories.compose.frame.StorySaveEvents.FrameSaveProgress | ||
import com.wordpress.stories.compose.frame.StorySaveEvents.FrameSaveStart | ||
import com.wordpress.stories.compose.frame.StorySaveEvents.StorySaveResult | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.wordpress.android.editor.gutenberg.StorySaveMediaListener | ||
import org.wordpress.android.fluxc.Dispatcher | ||
import org.wordpress.android.fluxc.model.MediaModel | ||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.fluxc.store.MediaStore | ||
import org.wordpress.android.ui.stories.SaveStoryGutenbergBlockUseCase.Companion.TEMPORARY_ID_PREFIX | ||
import org.wordpress.android.ui.stories.StoryRepositoryWrapper | ||
import org.wordpress.android.ui.stories.media.StoryMediaSaveUploadBridge.StoryFrameMediaModelCreatedEvent | ||
import org.wordpress.android.util.EventBusWrapper | ||
import org.wordpress.android.util.FluxCUtils | ||
import org.wordpress.android.util.helpers.MediaFile | ||
import javax.inject.Inject | ||
|
||
class StoriesEventListener @Inject constructor( | ||
private val dispatcher: Dispatcher, | ||
private val mediaStore: MediaStore, | ||
private val eventBusWrapper: EventBusWrapper, | ||
private val storyRepositoryWrapper: StoryRepositoryWrapper | ||
) : LifecycleObserver { | ||
private lateinit var lifecycle: Lifecycle | ||
private lateinit var site: SiteModel | ||
private var storySaveMediaListener: StorySaveMediaListener? = null | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE) | ||
private fun onCreate() { | ||
dispatcher.register(this) | ||
eventBusWrapper.register(this) | ||
} | ||
|
||
/** | ||
* Handles the [Lifecycle.Event.ON_DESTROY] event to cleanup the registration for dispatcher and removing the | ||
* observer for lifecycle. | ||
*/ | ||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | ||
private fun onDestroy() { | ||
lifecycle.removeObserver(this) | ||
dispatcher.unregister(this) | ||
eventBusWrapper.unregister(this) | ||
} | ||
|
||
fun start(lifecycle: Lifecycle, site: SiteModel) { | ||
this.site = site | ||
this.lifecycle = lifecycle | ||
this.lifecycle.addObserver(this) | ||
} | ||
|
||
fun setSaveMediaListener(newListener: StorySaveMediaListener) { | ||
storySaveMediaListener = newListener | ||
} | ||
|
||
// Story Frame Save Service events | ||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStoryFrameSaveStart(event: FrameSaveStart) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
val localMediaId = event.frameId.toString() | ||
val progress = storyRepositoryWrapper.getCurrentStorySaveProgress(event.storyIndex, 0.0f) | ||
storySaveMediaListener?.onMediaSaveReattached(localMediaId, progress) | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStoryFrameSaveProgress(event: FrameSaveProgress) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
val localMediaId = event.frameId.toString() | ||
val progress: Float = storyRepositoryWrapper.getCurrentStorySaveProgress( | ||
event.storyIndex, | ||
event.progress | ||
) | ||
storySaveMediaListener?.onMediaSaveProgress(localMediaId, progress) | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStoryFrameSaveCompleted(event: FrameSaveCompleted) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
val localMediaId = requireNotNull(event.frameId) | ||
|
||
// check whether this is a temporary file being just saved (so we don't have a proper local MediaModel yet) | ||
// catch ( NumberFormatException e) | ||
if (localMediaId.startsWith(TEMPORARY_ID_PREFIX)) { | ||
val (frames) = storyRepositoryWrapper.getStoryAtIndex(event.storyIndex) | ||
|
||
// first, update the media's url | ||
val frame = frames[event.frameIndex] | ||
storySaveMediaListener?.onMediaSaveSucceeded( | ||
localMediaId, | ||
Uri.fromFile(frame.composedFrameFile).toString() | ||
) | ||
|
||
// now update progress | ||
val totalProgress: Float = storyRepositoryWrapper.getCurrentStorySaveProgress( | ||
event.storyIndex, | ||
0.0f | ||
) | ||
storySaveMediaListener?.onMediaSaveProgress(localMediaId, totalProgress) | ||
} else { | ||
val mediaModel: MediaModel = mediaStore.getSiteMediaWithId(site, localMediaId.toLong()) | ||
if (mediaModel != null) { | ||
val mediaFile: MediaFile = FluxCUtils.mediaFileFromMediaModel(mediaModel) | ||
storySaveMediaListener?.onMediaSaveSucceeded(localMediaId, mediaFile.getFileURL()) | ||
} | ||
} | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStoryFrameMediaModelCreated(event: StoryFrameMediaModelCreatedEvent) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
storySaveMediaListener?.onMediaModelCreatedForFile(event.oldId, event.newId, event.oldUrl) | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStoryFrameSaveFailed(event: FrameSaveFailed) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
val localMediaId = event.frameId.toString() | ||
// just update progress, we may have still some other frames in this story that need be saved. | ||
// we will send the Failed signal once all the Story frames have been processed | ||
val progress: Float = storyRepositoryWrapper.getCurrentStorySaveProgress(event.storyIndex, 0.0f) | ||
storySaveMediaListener?.onMediaSaveReattached(localMediaId, progress) | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onStorySaveProcessFinished(event: StorySaveResult) { | ||
if (!lifecycle.currentState.isAtLeast(CREATED)) { | ||
return | ||
} | ||
val story = storyRepositoryWrapper.getStoryAtIndex(event.storyIndex) | ||
if (event.isSuccess() && event.frameSaveResult.size == story.frames.size) { | ||
// take the first frame IDs and mediaUri | ||
val localMediaId = story.frames[0].id.toString() | ||
val mediaUrl: String = Uri.fromFile(story.frames[0].composedFrameFile).toString() | ||
storySaveMediaListener?.onMediaSaveSucceeded(localMediaId, mediaUrl) | ||
} else { | ||
val localMediaId = story.frames[0].id.toString() | ||
storySaveMediaListener?.onMediaSaveFailed(localMediaId) | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
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.
NitPick 😅 Hi @mzorz could we put these dialogs and such forth in this method in another class? Or is it not worth it? I just glanced at the code again and it might not be worth the effort. If we could somehow simplify the dialog code with a
Util
function or something so we don't add too many lines here.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.
Yeah I understand where you come from - I think the logic is simple enough to follow but it's true it's "too vertical" and exceeds the screen, to add that we don't want this class to keep growing much. Might do that at a later phase 👍 (added to my ToDo list as well)
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.
Just following up here - addressed this here #13198