Skip to content
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

Progress and Error notifications: keep state of multiple concurrent Stories being saved #297

Conversation

mzorz
Copy link
Contributor

@mzorz mzorz commented Apr 9, 2020

Builds on top of #287

This PR fixes the problem identified in #286 (comment), by keeping state in the FrameSaveNotifier class of the amount of frames being saved belonging to different Stories.
This gives us 2 precious things:

  1. the ability to change the foreground progress notification title from Saving <story title>... to Saving several stories... and viceversa depending on how things are going
  2. the ability to have distinct error notifications for each Story being uploaded.

Screenshots:

Screen Shot 2020-04-09 at 18 43 45

Screen Shot 2020-04-09 at 18 43 18

Video showcasing this here:

https://cloudup.com/cMS87Fa9j3i

To test

CASE A: Happy path:

  1. we'll need to have a way to distinguish Stories, so replace line 150 in ComposeLoopFrameActivity with this:
storyViewModel.setCurrentStoryTitle("Test" + index)

This will set the story title to be something like Test0 or Test1, etc.

  1. run the app, select some 6-8 videos to upload
  2. add some text / emoji to each one of them
  3. tap NEXT to start the service
  4. as soon as you exit the Activity, drag from the top border of the screen down to the center, to observe the foreground notification. You should see the Saving Test0... title on it.
  5. tap on + to create a new story
  6. add another 2 videos there, and add some emoji/text (need to be quick here)
  7. drag from the top border of the screen down to the center, to observe the foreground notification. You should now see Saving several stories... title on it.
  8. Just wait and see how it changes, at some point the title should switch to Saving Test1... note it's no longer Test0, but Test1, indicating Test0 has finished now and we only have frames from Test1 remaining to be saved.

CASE B: Error path

  1. apply the patch provided in this gist. This is got several modifications just to deliberately throw an artificial exception for two different stories, for one of their video frames, when these reach 80% of progress being saved.
  2. select some 6-8 videos to upload
  3. add some text / emoji to each one of them
  4. tap NEXT to start the service
  5. as soon as you exit the Activity, tap on + to create a new story
  6. add another 2 videos there, and add some emoji/text (need to be quick here)
  7. when everything (or most) ends, the first video for each of these 2 stories should have failed, and hence you should have 2 distinct error notifications showing on your system dashboard.
  8. tap on one, verify it's for the long story
  9. tap on the second one, verify it's for the short (2 video frames) story.

mzorz added 3 commits April 9, 2020 11:55
…we're saving concurrently, to show the right progress notifications
…n the foregorund and we tap on a new error notification
@peril-automattic
Copy link

peril-automattic bot commented Apr 9, 2020

You can test the changes on this Pull Request by downloading the APK here.

@mzorz mzorz marked this pull request as ready for review April 9, 2020 22:44
@mzorz mzorz requested review from jd-alexander and marecar3 April 9, 2020 22:44
@jd-alexander
Copy link
Contributor

Hi @mzorz 😄 so I tried the Happy path but I kept getting a crash when I tried to create the second story. So what I think is happening is

  1. I create the first story and several videos.
  2. I go back to create the second story but the previous frames are already there and I click next again and these are added to the current story being processed.
  3. Then when I try to create another story again I get a crash. I wasn't able to get the stacktrace. I am trying to see if I can get it after the crash and if so I will share here 🙏

@mzorz mzorz changed the title Keep state of multiple concurrent Stories being saved Progress and Error notifications: keep state of multiple concurrent Stories being saved Apr 10, 2020
@mzorz
Copy link
Contributor Author

mzorz commented Apr 13, 2020

Thank you for your review, tests, and comments all around @jd-alexander !

#297 (comment)

  1. I create the first story and several videos.
  2. I go back to create the second story but the previous frames are already there and I click next again and these are added to the current story being processed.

I haven't been able to reproduce this issue here (...create the second story but the previous frames are already there ) on the Pixel 3 on this branch - although a change introduced later on in PR #289, particularly in this commit 2201c0f should also help avoid this kind of situation completely, given new stories are always signaled with the special case DEFAULT_NONE_SELECTED.

  1. Then when I try to create another story again I get a crash. I wasn't able to get the stacktrace. I am trying to see if I can get it after the crash and if so I will share here 🙏

Thanks for this one 🙏. As discussed, tracked this one here #299 and going to tackle it separately (it's happening on develop as well). In the meantime (so to test this PR) you should be able to workaround this crash by setting a fixed size here like this:

            //.size(originalCanvasWidth, originalCanvasHeight)
            .size(1440, 2560)

Or alternatively, use a Pixel 2 emulator where we know this issue won't be run into.

I think we should be able to continue unless on your side you see anything else blocking the tests for this PR? wdyt?

@@ -318,8 +377,11 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame
doNotify(notificationId, notificationBuilder.build()) // , notificationType)
}

fun getNotificationIdForError(): Long {
return BASE_MEDIA_ERROR_NOTIFICATION_ID.toLong()
fun getNotificationIdForError(storyIdx: StoryIndex): Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be renamed to storyIndex when I was scrolling and I saw it I thought it meant id and then I realized it's in an index. Of course, it's not necessary. Just a thought :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍 fixed in 03f31b5

@jd-alexander
Copy link
Contributor

jd-alexander commented Apr 14, 2020

I just got another crash. Not sure if it's related. I was trying to follow the happy path. I added the first set of stories but upon adding the second set the crash occurred. Let me know if this is related to this PR #292

    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5106)
        at android.view.ViewGroup.addView(ViewGroup.java:4935)
        at android.view.ViewGroup.addView(ViewGroup.java:4907)
        at com.automattic.photoeditor.PhotoEditor.addViewToParent(PhotoEditor.kt:370)
        at com.automattic.photoeditor.PhotoEditor.addViewToParent$default(PhotoEditor.kt:365)
        at com.automattic.portkey.compose.ComposeLoopFrameActivity.onStoryFrameSelected(ComposeLoopFrameActivity.kt:1309)
        at com.automattic.portkey.compose.story.StoryFrameSelectorFragment$onCreate$2.onChanged(StoryFrameSelectorFragment.kt:43)
        at com.automattic.portkey.compose.story.StoryFrameSelectorFragment$onCreate$2.onChanged(StoryFrameSelectorFragment.kt:27)
        at com.automattic.portkey.util.SingleLiveEvent$observe$1.onChanged(SingleLiveEvent.kt:50)
        at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
        at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
        at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
        at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
        at com.automattic.portkey.util.SingleLiveEvent.setValue(SingleLiveEvent.kt:58)
        at com.automattic.portkey.compose.story.StoryViewModel.setSelectedFrameByUser(StoryViewModel.kt:69)
        at com.automattic.portkey.compose.story.StoryViewModel$createUiStateFromModelState$$inlined$forEachIndexed$lambda$1.invoke(StoryViewModel.kt:190)
        at com.automattic.portkey.compose.story.StoryViewModel$createUiStateFromModelState$$inlined$forEachIndexed$lambda$1.invoke(StoryViewModel.kt:12)
        at com.automattic.portkey.compose.story.StoryFrameSelectorAdapter$StoryFrameHolder$StoryFrameHolderItem$1.onClick(StoryFrameSelectorAdapter.kt:108)
        at android.view.View.performClick(View.java:7125)

Copy link
Contributor

@jd-alexander jd-alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. So I was able to get the happy path working on my Pixel 4 XL device.
  2. For the error path, I applied the patch and got the error notifications as expected.
    I was also able to click on the stories and I was taken to the compose screen with the videos I selected for processing. LGTM 🚢 🕺

I left some minor comments 👍

@jd-alexander
Copy link
Contributor

jd-alexander commented Apr 14, 2020

@mzorz something I noticed when testing on my Pixel 4 XL. I wasn't able to add the emojis. Let me know if this is something you can reproduce or if you have been tracking this. Thanks, I think it might be device-related. It works fine on the emulator.

@mzorz
Copy link
Contributor Author

mzorz commented Apr 15, 2020

I just got another crash. Not sure if it's related. I was trying to follow the happy path. I added the first set of stories but upon adding the second set the crash occurred. Let me know if this is related to this PR #292

Yes exactly that crash was fixed in #290, merged in #292 and also another layer of protection was added (as I ran into another case) in this WIP PR. That one should cover it 💪

@mzorz something I noticed when testing on my Pixel 4 XL. I wasn't able to add the emojis. Let me know if this is something you can reproduce or if you have been tracking this. Thanks, I think it might be device-related. It works fine on the emulator.

Yeah saw this one too on the Pixel 3 emulator, on develop. Tracking it down in #301. Will prioritize accordingly, once I get the main feature ready 👍

@mzorz
Copy link
Contributor Author

mzorz commented Apr 15, 2020

Thanks for your review once more Joel! Merging now 👍

@mzorz mzorz merged commit 78132a6 into issue/273-save-frame-service-no-state Apr 15, 2020
@mzorz mzorz deleted the issue/273-save-frame-service-no-state-multi-errror branch April 15, 2020 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants