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

Loading…
Cancel
Save