diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt index ddf3c27a..e4d5591a 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt @@ -73,12 +73,12 @@ class ReplayerConfiguration(var handHistory: HandHistory) { private var lastBlindIndex: Int = 0 - private var stepIndex: Int = 0 + private var currentStepIndex: Int = 0 set(value) { val backwards = value < field field = value - // if we go backwards we don't want to perform an animate, otherwise we want + // if we go backwards we don't want to perform an animation, otherwise we want this.currentFrame = if (backwards) this.numberOfFramesForCurrentStep - 1 else 0 } @@ -86,7 +86,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) { this.actionList.load(this.handHistory) this.lastBlindIndex = max(this.actionList.indexOfLast { it.action.type?.isBlind == true }, 0) - this.stepIndex = this.lastBlindIndex + 1 // initialize at big blind + this.currentStepIndex = this.lastBlindIndex + 1 // initialize at big blind this.steps = HandStep.createSteps(this.handHistory) } @@ -366,20 +366,20 @@ class ReplayerConfiguration(var handHistory: HandHistory) { } fun next() { - if (this.steps.size > this.stepIndex + 1) { - this.stepIndex += 1 + if (this.steps.size > this.currentStepIndex + 1) { + this.currentStepIndex += 1 } } fun previous() { - if (this.stepIndex > this.lastBlindIndex + 1) { - this.stepIndex -= 1 + if (this.currentStepIndex > this.lastBlindIndex + 1) { + this.currentStepIndex -= 1 } } val currentStep: HandStep get() { - return this.steps[this.stepIndex] + return this.steps[this.currentStepIndex] } private val lastActionAtStep: ComputedAction? @@ -389,7 +389,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) { return step } else -> { - (0 until stepIndex).reversed().forEach { i -> + (0 until currentStepIndex).reversed().forEach { i -> val hs = this.steps[i] if (hs is ComputedAction) { return hs @@ -442,6 +442,16 @@ class ReplayerConfiguration(var handHistory: HandHistory) { return Circle(x, y, radius) } + fun restart() { + this.currentStepIndex = 0 + this.currentFrame = 0 + } + + val isReplayFinished: Boolean + get() { + return this.currentStepIndex >= this.steps.size - 1 && this.currentFrame >= this.numberOfFramesForCurrentStep - 1 + } + } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerFragment.kt index 1086be7a..67aaf736 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerFragment.kt @@ -93,11 +93,28 @@ class ReplayerFragment : RealmFragment() { private fun playOrPause() { if (this.model.isPlaying) { - mainHandler.removeCallbacks(timerRunnable) + pause() } else { - mainHandler.postDelayed(timerRunnable, 0L) + play() } - this.model.isPlaying = !this.model.isPlaying + } + + private fun play() { + + val isFinished = this.model.configuration?.isReplayFinished ?: false + if (isFinished) { + this.model.configuration?.restart() + } + + mainHandler.postDelayed(timerRunnable, 0L) + this.model.isPlaying = true + this.play_pause.setImageResource(R.drawable.ic_outline_pause) + } + + private fun pause() { + mainHandler.removeCallbacks(timerRunnable) + this.model.isPlaying = false + this.play_pause.setImageResource(R.drawable.ic_play_arrow) } private fun nextAction() { @@ -105,16 +122,26 @@ class ReplayerFragment : RealmFragment() { this.replayer.refresh() if (this.model.isPlaying) { - mainHandler.postDelayed(timerRunnable, this.model.actionDelay) + this.mainHandler.postDelayed(timerRunnable, this.model.actionDelay) } + refreshPlayButtonIfNecessary() + } + + private fun refreshPlayButtonIfNecessary() { + + val isFinished = this.model.configuration?.isReplayFinished ?: true + if (isFinished) { + pause() + } + } private fun previousAction() { this.model.previousStep() this.replayer.refresh() + refreshPlayButtonIfNecessary() } - private fun nextHand() { // TODO } 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 5100d68e..c23c8cc2 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 @@ -31,7 +31,7 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) fun refresh() { - if (configuration.shouldShowAdditionalFrame) { + if (this.configuration.shouldShowAdditionalFrame) { this.invalidate() animationHandler.postDelayed(this.timerRunnable, this.configuration.animationRate) } 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 c57f76ce..c23abe5d 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 @@ -457,6 +457,10 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private fun drawPot(street: Street, computedAction: ComputedAction?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + if (street == Street.SUMMARY && config.frameType != ReplayerConfiguration.FrameType.GATHER_ANIMATION) { + return + } + val pot = config.actionList.potSizeForStreet(street) val action = computedAction ?: config.lastActionBeforeStreet(street)