Add break time

feature/top10
Aurelien Hubert 7 years ago
parent 7912d1641a
commit 98739449b7
  1. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/TimeFrame.kt
  3. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  4. 13
      app/src/main/java/net/pokeranalytics/android/util/Extensions.kt

@ -16,10 +16,7 @@ import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.interfaces.Savable import net.pokeranalytics.android.model.interfaces.Savable
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.view.* import net.pokeranalytics.android.ui.view.*
import net.pokeranalytics.android.util.getDuration import net.pokeranalytics.android.util.*
import net.pokeranalytics.android.util.round
import net.pokeranalytics.android.util.shortDateTime
import net.pokeranalytics.android.util.toCurrency
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -131,6 +128,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
} }
SessionState.PAUSED -> { SessionState.PAUSED -> {
this.timeFrame?.paused = false this.timeFrame?.paused = false
this.timeFrame?.pauseDate = null
} }
else -> { else -> {
} }
@ -146,6 +144,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
when (getState()) { when (getState()) {
SessionState.STARTED -> { SessionState.STARTED -> {
this.timeFrame?.paused = true this.timeFrame?.paused = true
this.timeFrame?.pauseDate = Date()
} }
} }
} }
@ -159,6 +158,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
when (getState()) { when (getState()) {
SessionState.STARTED, SessionState.PAUSED -> { SessionState.STARTED, SessionState.PAUSED -> {
this.timeFrame?.paused = false this.timeFrame?.paused = false
this.timeFrame?.pauseDate = null
this.timeFrame?.setDate(null, Date()) this.timeFrame?.setDate(null, Date())
} }
} }
@ -339,6 +339,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
return when (row) { return when (row) {
SessionRow.BANKROLL -> bankroll?.name ?: "--" SessionRow.BANKROLL -> bankroll?.name ?: "--"
SessionRow.BLINDS -> getBlinds() SessionRow.BLINDS -> getBlinds()
SessionRow.BREAK_TIME -> timeFrame?.breakDuration?.toMinutes() ?: "--"
SessionRow.BUY_IN -> buyin.toCurrency() SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--" SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--" SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
@ -387,6 +388,12 @@ open class Session : RealmObject(), SessionInterface, Savable,
) )
) )
} }
SessionRow.BREAK_TIME -> {
data.add(
RowRepresentableEditDescriptor("",
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.BUY_IN -> { SessionRow.BUY_IN -> {
// Add first & second buttons values, current value & set the 2 edit texts // Add first & second buttons values, current value & set the 2 edit texts
if (cgBigBlind != null) { if (cgBigBlind != null) {
@ -499,6 +506,12 @@ open class Session : RealmObject(), SessionInterface, Savable,
cgSmallBlind = null cgSmallBlind = null
cgBigBlind = null cgBigBlind = null
} }
SessionRow.BREAK_TIME -> {
val timeFrameToUpdate =
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
timeFrameToUpdate.breakDuration = if (value != null) (value as String).toLong() * 60 * 1000 else 0
timeFrame = timeFrameToUpdate
}
SessionRow.BUY_IN -> { SessionRow.BUY_IN -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.buyin = value as Double? localResult.buyin = value as Double?

@ -26,6 +26,18 @@ open class TimeFrame : RealmObject() {
this.computeDuration() this.computeDuration()
} }
// The latest pause date
var pauseDate: Date? = null
set(value) {
field?.let {
if (value == null && field != null) {
breakDuration += Date().time - it.time
}
}
field = value
this.computeDuration()
}
// The break duration // The break duration
var breakDuration: Long = 0L var breakDuration: Long = 0L
set(value) { set(value) {

@ -5,10 +5,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.fragment_settings.* import kotlinx.android.synthetic.main.fragment_settings.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.DataListActivity import net.pokeranalytics.android.ui.activity.DataListActivity

@ -37,6 +37,19 @@ fun Double.toCurrency(): String {
return format.format(this) return format.format(this)
} }
// Return the time from milliseconds to hours:minutes
fun Long.toMinutes() : String {
val totalMinutes = this / (1000 * 60)
val hours = totalMinutes / 60
val minutesLeft = totalMinutes % 60
var duration = ""
duration += if (hours < 10) "0$hours" else hours.toString()
duration += ":"
duration += if (minutesLeft < 10) "0$minutesLeft" else minutesLeft.toString()
return duration
}
// Calendar // Calendar
// Return if the calendar dates are in the same month // Return if the calendar dates are in the same month

Loading…
Cancel
Save