|
|
|
|
@ -3,11 +3,14 @@ package net.pokeranalytics.android.ui.fragment |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.* |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_session.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.model.extensions.SessionState |
|
|
|
|
import net.pokeranalytics.android.model.extensions.getState |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
@ -20,12 +23,13 @@ import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheet |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.SessionRow |
|
|
|
|
import net.pokeranalytics.android.util.toast |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate { |
|
|
|
|
|
|
|
|
|
private lateinit var currentSession: Session |
|
|
|
|
private lateinit var sessionAdapter : RowRepresentableAdapter |
|
|
|
|
private lateinit var sessionAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_session, container, false) |
|
|
|
|
@ -44,7 +48,10 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
|
|
|
when (item!!.itemId) { |
|
|
|
|
R.id.restart -> toast("Restard is clicked!") |
|
|
|
|
R.id.delete -> toast("Delete is clicked!") |
|
|
|
|
R.id.delete -> { |
|
|
|
|
currentSession.delete() |
|
|
|
|
activity?.finish() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
@ -97,6 +104,10 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
val activity = activity as PokerAnalyticsActivity |
|
|
|
|
|
|
|
|
|
// Avoid a bug during setting the title |
|
|
|
|
toolbar.title = "" |
|
|
|
|
|
|
|
|
|
activity.setSupportActionBar(toolbar) |
|
|
|
|
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
|
|
|
|
setHasOptionsMenu(true) |
|
|
|
|
@ -112,24 +123,79 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = false |
|
|
|
|
|
|
|
|
|
bottomAppBar.setOnMenuItemClickListener { item -> |
|
|
|
|
when(item.itemId) { |
|
|
|
|
R.id.stop -> toast("Stop is clicked!") |
|
|
|
|
when (item.itemId) { |
|
|
|
|
R.id.stop -> { |
|
|
|
|
currentSession.stopSession() |
|
|
|
|
updateSessionUI() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
floatingActionButton.setExpanded(false) |
|
|
|
|
floatingActionButton.setOnClickListener { |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_pause) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = true |
|
|
|
|
manageSessionState() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update the UI with the session data |
|
|
|
|
* Should be called after the initialization of the session |
|
|
|
|
*/ |
|
|
|
|
private fun updateSessionUI() { |
|
|
|
|
|
|
|
|
|
when (currentSession.getState()) { |
|
|
|
|
SessionState.PENDING -> { |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_play) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = false |
|
|
|
|
} |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_pause) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = true |
|
|
|
|
} |
|
|
|
|
SessionState.PAUSED -> { |
|
|
|
|
floatingActionButton.setImageResource(R.drawable.ic_outline_play) |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = true |
|
|
|
|
} |
|
|
|
|
SessionState.FINISHED -> { |
|
|
|
|
bottomAppBar.menu.findItem(R.id.stop).isVisible = false |
|
|
|
|
floatingActionButton.animate() |
|
|
|
|
.scaleX(0f) |
|
|
|
|
.scaleY(0f) |
|
|
|
|
.alpha(0f) |
|
|
|
|
.setInterpolator(FastOutSlowInInterpolator()) |
|
|
|
|
.start() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sessionAdapter.refreshAllRows() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update the state of the session (start / pause) |
|
|
|
|
*/ |
|
|
|
|
private fun manageSessionState() { |
|
|
|
|
when (currentSession.getState()) { |
|
|
|
|
SessionState.PENDING -> { |
|
|
|
|
currentSession.startSession() |
|
|
|
|
} |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
currentSession.pauseSession() |
|
|
|
|
} |
|
|
|
|
SessionState.PAUSED -> { |
|
|
|
|
currentSession.startSession() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateSessionUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set fragment data |
|
|
|
|
*/ |
|
|
|
|
fun setData(isTournament: Boolean, sessionId: String) { |
|
|
|
|
toolbar.title = if (isTournament) "Tournament" else "Cash game" |
|
|
|
|
toolbar.title = if (isTournament) getString(R.string.tournament) else getString(R.string.cash_game) |
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
|
val sessionRealm = realm.where<Session>().equalTo("id", sessionId).findFirst() |
|
|
|
|
@ -144,6 +210,8 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott |
|
|
|
|
sessionAdapter = RowRepresentableAdapter(currentSession, this) |
|
|
|
|
recyclerView.adapter = sessionAdapter |
|
|
|
|
|
|
|
|
|
updateSessionUI() |
|
|
|
|
Timber.d("Session state: ${currentSession.getState()}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |