Skip to content

Commit

Permalink
removed measureTimeMillis, logging and unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mzorz committed Mar 18, 2020
1 parent 4c5b1f5 commit 6b4dcbd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Color
import android.net.Uri
import android.util.Log
import android.view.ViewGroup.LayoutParams
import android.widget.RelativeLayout
import com.automattic.photoeditor.PhotoEditor
Expand All @@ -24,12 +23,10 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield
import java.io.File
import kotlin.coroutines.CoroutineContext
import kotlin.system.measureTimeMillis

class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
private val job = Job()
Expand All @@ -45,19 +42,14 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
suspend fun saveStory(
context: Context,
frames: List<StoryFrameItem>
): List<File?>? {
var result: List<File?>? = null
Log.d("FrameSaveService", "saveStory() core 1")
): List<File?> {
// first, launch all frame save processes async
result = frames.mapIndexed { index, frame ->
return frames.mapIndexed { index, frame ->
async {
yield()
Log.d("FrameSaveService", "saveStory() core 2")
saveLoopFrame(context, frame, index)
}
}.awaitAll()
Log.d("FrameSaveService", "saveStory() core 3")
return result
}

private suspend fun saveLoopFrame(
Expand All @@ -66,26 +58,22 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
sequenceId: Int
): File? {
var frameFile: File? = null
Log.d("PORTKEY", "START SAVE: " + sequenceId)
val time = measureTimeMillis {
when (frame.frameItemType) {
VIDEO -> {
frameFile = saveVideoFrame(frame, sequenceId)
}
IMAGE -> {
// check whether there are any GIF stickers - if there are, we need to produce a video instead
if (frame.addedViews.containsAnyAddedViewsOfType(STICKER_ANIMATED)) {
// TODO make saveVideoWithStaticBackground return File
// saveVideoWithStaticBackground()
} else {
// create ghost PhotoEditorView to be used for saving off-screen
val ghostPhotoEditorView = createGhostPhotoEditor(context, photoEditor.composedCanvas)
frameFile = saveImageFrame(frame, ghostPhotoEditorView, sequenceId)
}
when (frame.frameItemType) {
VIDEO -> {
frameFile = saveVideoFrame(frame, sequenceId)
}
IMAGE -> {
// check whether there are any GIF stickers - if there are, we need to produce a video instead
if (frame.addedViews.containsAnyAddedViewsOfType(STICKER_ANIMATED)) {
// TODO make saveVideoWithStaticBackground return File
// saveVideoWithStaticBackground()
} else {
// create ghost PhotoEditorView to be used for saving off-screen
val ghostPhotoEditorView = createGhostPhotoEditor(context, photoEditor.composedCanvas)
frameFile = saveImageFrame(frame, ghostPhotoEditorView, sequenceId)
}
}
}
Log.d("PORTKEY", "END SAVE: " + sequenceId + " time: " + time)
return frameFile
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
import org.greenrobot.eventbus.EventBus
import kotlin.system.measureTimeMillis

class FrameSaveService : Service() {
private val binder = FrameSaveServiceBinder()
Expand Down Expand Up @@ -53,11 +52,9 @@ class FrameSaveService : Service() {
}

fun saveStoryFrames(storyIndex: Int, frameSaveManager: FrameSaveManager, frames: List<StoryFrameItem>) {
Log.d("FrameSaveService", "saveStoryFrames()")
this.storyIndex = storyIndex
this.frameSaveManager = frameSaveManager
CoroutineScope(Dispatchers.Default).launch {
Log.d("FrameSaveService", "saveStoryFrames() coroutine")
saveStoryFramesAndDispatchNewFileBroadcast(frameSaveManager, frames)
stopSelf()
}
Expand All @@ -67,25 +64,17 @@ class FrameSaveService : Service() {
frameSaveManager: FrameSaveManager,
frames: List<StoryFrameItem>
) {
val time = measureTimeMillis {
Log.d("FrameSaveService", "saveStoryFramesAndDispatchNewFileBroadcast() 1")
val frameFileList =
frameSaveManager.saveStory(
this,
frames
)

Log.d("FrameSaveService", "saveStoryFramesAndDispatchNewFileBroadcast() 2")

// once all frames have been saved, issue a broadcast so the system knows these frames are ready
frameFileList?.let {
sendNewMediaReadyBroadcast(frameFileList)
}
val frameFileList =
frameSaveManager.saveStory(
this,
frames
)

// TODO collect all the errors somehow before posting the SaveResult for the whole Story
EventBus.getDefault().post(StorySaveResult(true, storyIndex))
}
Log.d("PORTKEY", "TOTAL TIME: " + time)
// once all frames have been saved, issue a broadcast so the system knows these frames are ready
sendNewMediaReadyBroadcast(frameFileList)

// TODO collect all the errors somehow before posting the SaveResult for the whole Story
EventBus.getDefault().post(StorySaveResult(true, storyIndex))
}

private fun sendNewMediaReadyBroadcast(rawMediaFileList: List<File?>) {
Expand Down

0 comments on commit 6b4dcbd

Please sign in to comment.