|
|
|
|
@ -43,7 +43,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
/** |
|
|
|
|
* A view model used to store potential bottom sheet values |
|
|
|
|
*/ |
|
|
|
|
protected val viewModel: BottomSheetViewModel by lazy { |
|
|
|
|
protected val model: BottomSheetViewModel by lazy { |
|
|
|
|
ViewModelProviders.of(this).get(BottomSheetViewModel::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -107,19 +107,19 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
config = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.viewModel.load() |
|
|
|
|
this.model.load() |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun configure(configuration: BottomSheetConfig) { |
|
|
|
|
|
|
|
|
|
this.viewModel.row = configuration.row |
|
|
|
|
this.viewModel.rowRepresentableEditDescriptors = configuration.rowRepresentableEditDescriptors |
|
|
|
|
this.viewModel.isClearable = configuration.isClearable ?: true |
|
|
|
|
this.viewModel.currentCurrency = configuration.currentCurrency |
|
|
|
|
this.viewModel.isDeletable = configuration.isDeletable ?: false |
|
|
|
|
this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false |
|
|
|
|
this.viewModel.alternativeLabels = configuration.alternativeLabels |
|
|
|
|
this.model.row = configuration.row |
|
|
|
|
this.model.rowRepresentableEditDescriptors = configuration.rowRepresentableEditDescriptors |
|
|
|
|
this.model.isClearable = configuration.isClearable ?: true |
|
|
|
|
this.model.currentCurrency = configuration.currentCurrency |
|
|
|
|
this.model.isDeletable = configuration.isDeletable ?: false |
|
|
|
|
this.model.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false |
|
|
|
|
this.model.alternativeLabels = configuration.alternativeLabels |
|
|
|
|
|
|
|
|
|
this.delegate = configuration.delegate |
|
|
|
|
|
|
|
|
|
@ -135,7 +135,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
val primaryKey = data.getStringExtra(EditableDataActivity.IntentKey.PRIMARY_KEY.keyName) |
|
|
|
|
val pokerAnalyticsActivity = activity as BaseActivity |
|
|
|
|
val liveDataType = LiveData.values()[dataType] |
|
|
|
|
this.viewModel.addedData = liveDataType.getData(pokerAnalyticsActivity.getRealm(), primaryKey) |
|
|
|
|
this.model.addedData = liveDataType.getData(pokerAnalyticsActivity.getRealm(), primaryKey) |
|
|
|
|
this.onRowValueChanged() |
|
|
|
|
// this.delegate.onRowValueChanged(proxyItem, this.row) |
|
|
|
|
dismiss() |
|
|
|
|
@ -153,7 +153,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
val row = this.viewModel.row |
|
|
|
|
val row = this.model.row |
|
|
|
|
bottomSheetToolbar.title = row.localizedTitle(requireContext()) |
|
|
|
|
bottomSheetToolbar.inflateMenu(R.menu.toolbar_bottom_sheet) |
|
|
|
|
bottomSheetToolbar.setOnMenuItemClickListener { |
|
|
|
|
@ -204,8 +204,8 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = this.viewModel.isClearable |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).isVisible = this.viewModel.isDeletable |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = this.model.isClearable |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).isVisible = this.model.isDeletable |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -213,43 +213,43 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
* Return the data list |
|
|
|
|
*/ |
|
|
|
|
fun getDescriptors(): List<RowRepresentableEditDescriptor>? { |
|
|
|
|
return this.viewModel.rowRepresentableEditDescriptors |
|
|
|
|
return this.model.rowRepresentableEditDescriptors |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getValue(): Any? { |
|
|
|
|
return this.viewModel.getValue() |
|
|
|
|
return this.model.getValue() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun onClear() { |
|
|
|
|
this.delegate?.onRowValueChanged(null, this.viewModel.row) |
|
|
|
|
this.delegate?.onRowValueChanged(null, this.model.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowValueChanged() { |
|
|
|
|
|
|
|
|
|
val row = this.viewModel.row |
|
|
|
|
val row = this.model.row |
|
|
|
|
|
|
|
|
|
// if some data has been added |
|
|
|
|
this.viewModel.addedData?.let { |
|
|
|
|
this.model.addedData?.let { |
|
|
|
|
this.delegate?.onRowValueChanged(it, row) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val value = this.viewModel.changedValue() |
|
|
|
|
val value = this.model.changedValue() |
|
|
|
|
this.delegate?.onRowValueChanged(value, row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun onRowDeleted() { |
|
|
|
|
this.delegate?.onRowDeleted(this.viewModel.row) |
|
|
|
|
this.delegate?.onRowDeleted(this.model.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowSelected(row: RowRepresentable) { |
|
|
|
|
this.viewModel.rowSelected(row) |
|
|
|
|
this.model.rowSelected(row) |
|
|
|
|
this.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowSelected(position: Int) { |
|
|
|
|
val value = this.viewModel.rowSelected(position) |
|
|
|
|
this.delegate?.onRowValueChanged(value, this.viewModel.row) |
|
|
|
|
val value = this.model.rowSelected(position) |
|
|
|
|
this.delegate?.onRowValueChanged(value, this.model.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun notifyDataSetChanged() { |
|
|
|
|
|