parent
dc1405bf7a
commit
e6df9e42ca
@ -1,19 +1,83 @@ |
|||||||
package net.pokeranalytics.android.model.realm |
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import io.realm.Realm |
||||||
import io.realm.RealmObject |
import io.realm.RealmObject |
||||||
|
import io.realm.annotations.Ignore |
||||||
import io.realm.annotations.PrimaryKey |
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.SaveValidityStatus |
||||||
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
||||||
import java.util.* |
import java.util.* |
||||||
|
|
||||||
|
|
||||||
open class CustomField : RealmObject() { |
open class CustomField : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { |
||||||
|
|
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
val rowRepresentation: List<RowRepresentable> by lazy { |
||||||
|
val rows = ArrayList<RowRepresentable>() |
||||||
|
rows.add(SimpleRow.NAME) |
||||||
|
rows.addAll(CustomFieldRow.values()) |
||||||
|
rows |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
@PrimaryKey |
@PrimaryKey |
||||||
var id = UUID.randomUUID().toString() |
override var id = UUID.randomUUID().toString() |
||||||
|
|
||||||
// The name of the currency field |
// The name of the currency field |
||||||
var name: String = "" |
var name: String = "" |
||||||
|
|
||||||
// @todo |
// @todo |
||||||
|
|
||||||
|
override fun getDisplayName(): String { |
||||||
|
return this.name |
||||||
|
} |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal |
||||||
|
|
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return rowRepresentation |
||||||
|
} |
||||||
|
|
||||||
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
||||||
|
when (row) { |
||||||
|
SimpleRow.NAME -> this.name = value as String? ?: "" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun isValidForSave(): Boolean { |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun alreadyExists(realm: Realm): Boolean { |
||||||
|
return realm.where<CustomField>().equalTo("id", id).findFirst() != null |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedSaveMessage(status: SaveValidityStatus): Int { |
||||||
|
//TODO: |
||||||
|
return R.string.relationship_error |
||||||
|
} |
||||||
|
|
||||||
|
override fun isValidForDelete(realm: Realm): Boolean { |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedDeleteMessage(status: DeleteValidityStatus): Int { |
||||||
|
//TODO: |
||||||
|
return R.string.relationship_error |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment.data |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.view.View |
||||||
|
import net.pokeranalytics.android.model.realm.CustomField |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
||||||
|
import net.pokeranalytics.android.util.NULL_TEXT |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Custom EditableDataFragment to manage the Transaction data |
||||||
|
*/ |
||||||
|
class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDataSource { |
||||||
|
|
||||||
|
// Return the item as a Custom Field object |
||||||
|
private val customField: CustomField |
||||||
|
get() { |
||||||
|
return this.item as CustomField |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
shouldOpenKeyboard = false |
||||||
|
} |
||||||
|
|
||||||
|
override fun getDataSource(): RowRepresentableDataSource { |
||||||
|
return this |
||||||
|
} |
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return customField.adapterRows() |
||||||
|
} |
||||||
|
|
||||||
|
override fun stringForRow(row: RowRepresentable): String { |
||||||
|
return when (row) { |
||||||
|
SimpleRow.NAME -> if (customField.name.isNotEmpty()) customField.name else NULL_TEXT |
||||||
|
else -> super.stringForRow(row) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun boolForRow(row: RowRepresentable): Boolean { |
||||||
|
return when (row) { |
||||||
|
CustomFieldRow.COPY_ON_DUPLICATE -> false |
||||||
|
else -> super.boolForRow(row) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? { |
||||||
|
return when (row) { |
||||||
|
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.customField.name)) |
||||||
|
else -> null |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||||
|
when (row) { |
||||||
|
else -> super.onRowSelected(position, row, fromAction) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
||||||
|
super.onRowValueChanged(value, row) |
||||||
|
rowRepresentableAdapter.refreshRow(row) |
||||||
|
|
||||||
|
/* |
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
delay(200) |
||||||
|
when(row) { |
||||||
|
TransactionRow.BANKROLL -> onRowSelected(0, TransactionRow.TYPE) |
||||||
|
TransactionRow.TYPE -> onRowSelected(0, TransactionRow.AMOUNT) |
||||||
|
TransactionRow.AMOUNT -> onRowSelected(0, TransactionRow.DATE) |
||||||
|
TransactionRow.DATE -> onRowSelected(0, TransactionRow.COMMENT) |
||||||
|
} |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,4 +1,4 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
package net.pokeranalytics.android.ui.fragment.data |
||||||
|
|
||||||
import android.app.Activity.RESULT_OK |
import android.app.Activity.RESULT_OK |
||||||
import android.content.Intent |
import android.content.Intent |
||||||
@ -1,4 +1,4 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
package net.pokeranalytics.android.ui.fragment.data |
||||||
|
|
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
import android.view.View |
import android.view.View |
||||||
@ -1,4 +1,4 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
package net.pokeranalytics.android.ui.fragment.data |
||||||
|
|
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
import android.view.View |
import android.view.View |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType |
||||||
|
import net.pokeranalytics.android.ui.view.DefaultEditDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
|
enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource { |
||||||
|
COPY_ON_DUPLICATE; |
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
COPY_ON_DUPLICATE -> R.string.copy_on_duplicate |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
COPY_ON_DUPLICATE -> RowViewType.TITLE_SWITCH.ordinal |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val bottomSheetType: BottomSheetType |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
COPY_ON_DUPLICATE -> BottomSheetType.NONE |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue