improve delete and save management and add consistency through all the mangeable objects, add some todo

feature/top10
Razmig Sarkissian 7 years ago
parent a8edc36724
commit cd1b24f3b1
  1. 79
      app/src/main/java/net/pokeranalytics/android/model/interfaces/Manageable.kt
  2. 32
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  3. 31
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  4. 31
      app/src/main/java/net/pokeranalytics/android/model/realm/Location.kt
  5. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  7. 22
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  8. 16
      app/src/main/java/net/pokeranalytics/android/model/realm/Transaction.kt
  9. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  10. 20
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  11. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  12. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/BankrollRow.kt
  13. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/GameRow.kt
  14. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/LocationRow.kt
  15. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SimpleRow.kt
  16. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentFeatureRow.kt
  17. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentNameRow.kt
  18. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt
  19. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionTypeRow.kt

@ -1,12 +1,44 @@
package net.pokeranalytics.android.model.interfaces package net.pokeranalytics.android.model.interfaces
import io.realm.Realm
import io.realm.RealmObject
import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.ModelException
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
enum class ManageableStatus {
VALID,
ALREADY_EXISTS,
DATA_INVALID;
}
/** /**
* An interface to grouped object which are managed by the database * An interface to grouped object which are managed by the database
*/ */
interface Manageable : Savable, Deletable, Identifiable interface Manageable : Savable, Deletable, Identifiable, Editable
interface NameManageable: Manageable {
var name: String
override fun isValidForSave(): Boolean {
return this.name.isNotEmpty()
}
override fun alreadyExists(): Boolean {
return (this as RealmObject).realm.where((this as RealmObject)::class.java).equalTo("name", this.name).findAll().isNotEmpty()
}
override fun getFailedSaveMessage(status: ManageableStatus): Int {
return when (status) {
ManageableStatus.ALREADY_EXISTS -> R.string.duplicate_bankroll_name_error
ManageableStatus.DATA_INVALID -> R.string.empty_name_for_br_error
else -> throw ModelException("object should be savable")
}
}
}
/** /**
* An interface associate a unique identifier to an object * An interface associate a unique identifier to an object
@ -19,30 +51,45 @@ interface Identifiable {
var id: String var id: String
} }
/**
* An interface to update the fields of an object
*/
interface Editable {
/**
* a method to handle the modification of the object.
* Through [RowRepresentable] the object is able to update the right variable with the new value.
*/
fun updateValue(value: Any?, row: RowRepresentable)
}
/** /**
* An interface to easily handle the validity of any object we want to save * An interface to easily handle the validity of any object we want to save
*/ */
interface Savable { interface Savable {
fun isValidForSave(): Boolean
fun alreadyExists(): Boolean
/** /**
* A method to define if an object is safe for saving in database * A method to define if an object is safe for saving in database
*/ */
fun isValidForSave(): Boolean { fun saveStatus(): ManageableStatus {
//TODO should be by default to false if (!isValidForSave()) {
return true return ManageableStatus.DATA_INVALID
} }
/** if (alreadyExists()) {
* A method to get the reason why the object can't be saved return ManageableStatus.ALREADY_EXISTS
*/
fun getFailedSaveMessage(): Int {
return R.string.none
} }
return ManageableStatus.VALID
}
/** /**
* a method to handle the modification of the object. * A method to get the reason why the object can't be saved
* Through [RowRepresentable] the object is able to update the right variable with the new value.
*/ */
fun updateValue(value: Any?, row: RowRepresentable) fun getFailedSaveMessage(status:ManageableStatus): Int
} }
@ -54,14 +101,10 @@ interface Deletable {
/** /**
* A method to define if an object is safe for deletion in database * A method to define if an object is safe for deletion in database
*/ */
fun isValidForDelete(): Boolean { fun isValidForDelete(): Boolean
return true
}
/** /**
* A method to get the reason why the object can't be deleted * A method to get the reason why the object can't be deleted
*/ */
fun getFailedDeleteMessage(): Int { fun getFailedDeleteMessage(): Int
return R.string.none
}
} }

@ -5,7 +5,8 @@ import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowRepresentableEditDescriptor
@ -17,12 +18,11 @@ import net.pokeranalytics.android.util.NULL_TEXT
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Bankroll(name: String = "") : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { open class Bankroll(override var name: String = "") : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable {
companion object { companion object {
fun newInstance() : Bankroll { fun newInstance() : Bankroll {
val bankroll = Bankroll() return Bankroll()
return bankroll
} }
val rowRepresentation : List<RowRepresentable> by lazy { val rowRepresentation : List<RowRepresentable> by lazy {
@ -38,9 +38,6 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable, StaticRowRep
@PrimaryKey @PrimaryKey
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// the name of the bankroll
var name: String = name
// Indicates whether the bankroll is live or online // Indicates whether the bankroll is live or online
var live: Boolean = true var live: Boolean = true
@ -67,9 +64,9 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable, StaticRowRep
} }
override fun boolForRow(row: RowRepresentable): Boolean { override fun boolForRow(row: RowRepresentable): Boolean {
when (row) { return when (row) {
BankrollRow.LIVE -> return !this.live BankrollRow.LIVE -> !this.live
else -> return super.boolForRow(row) else -> super.boolForRow(row)
} }
} }
@ -92,20 +89,17 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable, StaticRowRep
} }
} }
override fun isValidForSave(): Boolean {
return this.name.isNotEmpty()
}
override fun getFailedSaveMessage(): Int {
return R.string.empty_name_for_br_error
}
override fun isValidForDelete(): Boolean { override fun isValidForDelete(): Boolean {
return this.realm.where<Session>().equalTo("bankroll.id", id).findAll().isEmpty() return this.realm.where<Session>().equalTo("bankroll.id", id).findAll().isEmpty()
} }
override fun getFailedDeleteMessage(): Int { override fun getFailedDeleteMessage(): Int {
return R.string.bankroll_relationship_error TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun getFailedSaveMessage(status: ManageableStatus): Int {
if (status == ManageableStatus.DATA_INVALID) R.string.empty_name_for_br_error
else if (status == ManageableStatus.ALREADY_EXISTS) R.string.duplicate_bankroll_name_error
return super.getFailedSaveMessage(status)
}
} }

@ -2,9 +2,11 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.CountableUsage import net.pokeranalytics.android.model.interfaces.CountableUsage
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowRepresentableEditDescriptor
@ -14,7 +16,7 @@ import net.pokeranalytics.android.util.NULL_TEXT
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable, CountableUsage { open class Game : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable, CountableUsage {
companion object { companion object {
val rowRepresentation : List<RowRepresentable> by lazy { val rowRepresentation : List<RowRepresentable> by lazy {
@ -29,7 +31,7 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// The name of the game // The name of the game
var name: String = "" override var name: String = ""
// A shorter name for the game // A shorter name for the game
var shortName: String? = null var shortName: String? = null
@ -69,10 +71,27 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
} }
override fun isValidForSave(): Boolean { override fun isValidForSave(): Boolean {
return this.name.isNotEmpty() return name.isNotEmpty() && !shortName.isNullOrEmpty()
} }
override fun getFailedSaveMessage(): Int { override fun getFailedSaveMessage(status: ManageableStatus): Int {
return R.string.variant_empty_name_error if (status == ManageableStatus.DATA_INVALID) {
return if (name.isEmpty()) {
R.string.variant_empty_name_error
} else {
R.string.variant_empty_shortname_error
}
}
else if (status == ManageableStatus.ALREADY_EXISTS) return R.string.duplicate_variant_error
return super.getFailedSaveMessage(status)
}
override fun isValidForDelete(): Boolean {
return this.realm.where<Session>().equalTo("game.id", id).findAll().isEmpty()
}
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }

@ -3,23 +3,25 @@ package net.pokeranalytics.android.model.realm
import com.google.android.libraries.places.api.model.Place import com.google.android.libraries.places.api.model.Place
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import java.util.* import java.util.*
open class Location : RealmObject(), Manageable, RowRepresentable { open class Location : RealmObject(), NameManageable, RowRepresentable {
@PrimaryKey @PrimaryKey
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// The name of the location // The name of the location
var name: String = "" override var name: String = ""
// The readable address of the location // The readable address of the location
var address: String = "" private var address: String = ""
// the longitude of the location // the longitude of the location
var longitude: Double? = null var longitude: Double? = null
@ -37,14 +39,6 @@ open class Location : RealmObject(), Manageable, RowRepresentable {
} }
} }
override fun isValidForSave(): Boolean {
return this.name.isNotEmpty()
}
override fun getFailedSaveMessage(): Int {
return R.string.location_empty_field_error
}
/** /**
* Fill the location attributes with a place object * Fill the location attributes with a place object
*/ */
@ -55,4 +49,17 @@ open class Location : RealmObject(), Manageable, RowRepresentable {
this.longitude = place.latLng?.longitude this.longitude = place.latLng?.longitude
} }
override fun getFailedSaveMessage(status: ManageableStatus): Int {
if (status == ManageableStatus.DATA_INVALID) R.string.location_empty_field_error
else if (status == ManageableStatus.ALREADY_EXISTS) R.string.duplicate_location_error
return super.getFailedSaveMessage(status)
}
override fun isValidForDelete(): Boolean {
return this.realm.where<Session>().equalTo("location.id", id).findAll().isEmpty()
}
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }

@ -23,9 +23,7 @@ import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.filter.Filterable import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryType import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.model.filter.QueryType.* import net.pokeranalytics.android.model.filter.QueryType.*
import net.pokeranalytics.android.model.interfaces.TimeFilterable import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.interfaces.Timed
import net.pokeranalytics.android.model.utils.SessionSetManager import net.pokeranalytics.android.model.utils.SessionSetManager
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException
@ -42,7 +40,7 @@ import java.util.*
import java.util.Currency import java.util.Currency
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable, Timed, open class Session : RealmObject(), Identifiable, Editable, StaticRowRepresentableDataSource, RowRepresentable, Timed,
TimeFilterable { TimeFilterable {
enum class Type { enum class Type {
@ -802,6 +800,5 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
} }
realm.commitTransaction() realm.commitTransaction()
} }
} }

@ -2,8 +2,10 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.model.interfaces.CountableUsage import net.pokeranalytics.android.model.interfaces.CountableUsage
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowRepresentableEditDescriptor
@ -13,7 +15,7 @@ import net.pokeranalytics.android.util.NULL_TEXT
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable, open class TournamentFeature : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable,
CountableUsage { CountableUsage {
companion object { companion object {
@ -29,7 +31,7 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// The name of the feature // The name of the feature
var name: String = "" override var name: String = ""
// CountableUsage // CountableUsage
override var useCount: Int = 0 override var useCount: Int = 0
@ -60,8 +62,17 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
} }
} }
override fun isValidForSave(): Boolean { override fun getFailedSaveMessage(status: ManageableStatus): Int {
return this.name.isNotEmpty() //TODO if (status == ManageableStatus.DATA_INVALID) R.string.tournament_feature_empty_field_error
//TODO else if (status == ManageableStatus.ALREADY_EXISTS) R.string.duplicate_tournament_feature_error
return super.getFailedSaveMessage(status)
} }
override fun isValidForDelete(): Boolean {
return this.realm.where<Session>().equalTo("tournamentFeatures.id", id).findAll().isEmpty()
}
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }

@ -2,8 +2,9 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R import io.realm.kotlin.where
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowRepresentableEditDescriptor
@ -14,7 +15,7 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { open class TournamentName : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable {
companion object { companion object {
val rowRepresentation : List<RowRepresentable> by lazy { val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>() val rows = ArrayList<RowRepresentable>()
@ -28,7 +29,7 @@ open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDat
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// The name of the tournament // The name of the tournament
var name: String = "" override var name: String = ""
override fun getDisplayName(): String { override fun getDisplayName(): String {
return this.name return this.name
@ -55,12 +56,17 @@ open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDat
return row.editingDescriptors(mapOf("defaultValue" to this.name)) return row.editingDescriptors(mapOf("defaultValue" to this.name))
} }
override fun isValidForSave(): Boolean { override fun getFailedSaveMessage(status: ManageableStatus): Int {
return this.name.isNotEmpty() //TODO if (status == ManageableStatus.DATA_INVALID) R.string.tournament_name_empty_field_error
//TODO else if (status == ManageableStatus.ALREADY_EXISTS) R.string.duplicate_tournament_name_error
return super.getFailedSaveMessage(status)
} }
override fun getFailedSaveMessage(): Int { override fun isValidForDelete(): Boolean {
return R.string.tt_empty_field_error return this.realm.where<Session>().equalTo("tournamentName.id", id).findAll().isEmpty()
} }
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }

@ -5,6 +5,7 @@ import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.interfaces.ManageableStatus
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
@ -62,15 +63,26 @@ open class Transaction : RealmObject(), Manageable, StaticRowRepresentableDataSo
return bankroll != null && type != null && amount != 0.0 return bankroll != null && type != null && amount != 0.0
} }
override fun getFailedSaveMessage(): Int { override fun alreadyExists(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getFailedSaveMessage(status: ManageableStatus): Int {
return if (bankroll == null) { return if (bankroll == null) {
R.string.no_br_popup_message R.string.no_br_popup_message
} else if (type == null || amount == 0.0) { } else if (type == null || amount == 0.0) {
R.string.operation_empty_field_error R.string.operation_empty_field_error
} else { } else {
super.getFailedSaveMessage() TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
override fun isValidForDelete(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }

@ -2,7 +2,7 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowRepresentableEditDescriptor
@ -12,7 +12,7 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable {
companion object { companion object {
val rowRepresentation : List<RowRepresentable> by lazy { val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>() val rows = ArrayList<RowRepresentable>()
@ -26,7 +26,7 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
override var id = UUID.randomUUID().toString() override var id = UUID.randomUUID().toString()
// The name of the transaction type // The name of the transaction type
var name: String = "" override var name: String = ""
// Whether or not the amount is added, or subtracted to the bankroll total // Whether or not the amount is added, or subtracted to the bankroll total
var additive: Boolean = false var additive: Boolean = false
@ -62,10 +62,13 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
} }
} }
override fun isValidForSave(): Boolean { override fun isValidForDelete(): Boolean {
return this.name.isNotEmpty() TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun getFailedDeleteMessage(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
} }
enum class TransactionKind { enum class TransactionKind {

@ -11,9 +11,7 @@ import kotlinx.android.synthetic.main.fragment_editable_data.*
import kotlinx.android.synthetic.main.fragment_editable_data.view.* import kotlinx.android.synthetic.main.fragment_editable_data.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.interfaces.Identifiable import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.interfaces.Savable
import net.pokeranalytics.android.model.realm.Bankroll import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.ui.activity.EditableDataActivity import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
@ -71,7 +69,7 @@ open class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDele
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
this.getRealm().executeTransaction { this.getRealm().executeTransaction {
(this.item as Savable).updateValue(value, row) (this.item as Editable).updateValue(value, row)
} }
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
@ -142,7 +140,10 @@ open class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDele
* Save data * Save data
*/ */
fun saveData() { fun saveData() {
if ((this.item as Savable).isValidForSave()) { if (this.item is Savable) {
val status = (this.item as Savable).saveStatus()
when (status) {
ManageableStatus.VALID -> {
this.getRealm().executeTransaction { this.getRealm().executeTransaction {
val item = it.copyToRealmOrUpdate(this.item) val item = it.copyToRealmOrUpdate(this.item)
@ -156,14 +157,19 @@ open class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDele
finishActivityWithResult(uniqueIdentifier) finishActivityWithResult(uniqueIdentifier)
} }
} else { }
val message = (this.item as Savable).getFailedSaveMessage() else -> {
val message = (this.item as Savable).getFailedSaveMessage(status)
val builder = AlertDialog.Builder(requireContext()) val builder = AlertDialog.Builder(requireContext())
.setMessage(message) .setMessage(message)
.setNegativeButton(R.string.ok, null) .setNegativeButton(R.string.ok, null)
builder.show() builder.show()
} }
} }
} else {
return
}
}
/** /**
* Delete data * Delete data

@ -8,20 +8,20 @@ import net.pokeranalytics.android.util.NULL_TEXT
/** /**
* An interface extending Displayable to add a way to represent an object as a String * An interface extending Displayable to add a way to represent an object as a String
*/ */
interface RowRepresentable : Displayable, Editable { interface RowRepresentable : Displayable, EditDataSource {
fun getDisplayName(): String { fun getDisplayName(): String {
return NULL_TEXT return NULL_TEXT
} }
} }
interface Editable { interface EditDataSource {
fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return null return null
} }
} }
interface DefaultEditable : Editable, Localizable { interface DefaultEditDataSource : EditDataSource, Localizable {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue: String? by map val defaultValue: String? by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId)) return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))

@ -3,13 +3,13 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType import android.text.InputType
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
enum class BankrollRow : RowRepresentable, DefaultEditable { enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
LIVE, LIVE,
CURRENCY, CURRENCY,
RATE, RATE,

@ -2,12 +2,11 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
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.RowViewType
enum class GameRow : RowRepresentable, DefaultEditable { enum class GameRow : RowRepresentable, DefaultEditDataSource {
SHORT_NAME; SHORT_NAME;
override val resId: Int? override val resId: Int?

@ -2,13 +2,12 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
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.RowViewType
enum class LocationRow : RowRepresentable, DefaultEditable { enum class LocationRow : RowRepresentable, DefaultEditDataSource {
LOCATION_PERMISSION_SWITCH, LOCATION_PERMISSION_SWITCH,
LOCATION_LOADER; LOCATION_LOADER;

@ -2,12 +2,12 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
enum class SimpleRow : RowRepresentable, DefaultEditable { enum class SimpleRow : RowRepresentable, DefaultEditDataSource {
NAME; NAME;
override val resId: Int? = R.string.name override val resId: Int? = R.string.name

@ -1,6 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TournamentFeatureRow : RowRepresentable, DefaultEditable enum class TournamentFeatureRow : RowRepresentable, DefaultEditDataSource

@ -1,6 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TournamentNameRow : RowRepresentable, DefaultEditable enum class TournamentNameRow : RowRepresentable, DefaultEditDataSource

@ -4,13 +4,13 @@ import android.text.InputType
import io.realm.RealmResults import io.realm.RealmResults
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
enum class TransactionRow : RowRepresentable, DefaultEditable { enum class TransactionRow : RowRepresentable, DefaultEditDataSource {
BANKROLL, BANKROLL,
TYPE, TYPE,
AMOUNT, AMOUNT,

@ -1,6 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TransactionTypeRow : RowRepresentable, DefaultEditable enum class TransactionTypeRow : RowRepresentable, DefaultEditDataSource

Loading…
Cancel
Save