Manage Restart Timer

feature/top10
Aurelien Hubert 7 years ago
parent c25086757f
commit 3d56a6bbbe
  1. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 37
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt

@ -165,6 +165,18 @@ open class Session : RealmObject(), SessionInterface, Savable,
}
}
/**
* Restart a session
*/
fun restartSession() {
realm.executeTransaction {
this.timeFrame?.paused = false
this.timeFrame?.pauseDate = null
this.timeFrame?.setDate(Date(), null)
this.timeFrame?.breakDuration = 0L
}
}
/**
* Return the duration of the current session
*/

@ -27,7 +27,6 @@ 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.toast
import java.util.*
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate {
@ -67,15 +66,9 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) {
R.id.stop -> {
currentSession.stopSession()
updateSessionUI()
}
R.id.restart -> toast("Restart is clicked!")
R.id.delete -> {
currentSession.delete()
activity?.finish()
}
R.id.stop -> stopSession()
R.id.restart -> restartTimer()
R.id.delete -> deleteSession()
}
return true
}
@ -231,6 +224,30 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
updateSessionUI()
}
/**
* Stop the current session
*/
private fun stopSession() {
currentSession.stopSession()
updateSessionUI()
}
/**
* Restart timer
*/
private fun restartTimer() {
currentSession.restartSession()
updateSessionUI()
}
/**
* Delete a session
*/
private fun deleteSession() {
currentSession.delete()
activity?.finish()
}
/**
* Set fragment data
*/

Loading…
Cancel
Save