|
|
|
@ -8,29 +8,12 @@ import io.realm.kotlin.where |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus |
|
|
|
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
|
|
|
|
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.rowrepresentable.BankrollRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.BankrollRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class Bankroll() : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable { |
|
|
|
open class Bankroll() : RealmObject(), NameManageable, RowRepresentable { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
val rowRepresentation : List<RowRepresentable> by lazy { |
|
|
|
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
|
|
|
rows.add(SimpleRow.NAME) |
|
|
|
|
|
|
|
rows.add(BankrollRow.LIVE) |
|
|
|
|
|
|
|
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.currency)) |
|
|
|
|
|
|
|
rows.add(BankrollRow.CURRENCY) |
|
|
|
|
|
|
|
rows |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
@PrimaryKey |
|
|
|
override var id = UUID.randomUUID().toString() |
|
|
|
override var id = UUID.randomUUID().toString() |
|
|
|
@ -46,44 +29,21 @@ open class Bankroll() : RealmObject(), NameManageable, StaticRowRepresentableDat |
|
|
|
// The currency of the bankroll |
|
|
|
// The currency of the bankroll |
|
|
|
var currency: Currency? = null |
|
|
|
var currency: Currency? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The initial value of the bankroll |
|
|
|
|
|
|
|
var initialValue: Double = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
override fun getDisplayName(): String { |
|
|
|
override fun getDisplayName(): String { |
|
|
|
return this.name |
|
|
|
return this.name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Row Representable Datasource |
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
|
|
|
return Bankroll.rowRepresentation |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: RowRepresentable): String { |
|
|
|
|
|
|
|
return when (row) { |
|
|
|
|
|
|
|
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT |
|
|
|
|
|
|
|
else -> return super.stringForRow(row) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: RowRepresentable): Boolean { |
|
|
|
|
|
|
|
return when (row) { |
|
|
|
|
|
|
|
BankrollRow.LIVE -> !this.live |
|
|
|
|
|
|
|
else -> super.boolForRow(row) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? { |
|
|
|
|
|
|
|
return when (row) { |
|
|
|
|
|
|
|
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.name)) |
|
|
|
|
|
|
|
BankrollRow.RATE -> row.editingDescriptors(mapOf()) |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
row.editingDescriptors(mapOf()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
|
|
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
|
|
|
when (row) { |
|
|
|
when (row) { |
|
|
|
SimpleRow.NAME -> this.name = value as String? ?: "" |
|
|
|
SimpleRow.NAME -> this.name = value as String? ?: "" |
|
|
|
BankrollRow.LIVE -> { |
|
|
|
BankrollRow.LIVE -> { |
|
|
|
this.live = if (value is Boolean) !value else false |
|
|
|
this.live = if (value is Boolean) !value else false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BankrollRow.INITIAL_VALUE -> { |
|
|
|
|
|
|
|
this.initialValue = value as Double? ?: 0.0 |
|
|
|
} |
|
|
|
} |
|
|
|
BankrollRow.CURRENCY -> { |
|
|
|
BankrollRow.CURRENCY -> { |
|
|
|
//TODO handle a use default currency option |
|
|
|
//TODO handle a use default currency option |
|
|
|
|