|
|
|
|
@ -1,11 +1,9 @@ |
|
|
|
|
package net.pokeranalytics.android.model.interfaces |
|
|
|
|
|
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.RealmModel |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
enum class ManageableStatus { |
|
|
|
|
@ -17,7 +15,7 @@ enum class ManageableStatus { |
|
|
|
|
/** |
|
|
|
|
* An interface to grouped object which are managed by the database |
|
|
|
|
*/ |
|
|
|
|
interface Manageable : Savable, Deletable, Identifiable, Editable |
|
|
|
|
interface Manageable : Savable, Deletable, Editable |
|
|
|
|
|
|
|
|
|
interface NameManageable: Manageable { |
|
|
|
|
var name: String |
|
|
|
|
@ -27,7 +25,10 @@ interface NameManageable: Manageable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun alreadyExists(): Boolean { |
|
|
|
|
return (this as RealmObject).realm.where((this as RealmObject)::class.java).equalTo("name", this.name).findAll().isNotEmpty() |
|
|
|
|
if (this is RealmObject && this.realm != null) { |
|
|
|
|
return (this as RealmObject).realm.where(this::class.java).equalTo("name", this.name).findAll().isNotEmpty() |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getFailedSaveMessage(status: ManageableStatus): Int { |
|
|
|
|
@ -43,7 +44,7 @@ interface NameManageable: Manageable { |
|
|
|
|
/** |
|
|
|
|
* An interface associate a unique identifier to an object |
|
|
|
|
*/ |
|
|
|
|
interface Identifiable { |
|
|
|
|
interface Identifiable : RealmModel { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A unique identifier getter |
|
|
|
|
@ -54,7 +55,7 @@ interface Identifiable { |
|
|
|
|
/** |
|
|
|
|
* An interface to update the fields of an object |
|
|
|
|
*/ |
|
|
|
|
interface Editable { |
|
|
|
|
interface Editable : Identifiable { |
|
|
|
|
/** |
|
|
|
|
* a method to handle the modification of the object. |
|
|
|
|
* Through [RowRepresentable] the object is able to update the right variable with the new value. |
|
|
|
|
@ -65,7 +66,7 @@ interface Editable { |
|
|
|
|
/** |
|
|
|
|
* An interface to easily handle the validity of any object we want to save |
|
|
|
|
*/ |
|
|
|
|
interface Savable { |
|
|
|
|
interface Savable : Identifiable { |
|
|
|
|
|
|
|
|
|
fun isValidForSave(): Boolean |
|
|
|
|
fun alreadyExists(): Boolean |
|
|
|
|
@ -96,7 +97,7 @@ interface Savable { |
|
|
|
|
/** |
|
|
|
|
* An interface to easily handle the validity of any object we want to delete |
|
|
|
|
*/ |
|
|
|
|
interface Deletable { |
|
|
|
|
interface Deletable : Identifiable { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A method to define if an object is safe for deletion in database |
|
|
|
|
|