|
|
|
|
@ -19,6 +19,7 @@ import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.BaseActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
|
|
|
|
@ -35,9 +36,7 @@ class BottomSheetConfig(var row: RowRepresentable, |
|
|
|
|
var isDeletable: Boolean? = false, |
|
|
|
|
var valueHasPlaceholder: Boolean? = null, |
|
|
|
|
var alternativeLabels: Boolean = false |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
|
|
|
|
|
@ -48,6 +47,10 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
ViewModelProviders.of(this).get(BottomSheetViewModel::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var delegate: RowRepresentableDelegate? = null |
|
|
|
|
|
|
|
|
|
protected lateinit var dataAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
private var config: BottomSheetConfig? = null |
|
|
|
|
@ -111,7 +114,6 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
private fun configure(configuration: BottomSheetConfig) { |
|
|
|
|
|
|
|
|
|
this.viewModel.row = configuration.row |
|
|
|
|
this.viewModel.delegate = configuration.delegate |
|
|
|
|
this.viewModel.rowRepresentableEditDescriptors = configuration.rowRepresentableEditDescriptors |
|
|
|
|
this.viewModel.isClearable = configuration.isClearable ?: true |
|
|
|
|
this.viewModel.currentCurrency = configuration.currentCurrency |
|
|
|
|
@ -119,6 +121,8 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false |
|
|
|
|
this.viewModel.alternativeLabels = configuration.alternativeLabels |
|
|
|
|
|
|
|
|
|
this.delegate = configuration.delegate |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
@ -132,7 +136,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
val pokerAnalyticsActivity = activity as BaseActivity |
|
|
|
|
val liveDataType = LiveData.values()[dataType] |
|
|
|
|
this.viewModel.addedData = liveDataType.getData(pokerAnalyticsActivity.getRealm(), primaryKey) |
|
|
|
|
this.viewModel.onRowValueChanged() |
|
|
|
|
this.onRowValueChanged() |
|
|
|
|
// this.delegate.onRowValueChanged(proxyItem, this.row) |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
@ -161,14 +165,14 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
|
|
|
|
|
// Menu |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener { |
|
|
|
|
this.viewModel.onClear() |
|
|
|
|
this.onClear() |
|
|
|
|
// delegate.onRowValueChanged(null, row) |
|
|
|
|
dismiss() |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).setOnMenuItemClickListener { |
|
|
|
|
this.viewModel.onRowDeleted() |
|
|
|
|
this.onRowDeleted() |
|
|
|
|
// delegate.onRowDeleted(row) |
|
|
|
|
dismiss() |
|
|
|
|
true |
|
|
|
|
@ -194,7 +198,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener { |
|
|
|
|
this.viewModel.onRowValueChanged() |
|
|
|
|
this.onRowValueChanged() |
|
|
|
|
// this.delegate.onRowValueChanged(getValue(), row) |
|
|
|
|
dismiss() |
|
|
|
|
true |
|
|
|
|
@ -216,4 +220,44 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
return this.viewModel.getValue() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun onClear() { |
|
|
|
|
this.delegate?.onRowValueChanged(null, this.viewModel.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowValueChanged() { |
|
|
|
|
|
|
|
|
|
val row = this.viewModel.row |
|
|
|
|
|
|
|
|
|
// if some data has been added |
|
|
|
|
this.viewModel.addedData?.let { |
|
|
|
|
this.delegate?.onRowValueChanged(it, row) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val value = this.viewModel.changedValue() |
|
|
|
|
this.delegate?.onRowValueChanged(value, row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun onRowDeleted() { |
|
|
|
|
this.delegate?.onRowDeleted(this.viewModel.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowSelected(row: RowRepresentable) { |
|
|
|
|
this.viewModel.rowSelected(row) |
|
|
|
|
this.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onRowSelected(position: Int) { |
|
|
|
|
val value = this.viewModel.rowSelected(position) |
|
|
|
|
this.delegate?.onRowValueChanged(value, this.viewModel.row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun notifyDataSetChanged() { |
|
|
|
|
this.dataAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun refreshRow(row: RowRepresentable) { |
|
|
|
|
this.dataAdapter.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |