|
|
|
|
@ -39,6 +39,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow |
|
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
import net.pokeranalytics.android.util.UserDefaults |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.text.DateFormat |
|
|
|
|
import java.util.* |
|
|
|
|
import java.util.Currency |
|
|
|
|
@ -293,6 +294,9 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
// The features of the tournament, like Knockout, Shootout, Turbo... |
|
|
|
|
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() |
|
|
|
|
|
|
|
|
|
// The custom fields values |
|
|
|
|
var customFieldEntries: RealmList<CustomFieldEntry> = RealmList() |
|
|
|
|
|
|
|
|
|
fun bankrollHasBeenUpdated() { |
|
|
|
|
formatBlinds() |
|
|
|
|
} |
|
|
|
|
@ -589,11 +593,13 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
* Delete the object from realm |
|
|
|
|
*/ |
|
|
|
|
fun delete() { |
|
|
|
|
if (isValid) { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
cleanup() |
|
|
|
|
deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This method is called whenever a session is about to be deleted |
|
|
|
|
@ -613,6 +619,16 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
@Ignore |
|
|
|
|
override val viewType: Int = RowViewType.ROW_SESSION.ordinal |
|
|
|
|
|
|
|
|
|
// Override to surcharge custom field viewType |
|
|
|
|
override fun viewTypeForPosition(position: Int): Int { |
|
|
|
|
rowRepresentationForCurrentState[position].let { |
|
|
|
|
if (it is CustomField) { |
|
|
|
|
return RowViewType.TITLE_VALUE.ordinal |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return super.viewTypeForPosition(position) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
|
return "Session ${this.creationDate}" |
|
|
|
|
} |
|
|
|
|
@ -678,6 +694,13 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
|
|
|
|
|
// Rows |
|
|
|
|
rows.addAll(SessionRow.getRows(this)) |
|
|
|
|
|
|
|
|
|
// Add custom fields |
|
|
|
|
realm?.let { |
|
|
|
|
rows.add(SeparatorRow()) |
|
|
|
|
rows.addAll(LiveData.CUSTOM_FIELD.itemsArray(it) as ArrayList<RowRepresentable>) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -711,11 +734,13 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
SessionRow.START_DATE -> this.startDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
|
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT |
|
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionRow.TOURNAMENT_TYPE -> this.tournamentType?.let { |
|
|
|
|
SessionRow.TOURNAMENT_TYPE -> { |
|
|
|
|
this.tournamentType?.let { |
|
|
|
|
TournamentType.values()[it].localizedTitle(context) |
|
|
|
|
} ?: run { |
|
|
|
|
NULL_TEXT |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionRow.TOURNAMENT_FEATURE -> { |
|
|
|
|
if (tournamentFeatures.size > 2) { |
|
|
|
|
"${tournamentFeatures.subList(0, 2).joinToString { |
|
|
|
|
@ -730,6 +755,12 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionRow.TOURNAMENT_NAME -> tournamentName?.name ?: NULL_TEXT |
|
|
|
|
is CustomField -> { |
|
|
|
|
customFieldEntries.find { it.customField?.id == row.id }?.let { customFieldEntry -> |
|
|
|
|
return customFieldEntry.getFormattedValue(currency) |
|
|
|
|
} |
|
|
|
|
return NULL_TEXT |
|
|
|
|
} |
|
|
|
|
else -> throw UnmanagedRowRepresentableException("Unmanaged row = ${row}") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -837,6 +868,19 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
"tips" to result?.tips |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
is CustomField -> { |
|
|
|
|
row.editingDescriptors( |
|
|
|
|
when (row.type) { |
|
|
|
|
CustomField.Type.LIST.uniqueIdentifier -> mapOf( |
|
|
|
|
"defaultValue" to customFieldEntries.find { it.customField?.id == row.id }?.value, |
|
|
|
|
"data" to row.entries |
|
|
|
|
) |
|
|
|
|
else -> mapOf( |
|
|
|
|
"defaultValue" to customFieldEntries.find { it.customField?.id == row.id }?.value |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
else -> null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -946,7 +990,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
result = localResult |
|
|
|
|
} |
|
|
|
|
SessionRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName? |
|
|
|
|
SessionRow.TOURNAMENT_TYPE -> tournamentType = value as Int? |
|
|
|
|
SessionRow.TOURNAMENT_TYPE -> tournamentType = (value as TournamentType?)?.ordinal |
|
|
|
|
SessionRow.TOURNAMENT_FEATURE -> { |
|
|
|
|
|
|
|
|
|
value?.let { |
|
|
|
|
@ -956,6 +1000,33 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
tournamentFeatures.removeAll(this.tournamentFeatures) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
is CustomField -> { |
|
|
|
|
customFieldEntries.filter { it.customField?.id == row.id }.let { |
|
|
|
|
customFieldEntries.removeAll(it) |
|
|
|
|
} |
|
|
|
|
when (row.type) { |
|
|
|
|
CustomField.Type.AMOUNT.uniqueIdentifier, |
|
|
|
|
CustomField.Type.NUMBER.uniqueIdentifier -> { |
|
|
|
|
Timber.d("AMOUNT or NUMBER: ${value}") |
|
|
|
|
if (value != null) { |
|
|
|
|
val customFieldEntry = CustomFieldEntry() |
|
|
|
|
customFieldEntry.customField = row |
|
|
|
|
customFieldEntry.value = value.toString() |
|
|
|
|
Timber.d("customFieldEntry: ${customFieldEntry.id}") |
|
|
|
|
Timber.d("customFieldEntry: ${customFieldEntry.customField}") |
|
|
|
|
Timber.d("customFieldEntry: ${customFieldEntry.value}") |
|
|
|
|
customFieldEntries.add(customFieldEntry) |
|
|
|
|
} |
|
|
|
|
Timber.d("customFieldEntries: ${customFieldEntries.size}") |
|
|
|
|
} |
|
|
|
|
CustomField.Type.LIST.uniqueIdentifier -> { |
|
|
|
|
if (value != null && value is CustomFieldEntry) { |
|
|
|
|
customFieldEntries.add(value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|