|
|
|
@ -22,7 +22,6 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
import net.pokeranalytics.android.util.enumerations.IntIdentifiable |
|
|
|
import net.pokeranalytics.android.util.enumerations.IntIdentifiable |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.collections.ArrayList |
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
@ -59,7 +58,11 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
// The type of the custom fields, mapped with the CustomField.Type enum |
|
|
|
// The type of the custom fields, mapped with the CustomField.Type enum |
|
|
|
var type: Int = Type.LIST.uniqueIdentifier |
|
|
|
var type: Int = Type.LIST.uniqueIdentifier |
|
|
|
set(value) { |
|
|
|
set(value) { |
|
|
|
|
|
|
|
if (field == Type.LIST.uniqueIdentifier && value != Type.LIST.uniqueIdentifier) { |
|
|
|
|
|
|
|
this.removeListEntries() |
|
|
|
|
|
|
|
} |
|
|
|
field = value |
|
|
|
field = value |
|
|
|
|
|
|
|
|
|
|
|
this.updateRowRepresentation() |
|
|
|
this.updateRowRepresentation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -244,7 +247,6 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun addEntry(): CustomFieldEntry { |
|
|
|
fun addEntry(): CustomFieldEntry { |
|
|
|
val entry = CustomFieldEntry() |
|
|
|
val entry = CustomFieldEntry() |
|
|
|
// entry.customField = this |
|
|
|
|
|
|
|
this.entries.add(entry) |
|
|
|
this.entries.add(entry) |
|
|
|
sortEntries() |
|
|
|
sortEntries() |
|
|
|
updateRowRepresentation() |
|
|
|
updateRowRepresentation() |
|
|
|
@ -261,25 +263,41 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
updateRowRepresentation() |
|
|
|
updateRowRepresentation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private fun removeListEntries() { |
|
|
|
* Clean the entries if the type is not a list & remove the deleted entries from realm |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun cleanEntries(realm: Realm) { |
|
|
|
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isListType) { |
|
|
|
this.entriesToDelete.addAll(entries) |
|
|
|
entriesToDelete.addAll(entries) |
|
|
|
this.entries.clear() |
|
|
|
entries.clear() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @TODO |
|
|
|
if (realm != null) { |
|
|
|
entriesToDelete.forEach { |
|
|
|
realm.executeTransaction { |
|
|
|
Timber.d("Delete entry: ${it.value} / ${it.id}") |
|
|
|
this.entriesToDelete.forEach { |
|
|
|
realm.where<CustomFieldEntry>().equalTo("id", it.id).findFirst()?.deleteFromRealm() |
|
|
|
if (it.isManaged) { |
|
|
|
|
|
|
|
it.deleteFromRealm() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
entriesToDelete.clear() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Clean the entries if the type is not a list & remove the deleted entries from realm |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// fun cleanEntries(realm: Realm) { |
|
|
|
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (!isListType) { |
|
|
|
|
|
|
|
// entriesToDelete.addAll(entries) |
|
|
|
|
|
|
|
// entries.clear() |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // @TODO |
|
|
|
|
|
|
|
// entriesToDelete.forEach { |
|
|
|
|
|
|
|
// Timber.d("Delete entry: V=${it.value} N=${it.numericValue} / ID=${it.id}") |
|
|
|
|
|
|
|
// realm.where<CustomFieldEntry>().equalTo("id", it.id).findFirst()?.deleteFromRealm() |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// entriesToDelete.clear() |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns a comparison criteria based on this custom field |
|
|
|
* Returns a comparison criteria based on this custom field |
|
|
|
|