Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Laurent 7 years ago
commit 096c39a59f
  1. 59
      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. 37
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  4. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  5. 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,12 +158,25 @@ 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())
} }
} }
} }
} }
/**
* 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 * Return the duration of the current session
*/ */
@ -339,16 +351,16 @@ 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, SessionRow.PRIZE -> result?.cashout?.toCurrency() ?: "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--" SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--" SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--"
SessionRow.GAME -> getGameTitle() SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: "--" SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: "--"
SessionRow.LOCATION -> location?.name ?: "--" SessionRow.LOCATION -> location?.name ?: "--"
SessionRow.PLAYERS -> "TODO" SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: "--"
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: "--" SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: "--"
SessionRow.PRIZE -> "TODO"
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--" SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--"
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--" SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--"
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--" SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
@ -387,6 +399,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) {
@ -395,6 +413,9 @@ open class Session : RealmObject(), SessionInterface, Savable,
} else if (tournamentEntryFee != null) { } else if (tournamentEntryFee != null) {
data.add(RowRepresentableEditDescriptor((tournamentEntryFee ?: 0.0) * 1.0)) data.add(RowRepresentableEditDescriptor((tournamentEntryFee ?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((tournamentEntryFee ?: 0.0) * 2.0)) data.add(RowRepresentableEditDescriptor((tournamentEntryFee ?: 0.0) * 2.0))
} else {
data.add(RowRepresentableEditDescriptor(0))
data.add(RowRepresentableEditDescriptor(0))
} }
data.add(RowRepresentableEditDescriptor(buyin)) data.add(RowRepresentableEditDescriptor(buyin))
@ -411,7 +432,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
) )
) )
} }
SessionRow.CASHED_OUT -> { SessionRow.CASHED_OUT, SessionRow.PRIZE -> {
data.add( data.add(
RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
) )
@ -433,10 +454,9 @@ open class Session : RealmObject(), SessionInterface, Savable,
// Add current location and locations list // Add current location and locations list
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm))) data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm)))
} }
//TODO
SessionRow.PLAYERS -> { SessionRow.PLAYERS -> {
data.add( data.add(
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(tournamentNumberOfPlayers?.toString(), inputType = InputType.TYPE_CLASS_NUMBER)
) )
} }
SessionRow.POSITION -> { SessionRow.POSITION -> {
@ -447,12 +467,6 @@ open class Session : RealmObject(), SessionInterface, Savable,
) )
) )
} }
//TODO
SessionRow.PRIZE -> {
data.add(
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.TABLE_SIZE -> { SessionRow.TABLE_SIZE -> {
data.add(RowRepresentableEditDescriptor(tableSize)) data.add(RowRepresentableEditDescriptor(tableSize))
} }
@ -499,12 +513,18 @@ 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?
result = localResult result = localResult
} }
SessionRow.CASHED_OUT -> { SessionRow.CASHED_OUT, SessionRow.PRIZE -> {
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.cashout = if (value == null) null else (value as String).toDouble() localResult.cashout = if (value == null) null else (value as String).toDouble()
result = localResult result = localResult
@ -533,15 +553,12 @@ open class Session : RealmObject(), SessionInterface, Savable,
} }
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble() SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble()
SessionRow.LOCATION -> location = value as Location? SessionRow.LOCATION -> location = value as Location?
SessionRow.PLAYERS -> { SessionRow.PLAYERS -> tournamentNumberOfPlayers = if (value != null) (value as String).toInt() else null
}//TODO
SessionRow.POSITION -> { SessionRow.POSITION -> {
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.tournamentFinalPosition = if (value == null) null else (value as String).toInt() localResult.tournamentFinalPosition = if (value == null) null else (value as String).toInt()
result = localResult result = localResult
} }
SessionRow.PRIZE -> {
}//TODO
SessionRow.START_DATE -> if (value is Date?) { SessionRow.START_DATE -> if (value is Date?) {
if (value == null) { if (value == null) {
timeFrame = null timeFrame = null

@ -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) {

@ -27,7 +27,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SessionRow import net.pokeranalytics.android.ui.view.SessionRow
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.util.toast
import java.util.* import java.util.*
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate { class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate {
@ -67,15 +66,9 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) { when (item!!.itemId) {
R.id.stop -> { R.id.stop -> stopSession()
currentSession.stopSession() R.id.restart -> restartTimer()
updateSessionUI() R.id.delete -> deleteSession()
}
R.id.restart -> toast("Restart is clicked!")
R.id.delete -> {
currentSession.delete()
activity?.finish()
}
} }
return true return true
} }
@ -231,6 +224,30 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
updateSessionUI() 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 * Set fragment data
*/ */

@ -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