Skip to content

Instantly share code, notes, and snippets.

@mzorz
Created April 9, 2020 22:41
Show Gist options
  • Save mzorz/3649ba15e6918fff024b36c8f1fae4c1 to your computer and use it in GitHub Desktop.
Save mzorz/3649ba15e6918fff024b36c8f1fae4c1 to your computer and use it in GitHub Desktop.
diff --git a/app/src/main/java/com/automattic/portkey/Portkey.kt b/app/src/main/java/com/automattic/portkey/Portkey.kt
index 7c85ea1..b1189b8 100644
--- a/app/src/main/java/com/automattic/portkey/Portkey.kt
+++ b/app/src/main/java/com/automattic/portkey/Portkey.kt
@@ -109,6 +109,8 @@ class Portkey : Application() {
companion object {
const val TAG = "Portkey"
+ var testFlagStory1: Int = 0
+ var testFlagStory2: Int = 0
}
fun setStatusBarHeight(newHeight: Int) {
diff --git a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
index 1723fd2..885e083 100644
--- a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
@@ -147,7 +147,8 @@ class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelectorTapped
val index = storyViewModel.getCurrentStoryIndex()
// TODO obtain the real Story title as assigned by the user when the BOTTOM SHEET is ready, and pass it up
- storyViewModel.setCurrentStoryTitle(getString(R.string.story_saving_untitled))
+ // storyViewModel.setCurrentStoryTitle(getString(R.string.story_saving_untitled))
+ storyViewModel.setCurrentStoryTitle("Test" + index)
frameSaveService.saveStoryFrames(index, photoEditor)
saveServiceBound = true
diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
index 3618065..d46a09a 100644
--- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
@@ -10,6 +10,7 @@ import com.automattic.photoeditor.PhotoEditor
import com.automattic.photoeditor.PhotoEditor.OnSaveWithCancelAndProgressListener
import com.automattic.photoeditor.views.PhotoEditorView
import com.automattic.photoeditor.views.ViewType.STICKER_ANIMATED
+import com.automattic.portkey.Portkey
import com.automattic.portkey.compose.story.StoryFrameItem
import com.automattic.portkey.compose.story.StoryFrameItem.BackgroundSource.FileBackgroundSource
import com.automattic.portkey.compose.story.StoryFrameItem.BackgroundSource.UriBackgroundSource
@@ -48,13 +49,14 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
suspend fun saveStory(
context: Context,
- frames: List<StoryFrameItem>
+ frames: List<StoryFrameItem>,
+ testIndex: Int
): List<File> {
// first, launch all frame save processes async
return frames.mapIndexed { index, frame ->
async {
yield()
- saveStoryFrame(context, frame, index)
+ saveStoryFrame(context, frame, index, testIndex)
}
}.awaitAll().filterNotNull()
}
@@ -62,12 +64,13 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
private suspend fun saveStoryFrame(
context: Context,
frame: StoryFrameItem,
- frameIndex: FrameIndex
+ frameIndex: FrameIndex,
+ testIndex: Int
): File? {
var frameFile: File? = null
when (frame.frameItemType) {
VIDEO -> {
- frameFile = saveVideoFrame(frame, frameIndex)
+ frameFile = saveVideoFrame(frame, frameIndex, testIndex)
}
IMAGE -> {
// check whether there are any GIF stickers - if there are, we need to produce a video instead
@@ -112,7 +115,8 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
private suspend fun saveVideoFrame(
frame: StoryFrameItem,
- frameIndex: FrameIndex
+ frameIndex: FrameIndex,
+ testIndex: Int
): File? {
var file: File? = null
@@ -139,6 +143,20 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
}
override fun onProgress(progress: Double) {
saveProgressListener?.onFrameSaveProgress(frameIndex, progress)
+ if (progress > 0.8) {
+ if (testIndex == 0) {
+ if (Portkey.testFlagStory1 == 0) {
+ Portkey.testFlagStory1 = 1
+ throw Exception("THIS IS A TEST1")
+ }
+ }
+ if (testIndex == 1) {
+ if (Portkey.testFlagStory2 == 0) {
+ Portkey.testFlagStory2 = 1
+ throw Exception("THIS IS A TEST2")
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
index c0f958f..77253b3 100644
--- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
@@ -14,6 +14,7 @@ import android.webkit.MimeTypeMap
import com.automattic.portkey.R
import com.automattic.portkey.compose.frame.FrameSaveManager.FrameSaveProgressListener
import com.automattic.photoeditor.PhotoEditor
+import com.automattic.portkey.Portkey
import com.automattic.portkey.compose.frame.FrameSaveService.SaveResultReason.SaveError
import com.automattic.portkey.compose.frame.FrameSaveService.SaveResultReason.SaveSuccess
import com.automattic.portkey.compose.story.StoryFrameItem
@@ -112,10 +113,12 @@ class FrameSaveService : Service() {
storyIndex: Int,
frames: List<StoryFrameItem>
) {
+ val testIndex = storyIndex
val frameFileList =
storySaveProcessor.saveStory(
this,
- frames
+ frames,
+ testIndex
)
// once all frames have been saved, issue a broadcast so the system knows these frames are ready
@@ -279,9 +282,10 @@ class FrameSaveService : Service() {
suspend fun saveStory(
context: Context,
- frames: List<StoryFrameItem>
+ frames: List<StoryFrameItem>,
+ testIndex: Int
): List<File> {
- return frameSaveManager.saveStory(context, frames)
+ return frameSaveManager.saveStory(context, frames, testIndex)
}
fun onCancel() {
diff --git a/app/src/main/java/com/automattic/portkey/Portkey.kt b/app/src/main/java/com/automattic/portkey/Portkey.kt
index 7c85ea1..b1189b8 100644
--- a/app/src/main/java/com/automattic/portkey/Portkey.kt
+++ b/app/src/main/java/com/automattic/portkey/Portkey.kt
@@ -109,6 +109,8 @@ class Portkey : Application() {
companion object {
const val TAG = "Portkey"
+ var testFlagStory1: Int = 0
+ var testFlagStory2: Int = 0
}
fun setStatusBarHeight(newHeight: Int) {
diff --git a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
index 1723fd2..885e083 100644
--- a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt
@@ -147,7 +147,8 @@ class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelectorTapped
val index = storyViewModel.getCurrentStoryIndex()
// TODO obtain the real Story title as assigned by the user when the BOTTOM SHEET is ready, and pass it up
- storyViewModel.setCurrentStoryTitle(getString(R.string.story_saving_untitled))
+ // storyViewModel.setCurrentStoryTitle(getString(R.string.story_saving_untitled))
+ storyViewModel.setCurrentStoryTitle("Test" + index)
frameSaveService.saveStoryFrames(index, photoEditor)
saveServiceBound = true
diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
index 3618065..d46a09a 100644
--- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt
@@ -10,6 +10,7 @@ import com.automattic.photoeditor.PhotoEditor
import com.automattic.photoeditor.PhotoEditor.OnSaveWithCancelAndProgressListener
import com.automattic.photoeditor.views.PhotoEditorView
import com.automattic.photoeditor.views.ViewType.STICKER_ANIMATED
+import com.automattic.portkey.Portkey
import com.automattic.portkey.compose.story.StoryFrameItem
import com.automattic.portkey.compose.story.StoryFrameItem.BackgroundSource.FileBackgroundSource
import com.automattic.portkey.compose.story.StoryFrameItem.BackgroundSource.UriBackgroundSource
@@ -48,13 +49,14 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
suspend fun saveStory(
context: Context,
- frames: List<StoryFrameItem>
+ frames: List<StoryFrameItem>,
+ testIndex: Int
): List<File> {
// first, launch all frame save processes async
return frames.mapIndexed { index, frame ->
async {
yield()
- saveStoryFrame(context, frame, index)
+ saveStoryFrame(context, frame, index, testIndex)
}
}.awaitAll().filterNotNull()
}
@@ -62,12 +64,13 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
private suspend fun saveStoryFrame(
context: Context,
frame: StoryFrameItem,
- frameIndex: FrameIndex
+ frameIndex: FrameIndex,
+ testIndex: Int
): File? {
var frameFile: File? = null
when (frame.frameItemType) {
VIDEO -> {
- frameFile = saveVideoFrame(frame, frameIndex)
+ frameFile = saveVideoFrame(frame, frameIndex, testIndex)
}
IMAGE -> {
// check whether there are any GIF stickers - if there are, we need to produce a video instead
@@ -112,7 +115,8 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
private suspend fun saveVideoFrame(
frame: StoryFrameItem,
- frameIndex: FrameIndex
+ frameIndex: FrameIndex,
+ testIndex: Int
): File? {
var file: File? = null
@@ -139,6 +143,20 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
}
override fun onProgress(progress: Double) {
saveProgressListener?.onFrameSaveProgress(frameIndex, progress)
+ if (progress > 0.8) {
+ if (testIndex == 0) {
+ if (Portkey.testFlagStory1 == 0) {
+ Portkey.testFlagStory1 = 1
+ throw Exception("THIS IS A TEST1")
+ }
+ }
+ if (testIndex == 1) {
+ if (Portkey.testFlagStory2 == 0) {
+ Portkey.testFlagStory2 = 1
+ throw Exception("THIS IS A TEST2")
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
index c0f958f..77253b3 100644
--- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
+++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt
@@ -14,6 +14,7 @@ import android.webkit.MimeTypeMap
import com.automattic.portkey.R
import com.automattic.portkey.compose.frame.FrameSaveManager.FrameSaveProgressListener
import com.automattic.photoeditor.PhotoEditor
+import com.automattic.portkey.Portkey
import com.automattic.portkey.compose.frame.FrameSaveService.SaveResultReason.SaveError
import com.automattic.portkey.compose.frame.FrameSaveService.SaveResultReason.SaveSuccess
import com.automattic.portkey.compose.story.StoryFrameItem
@@ -112,10 +113,12 @@ class FrameSaveService : Service() {
storyIndex: Int,
frames: List<StoryFrameItem>
) {
+ val testIndex = storyIndex
val frameFileList =
storySaveProcessor.saveStory(
this,
- frames
+ frames,
+ testIndex
)
// once all frames have been saved, issue a broadcast so the system knows these frames are ready
@@ -279,9 +282,10 @@ class FrameSaveService : Service() {
suspend fun saveStory(
context: Context,
- frames: List<StoryFrameItem>
+ frames: List<StoryFrameItem>,
+ testIndex: Int
): List<File> {
- return frameSaveManager.saveStory(context, frames)
+ return frameSaveManager.saveStory(context, frames, testIndex)
}
fun onCancel() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment