|
|
|
|
@ -5,10 +5,9 @@ import io.realm.RealmList |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.annotations.Ignore |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Manageable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
@ -18,7 +17,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class CustomField : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { |
|
|
|
|
open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable { |
|
|
|
|
|
|
|
|
|
enum class Type(var resId: Int) { |
|
|
|
|
LIST(R.string.enum_custom_field_type), |
|
|
|
|
@ -40,7 +39,7 @@ open class CustomField : RealmObject(), Manageable, StaticRowRepresentableDataSo |
|
|
|
|
override var id = UUID.randomUUID().toString() |
|
|
|
|
|
|
|
|
|
// The name of the currency field |
|
|
|
|
var name: String = "" |
|
|
|
|
override var name: String = "" |
|
|
|
|
|
|
|
|
|
// Migration |
|
|
|
|
var type: Int = Type.LIST.ordinal |
|
|
|
|
@ -75,12 +74,14 @@ open class CustomField : RealmObject(), Manageable, StaticRowRepresentableDataSo |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun alreadyExists(realm: Realm): Boolean { |
|
|
|
|
return realm.where<CustomField>().equalTo("id", id).findFirst() != null |
|
|
|
|
return realm.where(this::class.java).equalTo("name", this.name).and().notEqualTo("id", this.id).findAll().isNotEmpty() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getFailedSaveMessage(status: SaveValidityStatus): Int { |
|
|
|
|
//TODO: |
|
|
|
|
return R.string.relationship_error |
|
|
|
|
return when (status) { |
|
|
|
|
SaveValidityStatus.DATA_INVALID -> R.string.cf_empty_field_error |
|
|
|
|
else -> super.getFailedSaveMessage(status) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun isValidForDelete(realm: Realm): Boolean { |
|
|
|
|
|