|
|
|
|
@ -6,6 +6,7 @@ import android.view.animation.OvershootInterpolator |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_session.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
@ -22,6 +23,7 @@ import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback |
|
|
|
|
import net.pokeranalytics.android.ui.view.SessionRow |
|
|
|
|
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager |
|
|
|
|
import net.pokeranalytics.android.util.px |
|
|
|
|
@ -147,7 +149,6 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
floatingActionButton.setOnClickListener { |
|
|
|
|
manageSessionState() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -160,56 +161,89 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
SessionState.PENDING -> { |
|
|
|
|
state.text = "WAITING" |
|
|
|
|
state.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)) |
|
|
|
|
sessionData.animate().translationY(-(72f.px)).alpha(0f).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(-(72f.px)).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
sessionMenu?.findItem(R.id.restart)?.isVisible = false |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_play) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = false |
|
|
|
|
|
|
|
|
|
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f) |
|
|
|
|
.setInterpolator(OvershootInterpolator()).start() |
|
|
|
|
sessionData.animate().translationY(-(72f.px)).alpha(1f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(-(72f.px)) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
} |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
state.text = "PLAYING" |
|
|
|
|
state.setTextColor(ContextCompat.getColor(requireContext(), R.color.green)) |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
sessionMenu?.findItem(R.id.restart)?.isVisible = true |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_pause) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = true |
|
|
|
|
|
|
|
|
|
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f) |
|
|
|
|
.setInterpolator(OvershootInterpolator()).start() |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
} |
|
|
|
|
SessionState.PAUSED -> { |
|
|
|
|
state.text = "BREAK" |
|
|
|
|
state.setTextColor(ContextCompat.getColor(requireContext(), R.color.blue)) |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
sessionMenu?.findItem(R.id.restart)?.isVisible = true |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_play) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = true |
|
|
|
|
|
|
|
|
|
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f) |
|
|
|
|
.setInterpolator(OvershootInterpolator()).start() |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
} |
|
|
|
|
SessionState.FINISHED -> { |
|
|
|
|
state.text = "FINISHED" |
|
|
|
|
state.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)) |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px).setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
sessionMenu?.findItem(R.id.restart)?.isVisible = true |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = false |
|
|
|
|
|
|
|
|
|
floatingActionButton.animate().scaleX(0f).scaleY(0f).alpha(0f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).start() |
|
|
|
|
sessionData.animate().translationY(0f).alpha(1f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
recyclerView.animate().translationY(0f.px) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()).setDuration(500).start() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sessionAdapter.updateRows(currentSession.adapterRows()) |
|
|
|
|
recyclerView.smoothScrollToPosition(0) |
|
|
|
|
updateAdapterUI(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update adapter UI |
|
|
|
|
*/ |
|
|
|
|
private fun updateAdapterUI(scrollToTop: Boolean) { |
|
|
|
|
|
|
|
|
|
val diffResult = DiffUtil.calculateDiff(RowRepresentableDiffCallback(currentSession.adapterRows(), oldRows)) |
|
|
|
|
sessionAdapter.updateRows(diffResult) |
|
|
|
|
|
|
|
|
|
oldRows.clear() |
|
|
|
|
oldRows.addAll(currentSession.adapterRows()) |
|
|
|
|
|
|
|
|
|
if (scrollToTop) { |
|
|
|
|
recyclerView.smoothScrollToPosition(0) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val oldRows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update the state of the session (start / pause) |
|
|
|
|
*/ |
|
|
|
|
private fun manageSessionState() { |
|
|
|
|
|
|
|
|
|
Timber.d("oldRows: $oldRows") |
|
|
|
|
|
|
|
|
|
when (currentSession.getState()) { |
|
|
|
|
SessionState.PENDING -> { |
|
|
|
|
currentSession.startSession() |
|
|
|
|
|