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

Serializing Story in onSaveInstanceState, retrieving it in onCreate #435

Merged
merged 24 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8ea7519
serializing Story in onSaveInstanceState, retrieving it in onCreate
mzorz Jul 8, 2020
fcac8af
added SerializersModule for SaveResult, and moved to companion object…
mzorz Jul 8, 2020
5e7ee46
fixed lint warning
mzorz Jul 8, 2020
43897cc
added custom serializer for AddedViewList in StoryFrameItem
mzorz Jul 8, 2020
ffde0db
saving serialized frames state in onSaveInstanceState
mzorz Jul 8, 2020
bf50efd
clearing the storyRepository instance when the StoryViewModel gets on…
mzorz Jul 8, 2020
07e8885
saving statet for selected frame index, and retrieving and updating t…
mzorz Jul 8, 2020
fedec43
keeping state of other flags
mzorz Jul 13, 2020
cac37be
adding touch listener to newly created views from deserializer
mzorz Jul 13, 2020
8f65a05
added getWorkingAreaRect method to OnPhotoEditorListener interface so…
mzorz Jul 14, 2020
c3bc426
don't clear PhotoEditor.clearAllViews() when tapping + to go to the m…
mzorz Jul 15, 2020
81a491a
forgot to remove parameter in method calls
mzorz Jul 15, 2020
6cbbe6b
introduced a Handler() to be able to setup views on Activity re-creat…
mzorz Jul 15, 2020
14fd24b
added method launchCameraPreviewWithSafeWait() to prevent launching t…
mzorz Jul 15, 2020
1a70555
adding methods launchCameraPreviewWithSurfaceSafeguard() and showPlay…
mzorz Jul 16, 2020
68470c3
added safeguards to only access videoPlayerHandling if isVideoPlayerV…
mzorz Jul 16, 2020
136dc06
reverted use of prepareSurfaceHandler, we're using a synchronous appr…
mzorz Jul 16, 2020
8e04786
check for IOOB fix
mzorz Jul 16, 2020
436946a
added isTextureViewAvailable() method to surfaceManager so we can alw…
mzorz Jul 16, 2020
f56c6a5
added supresslint annotation for added views
mzorz Jul 16, 2020
ef051e6
Merge branch 'issue/393-keep-state' into issue/393-keep-state-part2
mzorz Jul 17, 2020
2678c4e
fixed merge conflicts
mzorz Jul 17, 2020
8cceabd
removed unmeaningul comments
mzorz Jul 17, 2020
be674c2
fixed lint warning
mzorz Jul 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.automattic.photoeditor

import android.graphics.Rect
import android.view.View
import com.automattic.photoeditor.views.ViewType

Expand Down Expand Up @@ -70,4 +71,6 @@ interface OnPhotoEditorListener {
fun onStopViewChangeListener(viewType: ViewType)

fun onRemoveViewReadyListener(removedView: View, ready: Boolean)

fun getWorkingAreaRect(): Rect?
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class PhotoEditor private constructor(builder: Builder) :
return MultiTouchListener(
mainView,
deleteView,
workAreaRect,
parentView,
imageView,
isTextPinchZoomable,
Expand Down Expand Up @@ -402,6 +401,7 @@ class PhotoEditor private constructor(builder: Builder) :
} ?: buildViewFromAddedViewInfo(addedView.viewInfo, addedView.viewType)
}

@SuppressLint("ClickableViewAccessibility")
private fun buildViewFromAddedViewInfo(addedViewInfo: AddedViewInfo, viewType: ViewType): View? {
var view: View? = null
when (viewType) {
Expand All @@ -412,6 +412,9 @@ class PhotoEditor private constructor(builder: Builder) :
val emojiTextView = view?.findViewById<TextView>(R.id.tvPhotoEditorEmoji)
// the actual calculated text size as obtained from the view is expressed in px.
emojiTextView?.setTextSize(TypedValue.COMPLEX_UNIT_PX, addedViewInfo.addedViewTextInfo.fontSizePx)

val multiTouchListenerInstance = getNewMultitouchListener(view) // newMultiTouchListener
view?.touchableArea?.setOnTouchListener(multiTouchListenerInstance)
}
TEXT -> {
// create TEXT view layout
Expand All @@ -425,6 +428,9 @@ class PhotoEditor private constructor(builder: Builder) :
// the actual calculated text size as obtained from the view is expressed in px.
normalTextView?.setTextSize(TypedValue.COMPLEX_UNIT_PX, addedViewInfo.addedViewTextInfo.fontSizePx)
normalTextView?.setTextColor(addedViewInfo.addedViewTextInfo.textColor)

val multiTouchListenerInstance = getNewMultitouchListener(view) // newMultiTouchListener
view?.setOnTouchListener(multiTouchListenerInstance)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.automattic.photoeditor.views.ViewType
internal class MultiTouchListener(
private val mainView: View?,
private val deleteView: View?,
private val workingAreaRect: Rect?,
private val parentView: RelativeLayout,
private val photoEditImageView: ImageView,
private val mIsTextPinchZoomable: Boolean,
Expand Down Expand Up @@ -94,7 +93,7 @@ internal class MultiTouchListener(
val currY = event.getY(pointerIndexMove)
if (!mScaleGestureDetector.isInProgress) {
// if workingAreaRect is set, verify movement is within the area
workingAreaRect?.let {
mOnPhotoEditorListener?.getWorkingAreaRect()?.let {
if (isViewCenterInWorkingAreaBounds(view, currX - mPrevX, currY - mPrevY)) {
adjustTranslation(
view,
Expand Down Expand Up @@ -207,7 +206,7 @@ internal class MultiTouchListener(
val deltaVector = getWouldBeTranslation(view, deltaX, deltaY)
val wouldBeY = deltaVector[1] + view.y

workingAreaRect?.let {
mOnPhotoEditorListener?.getWorkingAreaRect()?.let {
val distanceToCenter = view.height / 2
return ((wouldBeY - distanceToCenter) > it.top) && ((wouldBeY + distanceToCenter) < it.bottom)
} ?: return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ class BackgroundSurfaceManager(
stopRecordingVideo()
}
isCameraVisible = false
isVideoPlayerVisible = false
videoPlayerHandling.deactivate()
if (isVideoPlayerVisible) {
isVideoPlayerVisible = false
videoPlayerHandling.deactivate()
}
photoEditorView.hideLoading()
photoEditorView.turnTextureViewOff()
}
Expand All @@ -179,12 +181,21 @@ class BackgroundSurfaceManager(
photoEditorView.turnTextureViewOn()
}

fun isTextureViewAvailable(): Boolean {
if (lifeCycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
return videoPlayerHandling.textureView.isAvailable && cameraBasicHandler.textureView.isAvailable
}
return false
}

fun switchCameraPreviewOn() {
isCameraVisible = true
isVideoPlayerVisible = false
// now, start showing camera preview
photoEditorView.turnTextureViewOn()
videoPlayerHandling.deactivate()
if (isVideoPlayerVisible) {
isVideoPlayerVisible = false
videoPlayerHandling.deactivate()
}
photoEditorView.hideLoading()
cameraBasicHandler.activate()
}
Expand Down Expand Up @@ -271,11 +282,15 @@ class BackgroundSurfaceManager(
}

fun videoPlayerMute() {
videoPlayerHandling.mute()
if (isVideoPlayerVisible) {
videoPlayerHandling.mute()
}
}

fun videoPlayerUnmute() {
videoPlayerHandling.unmute()
if (isVideoPlayerVisible) {
videoPlayerHandling.unmute()
}
}

private fun cameraXAwareSurfaceDeactivate() {
Expand Down
Loading