|
|
|
|
@ -10,21 +10,15 @@ import androidx.lifecycle.ViewModelProviders |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_replayer.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.BaseFragment |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.HandHistoryViewModel |
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
class ReplayerFragment : RealmFragment() { |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The fragment's ViewModel |
|
|
|
|
*/ |
|
|
|
|
private lateinit var model: HandHistoryViewModel |
|
|
|
|
|
|
|
|
|
private var steps: List<HandStep> = listOf() |
|
|
|
|
|
|
|
|
|
// private lateinit var configuration: ReplayerConfiguration |
|
|
|
|
private lateinit var model: ReplayerModel |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
|
@ -41,7 +35,7 @@ class ReplayerFragment : RealmFragment() { |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
|
|
|
|
this.model = activity?.run { |
|
|
|
|
ViewModelProviders.of(this)[HandHistoryViewModel::class.java] |
|
|
|
|
ViewModelProviders.of(this)[ReplayerModel::class.java] |
|
|
|
|
} ?: throw Exception("Invalid Activity") |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -50,73 +44,91 @@ class ReplayerFragment : RealmFragment() { |
|
|
|
|
|
|
|
|
|
// TODO change |
|
|
|
|
val hh = getRealm().where(HandHistory::class.java).findFirst()!! |
|
|
|
|
Timber.d(">>> Load HH with player count = ${hh.numberOfPlayers}") |
|
|
|
|
this.model.setHandHistory(hh) |
|
|
|
|
// Timber.d(">>> Load HH with player count = ${hh.numberOfPlayers}") |
|
|
|
|
// this.model.setHandHistory(hh) |
|
|
|
|
|
|
|
|
|
loadHand(this.model.handHistory) |
|
|
|
|
val hhm = ViewModelProviders.of(this)[HandHistoryViewModel::class.java] |
|
|
|
|
loadHand(hh) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
this.next_action.setOnClickListener { |
|
|
|
|
nextAction() |
|
|
|
|
} |
|
|
|
|
this.previous_action.setOnClickListener { |
|
|
|
|
previousAction() |
|
|
|
|
} |
|
|
|
|
this.next_hand.setOnClickListener { |
|
|
|
|
nextHand() |
|
|
|
|
} |
|
|
|
|
this.previous_hand.setOnClickListener { |
|
|
|
|
previousHand() |
|
|
|
|
} |
|
|
|
|
this.play_pause.setOnClickListener { |
|
|
|
|
playOrPause() |
|
|
|
|
} |
|
|
|
|
this.speed.setOnClickListener { |
|
|
|
|
changeSpeed() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun loadHand(handHistory: HandHistory) { |
|
|
|
|
this.steps = HandStep.createSteps(handHistory) |
|
|
|
|
this.replayer.configuration = ReplayerConfiguration(handHistory) |
|
|
|
|
updateSpeedButtonText() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var isPlaying: Boolean = false |
|
|
|
|
private fun updateSpeedButtonText() { |
|
|
|
|
this.speed.text = "${this.model.speedMultiplier}x" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val mainHandler = Handler(Looper.getMainLooper()) |
|
|
|
|
private fun loadHand(handHistory: HandHistory) { |
|
|
|
|
val config = ReplayerConfiguration(handHistory) |
|
|
|
|
this.replayer.configuration = config |
|
|
|
|
this.model.configuration = config |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val actionSpeed = 1000L |
|
|
|
|
var speedMultiplier = 1 |
|
|
|
|
private val mainHandler = Handler(Looper.getMainLooper()) |
|
|
|
|
|
|
|
|
|
private val timerRunnable: Runnable = Runnable { |
|
|
|
|
nextAction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun playOrPause() { |
|
|
|
|
private fun playOrPause() { |
|
|
|
|
|
|
|
|
|
if (this.isPlaying) { |
|
|
|
|
if (this.model.isPlaying) { |
|
|
|
|
mainHandler.removeCallbacks(timerRunnable) |
|
|
|
|
} else { |
|
|
|
|
mainHandler.postDelayed(timerRunnable, 0L) |
|
|
|
|
} |
|
|
|
|
this.isPlaying = !this.isPlaying |
|
|
|
|
this.model.isPlaying = !this.model.isPlaying |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var stepIndex: Int = 0 |
|
|
|
|
private fun nextAction() { |
|
|
|
|
|
|
|
|
|
fun nextAction() { |
|
|
|
|
if (this.stepIndex < this.steps.size - 1) { |
|
|
|
|
this.stepIndex += 1 |
|
|
|
|
playAction() |
|
|
|
|
this.model.next?.let { |
|
|
|
|
this.replayer.next(it) |
|
|
|
|
} |
|
|
|
|
if (this.isPlaying) { |
|
|
|
|
mainHandler.postDelayed(timerRunnable, speedMultiplier * actionSpeed) |
|
|
|
|
|
|
|
|
|
if (this.model.isPlaying) { |
|
|
|
|
mainHandler.postDelayed(timerRunnable, this.model.actionDelay) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun previousAction() { |
|
|
|
|
if (this.stepIndex > 0) { |
|
|
|
|
this.stepIndex -= 1 |
|
|
|
|
playAction() |
|
|
|
|
private fun previousAction() { |
|
|
|
|
this.model.previous?.let { |
|
|
|
|
this.replayer.previous(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun playAction() { |
|
|
|
|
this.replayer.step = this.steps[this.stepIndex] |
|
|
|
|
this.replayer.invalidate() // force redraw |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun nextHand() { |
|
|
|
|
private fun nextHand() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun previousHand() { |
|
|
|
|
private fun previousHand() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun changeSpeed() { |
|
|
|
|
this.model.changeSpeed() |
|
|
|
|
updateSpeedButtonText() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |