Harmonizing number capture and management + fixing crashes

feature/top10
Laurent 7 years ago
parent 50feb6dc80
commit 0eba63f112
  1. 17
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt
  2. 42
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 80
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetNumericTextFragment.kt
  4. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetType.kt
  5. 130
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt

@ -80,13 +80,16 @@ open class Result : RealmObject() {
private fun computeNet() {
val transactionsSum = transactions.sumByDouble { it.amount }
this.netResult?.let {
this.net = it + transactionsSum
} ?: run {
val buyin = this.buyin ?: 0.0
val cashOut = this.cashout ?: 0.0
this.net = cashOut - buyin + transactionsSum
}
val isLive = this.session?.bankroll?.live ?: true
if (isLive) {
val buyin = this.buyin ?: 0.0
val cashOut = this.cashout ?: 0.0
this.net = cashOut - buyin + transactionsSum
} else {
val netResult = this.netResult ?: 0.0
this.net = netResult + transactionsSum
}
// Precompute results
this.session?.computeStats()

@ -627,7 +627,8 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
SessionRow.BLINDS -> getBlinds()
SessionRow.BREAK_TIME -> if (this.breakDuration > 0.0) this.breakDuration.toMinutes() else NULL_TEXT
SessionRow.BUY_IN -> this.result?.buyin?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.CASHED_OUT, SessionRow.PRIZE -> this.result?.cashout?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.NET_RESULT -> this.result?.netResult?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT
SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT
SessionRow.GAME -> getFormattedGame()
@ -664,7 +665,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
override fun actionIconForRow(row: RowRepresentable): Int? {
return when (row) {
SessionRow.START_DATE, SessionRow.END_DATE -> {
net.pokeranalytics.android.R.drawable.ic_close
R.drawable.ic_close
}
else -> null
}
@ -699,14 +700,14 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
SessionRow.BUY_IN -> row.editingDescriptors(mapOf(
"bb" to cgBigBlind,
"fee" to this.tournamentEntryFee,
"ratedBuyin" to ratedBuyin
"ratedBuyin" to result?.buyin
))
SessionRow.BREAK_TIME -> row.editingDescriptors(mapOf())
SessionRow.CASHED_OUT, SessionRow.PRIZE -> row.editingDescriptors(mapOf(
"defaultValue" to result?.cashout?.round()
"defaultValue" to result?.cashout
))
SessionRow.NET_RESULT -> row.editingDescriptors(mapOf(
"defaultValue" to result?.netResult?.round()
"defaultValue" to result?.netResult
))
SessionRow.COMMENT -> row.editingDescriptors(mapOf(
"defaultValue" to this.comment))
@ -759,43 +760,26 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
SessionRow.BUY_IN -> {
val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java)
if (value == null) {
localResult.buyin = null
} else {
localResult.buyin = (value as String).toDouble()
}
localResult.buyin = value as Double?
this.result = localResult
this.updateRowRepresentation()
}
SessionRow.CASHED_OUT, SessionRow.PRIZE -> {
val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java)
if (value == null) {
localResult.cashout = null
} else {
localResult.cashout = (value as String).toDouble()
}
localResult.cashout = value as Double?
this.result = localResult
}
SessionRow.NET_RESULT -> {
this.result?.let { result ->
if (value == null) {
result.netResult = null
} else {
result.netResult = (value as String).toDouble()
}
result.netResult = value as Double?
}
}
SessionRow.COMMENT -> comment = value as String? ?: ""
SessionRow.END_DATE -> if (value is Date?) {
this.endDate = value
}
SessionRow.GAME -> {
if (value is ArrayList<*>) {
@ -814,7 +798,6 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
} else if (value == null) {
limit = null
game = null
}
}
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble()
@ -831,12 +814,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
SessionRow.TABLE_SIZE -> tableSize = value as Int?
SessionRow.TIPS -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
if (value == null) {
localResult.tips = null
} else {
localResult.tips = (value as String).toDouble()
}
localResult.tips = value as Double?
result = localResult
}
SessionRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName?

@ -0,0 +1,80 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import kotlinx.android.synthetic.main.bottom_sheet_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException
import java.text.NumberFormat
class BottomSheetNumericTextFragment : BottomSheetFragment() {
private var value: Double? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
}
override fun onStart() {
super.onStart()
editText1.requestFocus()
}
override fun getValue(): Any? {
return this.value
}
/**
* Init data
*/
private fun initData() {
}
/**
* Init UI
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
if (data.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)
data[0].hint?.let { editText1.hint = getString(it) }
editText1.inputType = data[0].inputType ?: InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
editText1.addTextChangedListener {
this.value = try {
editText1.text.toString().toDouble()
} catch (e: Exception) {
null
}
}
data[0].defaultValue?.let {
val formatter = NumberFormat.getNumberInstance()
formatter.isGroupingUsed = false
editText1.setText(formatter.format(it))
}
editText1.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
delegate.onRowValueChanged(getValue(), row)
dismiss()
true
} else {
false
}
}
}
}

@ -11,6 +11,7 @@ enum class BottomSheetType {
EDIT_TEXT { override fun newInstance() = BottomSheetEditTextFragment()},
EDIT_TEXT_MULTI_LINES { override fun newInstance() = BottomSheetEditTextMultiLinesFragment()},
DOUBLE_EDIT_TEXT { override fun newInstance() = BottomSheetDoubleEditTextFragment()},
NUMERIC_TEXT { override fun newInstance() = BottomSheetNumericTextFragment()},
SUM { override fun newInstance() = BottomSheetSumFragment()};
abstract fun newInstance(): BottomSheetFragment
@ -26,7 +27,7 @@ enum class BottomSheetType {
val addRequired : Boolean
get() = when (this) {
EDIT_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false
EDIT_TEXT, NUMERIC_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false
else -> true
}
}

@ -49,17 +49,39 @@ enum class SessionRow : RowRepresentable {
return when (session.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
arrayListOf(
GAME, INITIAL_BUY_IN, LOCATION, BANKROLL, TABLE_SIZE, TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE,
START_DATE, END_DATE
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
START_DATE,
END_DATE
)
}
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
arrayListOf(
PRIZE, BUY_IN, POSITION, PLAYERS, TIPS,
PRIZE,
BUY_IN,
POSITION,
PLAYERS,
TIPS,
SeparatorRowRepresentable(),
GAME, INITIAL_BUY_IN, LOCATION, BANKROLL, TABLE_SIZE, TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE,
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
SeparatorRowRepresentable(),
START_DATE, END_DATE, BREAK_TIME, COMMENT
START_DATE,
END_DATE,
BREAK_TIME,
COMMENT
)
}
}
@ -73,15 +95,33 @@ enum class SessionRow : RowRepresentable {
val liveBankroll = session.bankroll?.live ?: false
return if (liveBankroll) {
arrayListOf(
CASHED_OUT, BUY_IN, TIPS,
CASHED_OUT,
BUY_IN,
TIPS,
SeparatorRowRepresentable(),
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE, BREAK_TIME, COMMENT
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
START_DATE,
END_DATE,
BREAK_TIME,
COMMENT
)
} else {
arrayListOf(
NET_RESULT,
SeparatorRowRepresentable(),
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE, BREAK_TIME, COMMENT
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
START_DATE,
END_DATE,
BREAK_TIME,
COMMENT
)
}
}
@ -131,7 +171,7 @@ enum class SessionRow : RowRepresentable {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.EDIT_TEXT
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.NUMERIC_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME
@ -151,10 +191,15 @@ enum class SessionRow : RowRepresentable {
val sb: String? by map
val bb: String? by map
arrayListOf(
RowRepresentableEditDescriptor(sb, R.string.smallblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL),
RowRepresentableEditDescriptor(bb, R.string.bigblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL))
RowRepresentableEditDescriptor(
sb, R.string.smallblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
),
RowRepresentableEditDescriptor(
bb, R.string.bigblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
}
BUY_IN -> {
val bb: Double? by map
@ -162,11 +207,11 @@ enum class SessionRow : RowRepresentable {
val ratedBuyin: Double? by map
val data = arrayListOf<RowRepresentableEditDescriptor>()
if (bb != null) {
data.add(RowRepresentableEditDescriptor(100.0 * (bb?: 0.0)))
data.add(RowRepresentableEditDescriptor(200.0 * (bb?: 0.0)))
data.add(RowRepresentableEditDescriptor(100.0 * (bb ?: 0.0)))
data.add(RowRepresentableEditDescriptor(200.0 * (bb ?: 0.0)))
} else if (fee != null) {
data.add(RowRepresentableEditDescriptor((fee?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((fee?: 0.0) * 2.0))
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 2.0))
} else {
data.add(RowRepresentableEditDescriptor(0))
data.add(RowRepresentableEditDescriptor(0))
@ -186,17 +231,18 @@ enum class SessionRow : RowRepresentable {
data
}
CASHED_OUT, PRIZE, NET_RESULT -> {
val defaultValue: String? by map
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
))
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
COMMENT -> {
val defaultValue : String? by map
val defaultValue: String? by map
arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment))
}
BREAK_TIME -> {
@ -207,22 +253,23 @@ enum class SessionRow : RowRepresentable {
)
}
GAME -> {
val limit : Int? by map
val defaultValue : Any? by map
val data : RealmResults<*>? by map
val limit: Int? by map
val defaultValue: Any? by map
val data: RealmResults<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(limit),
RowRepresentableEditDescriptor(defaultValue, data = data))
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
INITIAL_BUY_IN -> {
val defaultValue : Double? by map
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
BANKROLL, LOCATION, TOURNAMENT_FEATURE, TOURNAMENT_NAME -> {
val defaultValue : Any? by map
val data : RealmResults<*>? by map
val defaultValue: Any? by map
val data: RealmResults<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
@ -237,7 +284,7 @@ enum class SessionRow : RowRepresentable {
)
}
POSITION -> {
val defaultValue : Int? by map
val defaultValue: Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue,
@ -246,7 +293,7 @@ enum class SessionRow : RowRepresentable {
)
}
TABLE_SIZE -> {
val defaultValue : Int? by map
val defaultValue: Int? by map
arrayListOf(RowRepresentableEditDescriptor(defaultValue))
}
TIPS -> {
@ -256,19 +303,20 @@ enum class SessionRow : RowRepresentable {
// Disable the buttons with value = 0, add current value & set the 2 edit texts
arrayListOf(
RowRepresentableEditDescriptor(sb?: 0.0),
RowRepresentableEditDescriptor(bb?: 0.0),
RowRepresentableEditDescriptor(tips?: 0.0),
RowRepresentableEditDescriptor(sb ?: 0.0),
RowRepresentableEditDescriptor(bb ?: 0.0),
RowRepresentableEditDescriptor(tips ?: 0.0),
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER),
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
TOURNAMENT_TYPE -> {
val defaultValue : Any? by map
val defaultValue: Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map {
it
}))
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map {
it
})
)
}
else -> null
}

Loading…
Cancel
Save