Format Game

feature/top10
Aurelien Hubert 7 years ago
parent b36d0a582e
commit 872a239236
  1. 107
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt

@ -11,69 +11,68 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Game : RealmObject(), Savable, StaticRowRepresentableDataSource, open class Game : RealmObject(), Savable, StaticRowRepresentableDataSource, RowRepresentable {
RowRepresentable {
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
// The name of the game // The name of the game
var name: String = "" var name: String = ""
// A shorter name for the game // A shorter name for the game
var shortName: String? = null var shortName: String? = null
override fun getDisplayName(): String { override fun getDisplayName(): String {
return this.name return this.name
} }
override fun uniqueIdentifier(): String { override fun uniqueIdentifier(): String {
return this.id return this.id
} }
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>() val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME) rows.add(SimpleRow.NAME)
rows.addAll(GameRow.values()) rows.addAll(GameRow.values())
return rows return rows
} }
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name
GameRow.SHORT_NAME -> this.shortName?:"" GameRow.SHORT_NAME -> this.shortName ?: ""
else -> return super.stringForRow(row) else -> return super.stringForRow(row)
} }
} }
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> { override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>() val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) { when (row) {
SimpleRow.NAME -> data.add( SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor( RowRepresentableEditDescriptor(
this.name, this.name,
SimpleRow.NAME.resId SimpleRow.NAME.resId
) )
) )
GameRow.SHORT_NAME -> data.add( GameRow.SHORT_NAME -> data.add(
RowRepresentableEditDescriptor( RowRepresentableEditDescriptor(
this.shortName, this.shortName,
GameRow.SHORT_NAME.resId GameRow.SHORT_NAME.resId
) )
) )
} }
return data return data
} }
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? ?: ""
GameRow.SHORT_NAME -> this.shortName = value as String GameRow.SHORT_NAME -> this.shortName = value as String
} }
} }
override fun isValidForSave(): Boolean { override fun isValidForSave(): Boolean {
return this.name.isNotEmpty() return this.name.isNotEmpty()
} }
} }

Loading…
Cancel
Save