parent
8835a7d4d6
commit
e8f83ba08b
@ -0,0 +1,93 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import io.realm.RealmResults |
||||
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
||||
import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException |
||||
import net.pokeranalytics.android.util.UserDefaults |
||||
import java.util.* |
||||
import kotlin.collections.ArrayList |
||||
|
||||
/** |
||||
* An container class to describe the way an field of an object will be edited |
||||
*/ |
||||
|
||||
enum class RowEditableDescriptorType { |
||||
DATE, |
||||
DATA, |
||||
STATIC, |
||||
DEFAULT |
||||
} |
||||
|
||||
open class RowEditableDescriptor(var defaultValue: Any? = null, |
||||
var hint: Int? = null, |
||||
var inputType: Int? = null) |
||||
|
||||
class DateRowEditableDescriptor(date: Date? = null, |
||||
val minimumDate: Date? = null, |
||||
var onlyDate: Boolean = false, |
||||
var onlyTime: Boolean = false): RowEditableDescriptor(defaultValue = date) { |
||||
val date: Date? |
||||
get() { |
||||
return defaultValue as Date? |
||||
} |
||||
} |
||||
|
||||
class DataRowEditableDescriptor( |
||||
defaultValue: Any? = null, |
||||
hint: Int? = null, |
||||
inputType: Int? = null, |
||||
data: RealmResults<*>? = null): RowEditableDescriptor(defaultValue, hint, inputType) { |
||||
|
||||
var data: RealmResults<RowRepresentable>? = null |
||||
|
||||
init { |
||||
if (data != null && data.count() > 0) { |
||||
if (data.first() is RowRepresentable) { |
||||
this.data = data as RealmResults<RowRepresentable>? |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
class StaticDataRowEditableDescriptor( |
||||
defaultValue: Any? = null, |
||||
hint: Int? = null, |
||||
inputType: Int? = null, |
||||
var staticData: List<RowRepresentable>? = null): RowEditableDescriptor(defaultValue, hint, inputType) { |
||||
} |
||||
|
||||
class RowEditableDataSource(customCurrency: Currency? = null) { |
||||
var currency: Currency = UserDefaults.currency |
||||
|
||||
init { |
||||
customCurrency?.let { currency = it } |
||||
} |
||||
|
||||
var descriptors = ArrayList<RowEditableDescriptor>() |
||||
|
||||
fun append(defaultValue: Any? = null, hint: Int? = null, inputType: Int? = null, data: RealmResults<*>? = null, staticData: List<RowRepresentable>? = null) { |
||||
when { |
||||
data != null -> descriptors.add(DataRowEditableDescriptor(defaultValue, hint, inputType, data)) |
||||
staticData != null -> descriptors.add(StaticDataRowEditableDescriptor(defaultValue, hint, inputType, staticData)) |
||||
else -> descriptors.add(RowEditableDescriptor(defaultValue, hint, inputType)) |
||||
} |
||||
} |
||||
|
||||
fun appendDateDescriptor(date:Date?= null, |
||||
minimumDate: Date? = null, |
||||
onlyDate: Boolean = false, |
||||
onlyTime: Boolean = false) { |
||||
descriptors.add(DateRowEditableDescriptor(date, minimumDate, onlyDate, onlyTime)) |
||||
} |
||||
|
||||
val descriptorType: RowEditableDescriptorType |
||||
get() { |
||||
return when (descriptors.firstOrNull()) { |
||||
null -> throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") |
||||
is DateRowEditableDescriptor -> RowEditableDescriptorType.DATE |
||||
is DataRowEditableDescriptor -> RowEditableDescriptorType.DATA |
||||
is StaticDataRowEditableDescriptor -> RowEditableDescriptorType.STATIC |
||||
else -> RowEditableDescriptorType.DEFAULT |
||||
} |
||||
} |
||||
} |
||||
@ -1,25 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import io.realm.RealmResults |
||||
import net.pokeranalytics.android.util.UserDefaults |
||||
import java.util.* |
||||
import kotlin.collections.ArrayList |
||||
|
||||
/** |
||||
* An container class to describe the way an field of an object will be edited |
||||
*/ |
||||
class RowRepresentableEditDescriptor( |
||||
var defaultValue: Any? = null, |
||||
var hint: Int? = null, |
||||
var inputType: Int? = null, |
||||
var data: RealmResults<RowRepresentable>? = null, |
||||
var staticData: List<RowRepresentable>? = null |
||||
) |
||||
|
||||
class RowRepresentableEditData(val currency: Currency = UserDefaults.currency) { |
||||
var descriptors = ArrayList<RowRepresentableEditDescriptor>() |
||||
|
||||
fun append(defaultValue: Any? = null, hint: Int? = null, inputType: Int? = null, data: RealmResults<RowRepresentable>? = null, staticData: List<RowRepresentable>? = null) { |
||||
descriptors.add(RowRepresentableEditDescriptor(defaultValue, hint, inputType, data, staticData)) |
||||
} |
||||
} |
||||
Loading…
Reference in new issue