Refactoring + crash fix

kmm_hh
Laurent 5 years ago
parent 4cc9a73120
commit cd22a60dcc
  1. 5
      app/src/main/java/net/pokeranalytics/android/model/extensions/SessionExtensions.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt

@ -10,6 +10,7 @@ import net.pokeranalytics.android.model.TournamentType
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.NotificationSchedule
import net.pokeranalytics.android.util.extensions.toCurrency
import timber.log.Timber
import java.util.*
import java.util.concurrent.TimeUnit
@ -103,7 +104,9 @@ fun Session.cancelStopNotification(context: Context) {
fun Session.scheduleStopNotification(context: Context, optimalDuration: Long) {
val timeDelay = optimalDuration - this.currentDuration()
if (timeDelay <= 0) throw PAIllegalStateException("A stop notif has been setup for the past: start=${this.startDate}, end=${this.endDate}, optimalDuration=$optimalDuration")
if (timeDelay <= 0) {
return
}
val title = context.getString(R.string.stop_notification_title)
val body = context.getString(R.string.stop_notification_body)

@ -137,7 +137,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRepr
binding.floatingActionButton.setOnClickListener {
if (this.currentSession.isValidForSave()) {
sessionHasBeenUserCustomized = true
manageSessionState()
startPauseResumeSession()
} else {
val builder = AlertDialog.Builder(requireContext())
.setMessage(this.currentSession.getFailedSaveMessage(SaveValidityStatus.DATA_INVALID))
@ -370,9 +370,9 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRepr
}
/**
* Update the state of the session (start / pause)
* Update the state of the session (start / pause / resume)
*/
private fun manageSessionState() {
private fun startPauseResumeSession() {
when (val state = currentSession.getState()) {
SessionState.PENDING, SessionState.PLANNED, SessionState.PAUSED -> {

Loading…
Cancel
Save