finishing the editDescriptors refactoring

feature/top10
Razmig Sarkissian 7 years ago
parent 4ef9dc4d77
commit 81a2f89bc4
  1. 178
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 141
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt

@ -588,136 +588,56 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SessionRow.BANKROLL -> {
// Add current bankroll and bankrolls list
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm)))
}
SessionRow.BLINDS -> {
data.add(
RowRepresentableEditDescriptor(
cgSmallBlind?.round(),
R.string.smallblind,
InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data.add(
RowRepresentableEditDescriptor(
cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
}
SessionRow.BREAK_TIME -> {
data.add(
RowRepresentableEditDescriptor(
"",
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.BUY_IN -> {
// Add first & second buttons values, current value & set the 2 edit texts
if (this.cgBigBlind != null) {
data.add(RowRepresentableEditDescriptor(100.0 * (this.cgBigBlind ?: 0.0)))
data.add(RowRepresentableEditDescriptor(200.0 * (this.cgBigBlind ?: 0.0)))
} else if (this.tournamentEntryFee != null) {
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 2.0))
} else {
data.add(RowRepresentableEditDescriptor(0))
data.add(RowRepresentableEditDescriptor(0))
}
data.add(RowRepresentableEditDescriptor(buyin))
data.add(
RowRepresentableEditDescriptor(
"",
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data.add(
RowRepresentableEditDescriptor(
"",
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
}
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> {
data.add(
RowRepresentableEditDescriptor(
result?.cashout?.round(),
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
SessionRow.COMMENT -> {
data.add(RowRepresentableEditDescriptor(comment, R.string.comment))
}
SessionRow.GAME -> {
// Add current game & games list
data.add(RowRepresentableEditDescriptor(limit))
data.add(RowRepresentableEditDescriptor(game, data = LiveData.GAME.items(realm)))
}
SessionRow.INITIAL_BUY_IN -> {
data.add(
RowRepresentableEditDescriptor(tournamentEntryFee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.LOCATION -> {
// Add current location and locations list
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm)))
}
SessionRow.PLAYERS -> {
data.add(
RowRepresentableEditDescriptor(
tournamentNumberOfPlayers?.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.POSITION -> {
data.add(
RowRepresentableEditDescriptor(
result?.tournamentFinalPosition,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.TABLE_SIZE -> {
data.add(RowRepresentableEditDescriptor(tableSize))
}
SessionRow.TIPS -> {
// Disable the buttons with value = 0, add current value & set the 2 edit texts
data.add(RowRepresentableEditDescriptor(cgSmallBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(cgBigBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(result?.tips ?: 0.0))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
}
SessionRow.TOURNAMENT_NAME -> {
// Add current tournament name and tournament names list
data.add(RowRepresentableEditDescriptor(tournamentName, data = LiveData.TOURNAMENT_NAME.items(realm)))
}
SessionRow.TOURNAMENT_TYPE -> {
// Add current tournament kind and tournament kind list
data.add(RowRepresentableEditDescriptor(tournamentType, staticData = TournamentType.values().map {
it
}))
}
SessionRow.TOURNAMENT_FEATURE -> {
// Add current tournament feature and tournament features list
data.add(RowRepresentableEditDescriptor(tournamentFeatures, data = LiveData.TOURNAMENT_FEATURE.items(realm)))
}
return when (row) {
SessionRow.BANKROLL -> row.editingDescriptors(mapOf(
"defaultValue" to this.bankroll,
"data" to LiveData.BANKROLL.items(realm)))
SessionRow.GAME -> row.editingDescriptors(mapOf(
"limit" to this.limit,
"defaultValue" to this.game,
"data" to LiveData.GAME.items(realm)))
SessionRow.LOCATION -> row.editingDescriptors(mapOf(
"defaultValue" to this.location,
"data" to LiveData.LOCATION.items(realm)))
SessionRow.TOURNAMENT_FEATURE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentFeatures,
"data" to LiveData.TOURNAMENT_FEATURE.items(realm)))
SessionRow.TOURNAMENT_NAME -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentName,
"data" to LiveData.TOURNAMENT_NAME.items(realm)))
SessionRow.TOURNAMENT_TYPE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentType))
SessionRow.TABLE_SIZE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tableSize))
SessionRow.BLINDS -> row.editingDescriptors(mapOf(
"SB" to cgSmallBlind?.round(),
"BB" to cgBigBlind?.round()
))
SessionRow.BUY_IN -> row.editingDescriptors(mapOf(
"BB" to cgBigBlind,
"fee" to this.tournamentEntryFee,
"buying" to buyin
))
SessionRow.BREAK_TIME -> row.editingDescriptors(mapOf())
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> row.editingDescriptors(mapOf(
"result" to result?.cashout?.round()
))
SessionRow.COMMENT -> row.editingDescriptors(mapOf(
"defaultValue" to this.comment))
SessionRow.INITIAL_BUY_IN -> row.editingDescriptors(mapOf(
"fee" to this.tournamentEntryFee
))
SessionRow.PLAYERS -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentNumberOfPlayers))
SessionRow.POSITION -> row.editingDescriptors(mapOf(
"defaultValue" to this.result?.tournamentFinalPosition))
SessionRow.TIPS -> row.editingDescriptors(mapOf(
"SB" to cgSmallBlind?.round(),
"BB" to cgBigBlind?.round(),
"tips" to result?.tips
))
else -> null
}
return data
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -1,12 +1,18 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import io.realm.RealmResults
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.TournamentType
import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.round
enum class SessionRow : RowRepresentable {
@ -140,4 +146,139 @@ enum class SessionRow : RowRepresentable {
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
BLINDS -> {
val sb: Double? by map
val bb: Double? 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))
}
BUY_IN -> {
val bb: Double? by map
val fee: Double? by map
val buyin: 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)))
} else if (fee != null) {
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))
}
data.add(RowRepresentableEditDescriptor(buyin))
data.add(
RowRepresentableEditDescriptor(
"",
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data.add(
RowRepresentableEditDescriptor(
"",
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data
}
CASHED_OUT, PRIZE, NET_RESULT -> {
val cashout: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
cashout?.round(),
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
))
}
COMMENT -> {
val comment : String? by map
arrayListOf(RowRepresentableEditDescriptor(comment, R.string.comment))
}
BREAK_TIME -> {
arrayListOf(
RowRepresentableEditDescriptor(
"",
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
GAME -> {
val limit : Int? by map
val defaultValue : Any? by map
val data : RealmResults<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(limit),
RowRepresentableEditDescriptor(defaultValue, data = data))
}
INITIAL_BUY_IN -> {
val fee : Double? by map
arrayListOf(
RowRepresentableEditDescriptor(fee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
BANKROLL, LOCATION, TOURNAMENT_FEATURE, TOURNAMENT_NAME -> {
val defaultValue : Any? by map
val data : RealmResults<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
PLAYERS -> {
val tournamentNumberOfPlayers: Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
tournamentNumberOfPlayers?.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
POSITION -> {
val tournamentFinalPosition : Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
tournamentFinalPosition,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
TABLE_SIZE -> {
val tableSize : Int? by map
arrayListOf(RowRepresentableEditDescriptor(tableSize))
}
TIPS -> {
val sb: Double? by map
val bb: Double? by map
val tips: Double? by map
// 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("", inputType = InputType.TYPE_CLASS_NUMBER),
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
TOURNAMENT_TYPE -> {
val defaultValue : Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map {
it
}))
}
else -> null
}
}
}
Loading…
Cancel
Save