@ -1,17 +1,22 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import io.realm.RealmResults
import android.widget.Toast
import androidx.fragment.app.Fragment
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.Session
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.round
import net.pokeranalytics.android.util.extensions.sorted
import java.util.*
enum class SessionRow : RowRepresentable {
@ -102,7 +107,8 @@ enum class SessionRow : RowRepresentable {
}
fields . add ( COMMENT )
fields . add ( SeparatorRow ( ) )
fields . addAll ( listOf (
fields . addAll (
listOf (
GAME ,
BLINDS ,
LOCATION ,
@ -158,158 +164,123 @@ enum class SessionRow : RowRepresentable {
}
}
override val bottomSheetType : BottomShee tType
override val inputFragmentType : InputFragmen tType
get ( ) {
return when ( this ) {
NET _RESULT , CASHED _OUT , INITIAL _BUY _IN , BREAK _TIME , POSITION , PLAYERS , PRIZE -> BottomShee tType. NUMERIC _TEXT
BUY _IN , TIPS -> BottomShee tType. SUM
BLINDS -> BottomShee tType . DOUBLE _EDIT _TEXT
GAME -> BottomShee tType . LIST _GAME
TOURNAMENT _TYPE -> BottomShee tType. LIST _STATIC
LOCATION , BANKROLL , TOURNAMENT _NAME -> BottomShee tType. LIST
TOURNAMENT _FEATURE -> BottomShee tType. MULTI _SELECTION
TABLE _SIZE -> BottomShee tType. GRID
COMMENT -> BottomShee tType . EDIT _TEXT _MULTI _LINES
else -> BottomShee tType . NONE
NET _RESULT , CASHED _OUT , INITIAL _BUY _IN , BREAK _TIME , POSITION , PLAYERS , PRIZE -> InputFragmen tType. NUMERIC _TEXT
BUY _IN , TIPS -> InputFragmen tType. SUM
BLINDS -> InputFragmen tType . DOUBLE _EDIT _TEXT
GAME -> InputFragmen tType . LIST _GAME
TOURNAMENT _TYPE -> InputFragmen tType. LIST _STATIC
LOCATION , BANKROLL , TOURNAMENT _NAME -> InputFragmen tType. LIST
TOURNAMENT _FEATURE -> InputFragmen tType. MULTI _SELECTION
TABLE _SIZE -> InputFragmen tType. GRID
COMMENT -> InputFragmen tType . EDIT _TEXT _MULTI _LINES
else -> InputFragmen tType . NONE
}
}
override fun editingDescriptors ( map : Map < String , Any ? > ) : ArrayList < RowRepresentableEditDescriptor > ? {
return when ( this ) {
BLINDS -> {
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
override fun startEditing ( dataSource : Any ? , parent : Fragment ? ) {
if ( dataSource == null ) return
if ( dataSource !is Session ) return
if ( parent == null ) return
if ( parent !is RowRepresentableDelegate ) return
val session : Session = dataSource
val data = RowEditableDataSource ( session . currency )
when ( this ) {
START _DATE -> {
data . appendDateDescriptor ( session . startDate )
}
END _DATE -> {
if ( session . startDate == null ) {
Toast . makeText ( parent . context , R . string . session _missing _start _date , Toast . LENGTH _SHORT ) . show ( )
return
} else {
data . appendDateDescriptor ( session . endDate ?: session . startDate ?: Date ( ) , session . startDate )
}
}
BANKROLL -> data . append ( session . bankroll , data = session . realm . sorted < Bankroll > ( ) )
CASHED _OUT , PRIZE -> data . append (
session . result ?. cashout ,
inputType = InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL or InputType . TYPE _NUMBER _FLAG _SIGNED
)
NET _RESULT -> data . append (
session . result ?. netResult ,
inputType = InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL or InputType . TYPE _NUMBER _FLAG _SIGNED
)
}
INITIAL _BUY _IN -> data . append ( session . tournamentEntryFee ?. round ( ) , inputType = InputType . TYPE _CLASS _NUMBER )
BUY _IN -> {
val bb : Double ? by map
val fee : Double ? by map
val ratedBuyin : Double ? by map
val data = arrayListOf < RowRepresentableEditDescriptor > ( )
val bb : Double ? = session . cgBigBlind
val fee : Double ? = session . tournamentEntryFee
val ratedBuyin : Double ? = session . result ?. buyin
if ( bb != null ) {
data . add ( RowRepresentableEditDescriptor ( 100.0 * ( bb ?: 0.0 ) ) )
data . add ( RowRepresentableEditDescriptor ( 200.0 * ( bb ?: 0.0 ) ) )
data . app end ( 100.0 * bb )
data . app end ( 200.0 * bb )
} else if ( fee != null ) {
data . add ( RowRepresentableEditDescriptor ( ( fee ?: 0.0 ) * 1.0 ) )
data . add ( RowRepres entableE ditDescriptor ( ( fee ?: 0.0 ) * 2.0 ) )
data . app end ( fee )
data . app end ( fee * 2.0 )
} else {
data . add ( RowRepres entableE ditDescriptor ( 0 ) )
data . add ( RowRepres entableE ditDescriptor ( 0 ) )
data . app end ( 0 )
data . app end ( 0 )
}
data . add ( RowRepresentableEditDescriptor ( ratedBuyin ) )
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
data . append ( ratedBuyin )
data . append ( inputType = InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL )
data . append ( inputType = InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL )
}
CASHED _OUT , PRIZE , NET _RESULT -> {
val defaultValue : Double ? by map
arrayListOf (
RowRepresentableEditDescriptor (
defaultValue ,
POSITION -> data . append ( session . result ?. tournamentFinalPosition , inputType = InputType . TYPE _CLASS _NUMBER )
PLAYERS -> data . append (
session . tournamentNumberOfPlayers . toString ( ) ,
inputType = InputType . TYPE _CLASS _NUMBER
or InputType . TYPE _NUMBER _FLAG _DECIMAL
or InputType . TYPE _NUMBER _FLAG _SIGNED
)
)
}
COMMENT -> {
val defaultValue : String ? by map
arrayListOf ( RowRepresentableEditDescriptor ( defaultValue , R . string . comment ) )
}
BREAK _TIME -> {
arrayListOf (
RowRepresentableEditDescriptor (
hint = R . string . in _minutes , inputType = InputType . TYPE _CLASS _NUMBER
)
)
TIPS -> {
val sb : String ? = session . cgSmallBlind ?. round ( )
val bb : String ? = session . cgBigBlind ?. round ( )
val tips : Double ? = session . result ?. tips
data . append ( sb ?: 0.0 )
data . append ( bb ?: 0.0 )
data . append ( tips ?: 0.0 )
data . append ( " " , inputType = InputType . TYPE _CLASS _NUMBER )
data . append ( " " , inputType = InputType . TYPE _CLASS _NUMBER )
}
GAME -> {
val limit : Int ? by map
val defaultValue : Any ? by map
val data : RealmResults < RowRepresentable > ? by map
arrayListOf (
RowRepresentableEditDescriptor ( limit ) ,
RowRepresentableEditDescriptor ( defaultValue , data = data )
)
data . append ( session . limit )
data . append ( session . game , data = session . realm . sorted < Game > ( ) )
}
INITIAL _BUY _IN -> {
val defaultValue : Double ? by map
arrayListOf (
RowRepresentableEditDescriptor ( defaultValue ?. round ( ) , inputType = InputType . TYPE _CLASS _NUMBER )
BLINDS -> {
data . append (
session . cgSmallBlind ?. round ( ) ,
R . string . smallblind ,
InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL
)
}
BANKROLL , LOCATION , TOURNAMENT _FEATURE , TOURNAMENT _NAME -> {
val defaultValue : Any ? by map
val data : RealmResults < RowRepresentable > ? by map
arrayListOf (
RowRepresentableEditDescriptor ( defaultValue , data = data )
data . append (
session . cgBigBlind ?. round ( ) ,
R . string . bigblind ,
InputType . TYPE _CLASS _NUMBER or InputType . TYPE _NUMBER _FLAG _DECIMAL
)
}
PLAYERS -> {
val defaultValue : Int ? by map
arrayListOf (
RowRepresentableEditDescriptor (
defaultValue ?. toString ( ) ,
inputType = InputType . TYPE _CLASS _NUMBER
)
LOCATION -> data . append ( session . location , data = session . realm . sorted < Location > ( ) )
TABLE _SIZE -> data . append ( session . tableSize )
TOURNAMENT _TYPE -> data . append ( session . tournamentType , staticData = TournamentType . values ( ) . map { it } )
TOURNAMENT _NAME -> data . append ( session . tournamentName , data = session . realm . sorted < TournamentName > ( ) )
TOURNAMENT _FEATURE -> data . append (
session . tournamentFeatures ,
data = session . realm . sorted < TournamentFeature > ( )
)
BREAK _TIME -> data . append ( hint = R . string . in _minutes , inputType = InputType . TYPE _CLASS _NUMBER )
COMMENT -> data . append ( session . comment , R . string . comment )
}
POSITION -> {
val defaultValue : Int ? by map
arrayListOf (
RowRepresentableEditDescriptor (
defaultValue ,
inputType = InputType . TYPE _CLASS _NUMBER
)
)
InputFragment . buildAndShow ( this , parent , data )
}
TABLE _SIZE -> {
val defaultValue : Int ? by map
arrayListOf ( RowRepresentableEditDescriptor ( defaultValue ) )
}
TIPS -> {
val sb : String ? by map
val bb : String ? 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
override val valueCanBeClearedWhenEditing : Boolean
get ( ) {
return when ( this ) {
BANKROLL -> false
else -> true
}
}
}