diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt index 7db59bb0..7ceee45d 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt @@ -57,8 +57,8 @@ class ReplayExportService : Service() { fun gifExport(handHistoryId: String) { this@ReplayExportService.handHistoryId = handHistoryId startGIFExport() - } + private fun startGIFExport() { GlobalScope.launch(coroutineContext) { @@ -76,7 +76,7 @@ class ReplayExportService : Service() { val width = square val height = square - animator.setDimension(width.toFloat(), height.toFloat()) + animator.configure(width.toFloat(), height.toFloat(), context) val formattedDate = Date().dateTimeFileFormatted val path = File( @@ -92,7 +92,7 @@ class ReplayExportService : Service() { drawer.configurePaints(context, animator) var animationCount = 0 - animator.frames(drawer, context) { bitmap, count -> + animator.frames(context) { bitmap, count -> when { count > 10 -> { @@ -136,13 +136,14 @@ class ReplayExportService : Service() { val width = square val height = square - animator.setDimension(width.toFloat(), height.toFloat()) + animator.configure(width.toFloat(), height.toFloat(), this@ReplayExportService) +// animator.setDimension() val drawer = TableDrawer() drawer.configurePaints(context, animator) // generates all images and file descriptor Timber.d("Generating images for video...") - val tmpDir = animator.generateVideoContent(drawer, this@ReplayExportService) + val tmpDir = animator.generateVideoContent(this@ReplayExportService) val dpath = "${tmpDir.path}/$FFMPEG_DESCRIPTOR_FILE" // val directory = context.getExternalFilesDir(null) ?: throw PAIllegalStateException("File is invalid") diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt index ebb88016..43470af1 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt @@ -22,6 +22,7 @@ import java.util.* class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { // Steps & Frames + private var drawer = TableDrawer() /*** * The number of frames per second @@ -233,10 +234,17 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { var playerStrokeWidth = 8f var cardStrokeWidth = 8f + fun configure(width: Float, height: Float, context: Context) { + + this.setDimension(width, height) + this.drawer.configurePaints(context, this) + } + /*** * Calculates the position of all elements to draw */ - fun setDimension(width: Float, height: Float) { + private fun setDimension(width: Float, height: Float) { + Timber.d("Setting dimensions...") this.width = width this.height = height @@ -352,6 +360,9 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { } } + fun drawTable(canvas: Canvas, context: Context) { + this.drawer.drawTable(canvas, context) + } fun stackRectForPlayer(positionIndex: Int): RectF { return this.playerStackRects[positionIndex] @@ -486,7 +497,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { * Generates images and image descriptor to build the video using ffmpeg * Command line: https://trac.ffmpeg.org/wiki/Slideshow */ - suspend fun generateVideoContent(tableDrawer: TableDrawer, context: Context): File { + suspend fun generateVideoContent(context: Context): File { var ffmpegImageDescriptor = "" var count = 0 @@ -507,7 +518,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { val canvas = Canvas(bitmap) val vo = this.visualOccurences / 90.0 // this is needed before the call to drawTable which pass to the next frame - tableDrawer.drawTable(canvas, context) + this.drawer.drawTable(canvas, context) imagePath = File(directory, "img_$count.png").path @@ -545,7 +556,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { * As soon as a bitmap has been created, the [frameHandler] is called with the created * bitmap, and a appropriate occurrences of the bitmap to be added is passed along */ - fun frames(tableDrawer: TableDrawer, context: Context, frameHandler: (Bitmap, Int) -> Unit) { + fun frames(context: Context, frameHandler: (Bitmap, Int) -> Unit) { Timber.d("Step count = ${this.steps.size}") @@ -561,7 +572,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { val canvas = Canvas(bitmap) val vo = this.visualOccurences // this is needed before the call to drawTable which pass to the next frame - tableDrawer.drawTable(canvas, context) + this.drawer.drawTable(canvas, context) frameHandler(bitmap, vo) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt index edcbe607..5c1d9fdf 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt @@ -9,8 +9,6 @@ import android.view.View class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) { - private var drawer: TableDrawer = TableDrawer() - lateinit var animator: ReplayerAnimator private val animationHandler = Handler(Looper.getMainLooper()) @@ -21,8 +19,8 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) init { this.viewTreeObserver.addOnGlobalLayoutListener { - this.animator.setDimension(width.toFloat(), height.toFloat()) - this.drawer.configurePaints(context, this.animator) + this.animator.configure(width.toFloat(), height.toFloat(), context) +// this.drawer.configurePaints(context, this.animator) } } @@ -39,7 +37,7 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) super.onDraw(canvas) canvas?.let { - this.drawer.drawTable(canvas, context) + this.animator.drawTable(canvas, context) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt index 296d5d9c..fbfbec80 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt @@ -30,10 +30,6 @@ class TableDrawer { private val colorsByAmount = hashMapOf() -// fun clearColors() { -// this.colorsByAmount.clear() -// } - fun configurePaints(context: Context, animator: ReplayerAnimator) { this.animator = animator