@ -5,6 +5,8 @@ import io.realm.RealmObject
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
@ -15,39 +17,47 @@ import java.util.*
import kotlin.collections.ArrayList
open class Transaction : RealmObject ( ) , Manageable , StaticRowRepresentableDataSource , RowRepresentable {
open class Transaction : RealmObject ( ) , Manageable , StaticRowRepresentableDataSource , RowRepresentable , Filterable {
companion object {
val rowRepresentation : List < RowRepresentable > by lazy {
val rowRepresentation : List < RowRepresentable > by lazy {
val rows = ArrayList < RowRepresentable > ( )
rows . addAll ( TransactionRow . values ( ) )
rows
}
fun fieldNameForQueryType ( queryCondition : Class < out QueryCondition > ) : String ? {
return when ( queryCondition ) {
QueryCondition . AnyBankroll :: class . java -> " bankroll.id "
QueryCondition . StartedFromDate :: class . java , QueryCondition . StartedToDate :: class . java -> " date "
else -> null
}
}
}
@PrimaryKey
@PrimaryKey
override var id = UUID . randomUUID ( ) . toString ( )
// The bankroll of the transaction
var bankroll : Bankroll ? = null
// The amount of the transaction
var amount : Double = 0.0
// The amount of the transaction
var amount : Double = 0.0
// The date of the transaction
var date : Date = Date ( )
// The date of the transaction
var date : Date = Date ( )
// The type of the transaction
var type : TransactionType ? = null
// The type of the transaction
var type : TransactionType ? = null
// A user comment
var comment : String = " "
// A user comment
var comment : String = " "
@Ignore
override val viewType : Int = RowViewType . ROW _TRANSACTION . ordinal
override fun updateValue ( value : Any ? , row : RowRepresentable ) {
when ( row ) {
when ( row ) {
TransactionRow . BANKROLL -> bankroll = value as Bankroll ?
TransactionRow . TYPE -> type = value as TransactionType ?
TransactionRow . AMOUNT -> amount = if ( value == null ) 0.0 else ( value as String ) . toDouble ( )
@ -85,5 +95,5 @@ open class Transaction : RealmObject(), Manageable, StaticRowRepresentableDataSo
override fun getFailedDeleteMessage ( ) : Int {
TODO ( " not implemented " ) //To change body of created functions use File | Settings | File Templates.
}
}
}