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>? { override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
val data = ArrayList<RowRepresentableEditDescriptor>() SessionRow.BANKROLL -> row.editingDescriptors(mapOf(
"defaultValue" to this.bankroll,
when (row) { "data" to LiveData.BANKROLL.items(realm)))
SessionRow.BANKROLL -> { SessionRow.GAME -> row.editingDescriptors(mapOf(
// Add current bankroll and bankrolls list "limit" to this.limit,
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm))) "defaultValue" to this.game,
} "data" to LiveData.GAME.items(realm)))
SessionRow.BLINDS -> { SessionRow.LOCATION -> row.editingDescriptors(mapOf(
data.add( "defaultValue" to this.location,
RowRepresentableEditDescriptor( "data" to LiveData.LOCATION.items(realm)))
cgSmallBlind?.round(), SessionRow.TOURNAMENT_FEATURE -> row.editingDescriptors(mapOf(
R.string.smallblind, "defaultValue" to this.tournamentFeatures,
InputType.TYPE_CLASS_NUMBER "data" to LiveData.TOURNAMENT_FEATURE.items(realm)))
or InputType.TYPE_NUMBER_FLAG_DECIMAL SessionRow.TOURNAMENT_NAME -> row.editingDescriptors(mapOf(
) "defaultValue" to this.tournamentName,
) "data" to LiveData.TOURNAMENT_NAME.items(realm)))
data.add( SessionRow.TOURNAMENT_TYPE -> row.editingDescriptors(mapOf(
RowRepresentableEditDescriptor( "defaultValue" to this.tournamentType))
cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER SessionRow.TABLE_SIZE -> row.editingDescriptors(mapOf(
or InputType.TYPE_NUMBER_FLAG_DECIMAL "defaultValue" to this.tableSize))
) SessionRow.BLINDS -> row.editingDescriptors(mapOf(
) "SB" to cgSmallBlind?.round(),
} "BB" to cgBigBlind?.round()
SessionRow.BREAK_TIME -> { ))
data.add( SessionRow.BUY_IN -> row.editingDescriptors(mapOf(
RowRepresentableEditDescriptor( "BB" to cgBigBlind,
"", "fee" to this.tournamentEntryFee,
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER "buying" to buyin
) ))
) SessionRow.BREAK_TIME -> row.editingDescriptors(mapOf())
} SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> row.editingDescriptors(mapOf(
SessionRow.BUY_IN -> { "result" to result?.cashout?.round()
// Add first & second buttons values, current value & set the 2 edit texts ))
if (this.cgBigBlind != null) { SessionRow.COMMENT -> row.editingDescriptors(mapOf(
data.add(RowRepresentableEditDescriptor(100.0 * (this.cgBigBlind ?: 0.0))) "defaultValue" to this.comment))
data.add(RowRepresentableEditDescriptor(200.0 * (this.cgBigBlind ?: 0.0))) SessionRow.INITIAL_BUY_IN -> row.editingDescriptors(mapOf(
} else if (this.tournamentEntryFee != null) { "fee" to this.tournamentEntryFee
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 1.0)) ))
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 2.0)) SessionRow.PLAYERS -> row.editingDescriptors(mapOf(
} else { "defaultValue" to this.tournamentNumberOfPlayers))
data.add(RowRepresentableEditDescriptor(0)) SessionRow.POSITION -> row.editingDescriptors(mapOf(
data.add(RowRepresentableEditDescriptor(0)) "defaultValue" to this.result?.tournamentFinalPosition))
} SessionRow.TIPS -> row.editingDescriptors(mapOf(
"SB" to cgSmallBlind?.round(),
data.add(RowRepresentableEditDescriptor(buyin)) "BB" to cgBigBlind?.round(),
data.add( "tips" to result?.tips
RowRepresentableEditDescriptor( ))
"", else -> null
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 data
} }
override fun updateValue(value: Any?, row: RowRepresentable) { override fun updateValue(value: Any?, row: RowRepresentable) {

@ -1,12 +1,18 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import io.realm.RealmResults
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.TournamentType
import net.pokeranalytics.android.model.extensions.SessionState import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState 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.model.realm.Session
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable 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.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.round
enum class SessionRow : RowRepresentable { 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