|
|
|
|
@ -2,7 +2,6 @@ package net.pokeranalytics.android.model.realm |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import android.text.InputType |
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.annotations.Ignore |
|
|
|
|
@ -16,6 +15,7 @@ import net.pokeranalytics.android.model.extensions.SessionState |
|
|
|
|
import net.pokeranalytics.android.model.extensions.getState |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Savable |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.view.HeaderRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
|
|
|
|
import net.pokeranalytics.android.ui.view.SessionRow |
|
|
|
|
@ -23,7 +23,6 @@ import net.pokeranalytics.android.util.getDuration |
|
|
|
|
import net.pokeranalytics.android.util.round |
|
|
|
|
import net.pokeranalytics.android.util.shortDateTime |
|
|
|
|
import net.pokeranalytics.android.util.toCurrency |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
@ -153,17 +152,17 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
/** |
|
|
|
|
* Return the duration of the current session |
|
|
|
|
*/ |
|
|
|
|
fun getDuration(context: Context): String { |
|
|
|
|
fun getDuration(): String { |
|
|
|
|
val startDate = timeFrame?.startDate ?: Date() |
|
|
|
|
val enDate = timeFrame?.endDate ?: Date() |
|
|
|
|
return startDate.getDuration(context, enDate) |
|
|
|
|
return startDate.getDuration(enDate) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the formatted blinds |
|
|
|
|
*/ |
|
|
|
|
fun getBlinds(): String { |
|
|
|
|
return if (cgSmallBlind == null) "--" else "$${cgSmallBlind?.round()}/${cgBigBlind?.round()}" |
|
|
|
|
return if (cgSmallBlind == null) "--" else "${cgSmallBlind?.toCurrency()}/${cgBigBlind?.round()}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -275,6 +274,22 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): ArrayList<RowRepresentable> { |
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
|
|
|
|
|
// Headers |
|
|
|
|
when (getState()) { |
|
|
|
|
SessionState.STARTED, SessionState.PAUSED -> { |
|
|
|
|
rows.add(HeaderRowRepresentable.HEADER_SESSION_DURATION) |
|
|
|
|
} |
|
|
|
|
SessionState.FINISHED -> { |
|
|
|
|
rows.add(HeaderRowRepresentable.HEADER_SESSION_DURATION) |
|
|
|
|
rows.add(HeaderRowRepresentable.HEADER_SESSION_NET_HOURLY_RATE) |
|
|
|
|
rows.add(HeaderRowRepresentable.HEADER_SESSION_BANKROLL_VARIATION) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Rows |
|
|
|
|
rows.addAll(SessionRow.getRowsForState(getState())) |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
@ -285,7 +300,9 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: RowRepresentable, context: Context): String { |
|
|
|
|
return when (row) { |
|
|
|
|
SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--" |
|
|
|
|
SessionRow.BUY_IN -> buyin.toCurrency() |
|
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--" |
|
|
|
|
SessionRow.BLINDS -> getBlinds() |
|
|
|
|
SessionRow.GAME -> getGameTitle() |
|
|
|
|
SessionRow.LOCATION -> location?.name ?: "--" |
|
|
|
|
@ -312,7 +329,11 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
val data = ArrayList<RowRepresentableEditDescriptor>() |
|
|
|
|
|
|
|
|
|
when (row) { |
|
|
|
|
|
|
|
|
|
SessionRow.CASHED_OUT -> { |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
SessionRow.BUY_IN -> { |
|
|
|
|
// Add first & second buttons values, current value & set the 2 edit texts |
|
|
|
|
data.add(RowRepresentableEditDescriptor(100.0 * (cgBigBlind ?: 0.0))) |
|
|
|
|
@ -331,32 +352,13 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
SessionRow.CASHED_OUT -> { |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
result?.cashout, |
|
|
|
|
inputType = InputType.TYPE_CLASS_NUMBER |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
SessionRow.TIPS -> { |
|
|
|
|
// Disable the buttons with value = 0, add current value & set the 2 edit texts |
|
|
|
|
// TODO: manage tips |
|
|
|
|
data.add(RowRepresentableEditDescriptor(cgSmallBlind ?: 0.0)) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(cgBigBlind ?: 0.0)) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(0)) |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
"", |
|
|
|
|
inputType = InputType.TYPE_CLASS_NUMBER |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
"", |
|
|
|
|
inputType = InputType.TYPE_CLASS_NUMBER |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(result?.tips ?: 0.0)) |
|
|
|
|
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
} |
|
|
|
|
SessionRow.TABLE_SIZE -> { |
|
|
|
|
data.add(RowRepresentableEditDescriptor(tableSize)) |
|
|
|
|
@ -368,46 +370,18 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
} |
|
|
|
|
SessionRow.LOCATION -> { |
|
|
|
|
// Add current location and locations list |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
location, |
|
|
|
|
data = LiveData.LOCATION.items(realm) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm))) |
|
|
|
|
} |
|
|
|
|
SessionRow.BANKROLL -> { |
|
|
|
|
// Add current bankroll and bankrolls list |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
bankroll, |
|
|
|
|
data = LiveData.BANKROLL.items(realm) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm))) |
|
|
|
|
} |
|
|
|
|
SessionRow.BLINDS -> { |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
cgSmallBlind, |
|
|
|
|
R.string.smallblind, |
|
|
|
|
InputType.TYPE_CLASS_NUMBER |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
cgBigBlind, |
|
|
|
|
R.string.bigblind, |
|
|
|
|
InputType.TYPE_CLASS_NUMBER |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(cgSmallBlind, R.string.smallblind, InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(cgBigBlind, R.string.bigblind, InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
} |
|
|
|
|
SessionRow.COMMENT -> { |
|
|
|
|
data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
comment, |
|
|
|
|
R.string.comment, |
|
|
|
|
InputType.TYPE_CLASS_TEXT |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
data.add(RowRepresentableEditDescriptor(comment, R.string.comment, InputType.TYPE_CLASS_TEXT)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -427,11 +401,14 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
localResult.cashout = if (value == null) null else (value as String).toDouble() |
|
|
|
|
result = localResult |
|
|
|
|
} |
|
|
|
|
SessionRow.TIPS -> { |
|
|
|
|
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) |
|
|
|
|
localResult.tips = value as Double? |
|
|
|
|
result = localResult |
|
|
|
|
} |
|
|
|
|
SessionRow.TABLE_SIZE -> tableSize = value as Int? |
|
|
|
|
SessionRow.GAME -> { |
|
|
|
|
if (value is ArrayList<*>) { |
|
|
|
|
Timber.d("${value[0]}") |
|
|
|
|
Timber.d("${value[1]}") |
|
|
|
|
limit = try { |
|
|
|
|
(value[0] as Int?) |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
@ -465,7 +442,6 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//TODO: Update |
|
|
|
|
SessionRow.START_DATE -> if (value is Date?) { |
|
|
|
|
if (value == null) { |
|
|
|
|
timeFrame = null |
|
|
|
|
@ -476,7 +452,6 @@ open class Session : RealmObject(), SessionInterface, Savable, |
|
|
|
|
timeFrame = timeFrameToUpdate |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//TODO: Update |
|
|
|
|
SessionRow.END_DATE -> if (value is Date?) { |
|
|
|
|
val timeFrameToUpdate = |
|
|
|
|
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java) |
|
|
|
|
|