|
|
|
@ -42,6 +42,23 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
|
|
|
|
|
|
|
const val REQUEST_CODE_ADD_NEW_OBJECT = 100 |
|
|
|
const val REQUEST_CODE_ADD_NEW_OBJECT = 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun newInstance(bottomSheetType: BottomSheetType): BottomSheetFragment { |
|
|
|
|
|
|
|
return when (bottomSheetType) { |
|
|
|
|
|
|
|
BottomSheetType.NONE -> BottomSheetFragment() |
|
|
|
|
|
|
|
BottomSheetType.LIST -> BottomSheetListFragment() |
|
|
|
|
|
|
|
BottomSheetType.LIST_STATIC -> BottomSheetStaticListFragment() |
|
|
|
|
|
|
|
BottomSheetType.LIST_GAME -> BottomSheetListGameFragment() |
|
|
|
|
|
|
|
BottomSheetType.DOUBLE_LIST -> BottomSheetListGameFragment() |
|
|
|
|
|
|
|
BottomSheetType.MULTI_SELECTION -> BottomSheetMultiSelectionFragment() |
|
|
|
|
|
|
|
BottomSheetType.GRID -> BottomSheetTableSizeGridFragment() |
|
|
|
|
|
|
|
BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment() |
|
|
|
|
|
|
|
BottomSheetType.EDIT_TEXT_MULTI_LINES -> BottomSheetEditTextMultiLinesFragment() |
|
|
|
|
|
|
|
BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment() |
|
|
|
|
|
|
|
BottomSheetType.NUMERIC_TEXT -> BottomSheetNumericTextFragment() |
|
|
|
|
|
|
|
BottomSheetType.SUM -> BottomSheetSumFragment() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun create( |
|
|
|
fun create( |
|
|
|
fragmentManager: FragmentManager?, |
|
|
|
fragmentManager: FragmentManager?, |
|
|
|
row: RowRepresentable, |
|
|
|
row: RowRepresentable, |
|
|
|
@ -52,7 +69,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
isDeletable: Boolean? = false, |
|
|
|
isDeletable: Boolean? = false, |
|
|
|
valueHasPlaceholder: Boolean? = null |
|
|
|
valueHasPlaceholder: Boolean? = null |
|
|
|
): BottomSheetFragment { |
|
|
|
): BottomSheetFragment { |
|
|
|
val bottomSheetFragment = row.bottomSheetType.newInstance() |
|
|
|
val bottomSheetFragment = newInstance(row.bottomSheetType) |
|
|
|
bottomSheetFragment.show(fragmentManager, "bottomSheet") |
|
|
|
bottomSheetFragment.show(fragmentManager, "bottomSheet") |
|
|
|
bottomSheetFragment.row = row |
|
|
|
bottomSheetFragment.row = row |
|
|
|
bottomSheetFragment.delegate = delegate |
|
|
|
bottomSheetFragment.delegate = delegate |
|
|
|
@ -76,7 +93,6 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
|
|
|
|
@ -103,57 +119,57 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
* Init UI |
|
|
|
* Init UI |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initUI() { |
|
|
|
private fun initUI() { |
|
|
|
row.let { |
|
|
|
|
|
|
|
bottomSheetToolbar.title = row.localizedTitle(requireContext()) |
|
|
|
|
|
|
|
bottomSheetToolbar.inflateMenu(R.menu.toolbar_bottom_sheet) |
|
|
|
|
|
|
|
bottomSheetToolbar.setOnMenuItemClickListener { |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).isVisible = row.bottomSheetType.validationRequired |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = row.bottomSheetType.clearRequired |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionAdd).isVisible = row.bottomSheetType.addRequired |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Menu |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener { |
|
|
|
|
|
|
|
delegate.onRowValueChanged(null, row) |
|
|
|
|
|
|
|
dismiss() |
|
|
|
|
|
|
|
true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).setOnMenuItemClickListener { |
|
|
|
bottomSheetToolbar.title = row.localizedTitle(requireContext()) |
|
|
|
delegate.onRowDeleted(row) |
|
|
|
bottomSheetToolbar.inflateMenu(R.menu.toolbar_bottom_sheet) |
|
|
|
dismiss() |
|
|
|
bottomSheetToolbar.setOnMenuItemClickListener { |
|
|
|
true |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).isVisible = row.bottomSheetType.validationRequired |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = row.bottomSheetType.clearRequired |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionAdd).isVisible = row.bottomSheetType.addRequired |
|
|
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener { |
|
|
|
// Menu |
|
|
|
val liveData = when (row) { |
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener { |
|
|
|
SessionRow.GAME -> LiveData.GAME |
|
|
|
delegate.onRowValueChanged(null, row) |
|
|
|
SessionRow.BANKROLL, TransactionRow.BANKROLL -> LiveData.BANKROLL |
|
|
|
dismiss() |
|
|
|
SessionRow.LOCATION -> LiveData.LOCATION |
|
|
|
true |
|
|
|
SessionRow.TOURNAMENT_NAME -> LiveData.TOURNAMENT_NAME |
|
|
|
} |
|
|
|
SessionRow.TOURNAMENT_FEATURE -> LiveData.TOURNAMENT_FEATURE |
|
|
|
|
|
|
|
TransactionRow.TYPE -> LiveData.TRANSACTION_TYPE |
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).setOnMenuItemClickListener { |
|
|
|
else -> throw PAIllegalStateException("row $row does not have an associated LiveData value") |
|
|
|
delegate.onRowDeleted(row) |
|
|
|
} |
|
|
|
dismiss() |
|
|
|
|
|
|
|
true |
|
|
|
EditableDataActivity.newInstanceForResult( |
|
|
|
} |
|
|
|
this, |
|
|
|
|
|
|
|
liveData, |
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener { |
|
|
|
requestCode = REQUEST_CODE_ADD_NEW_OBJECT |
|
|
|
val liveData = when (row) { |
|
|
|
) |
|
|
|
SessionRow.GAME -> LiveData.GAME |
|
|
|
|
|
|
|
SessionRow.BANKROLL, TransactionRow.BANKROLL -> LiveData.BANKROLL |
|
|
|
true |
|
|
|
SessionRow.LOCATION -> LiveData.LOCATION |
|
|
|
} |
|
|
|
SessionRow.TOURNAMENT_NAME -> LiveData.TOURNAMENT_NAME |
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener { |
|
|
|
SessionRow.TOURNAMENT_FEATURE -> LiveData.TOURNAMENT_FEATURE |
|
|
|
this.delegate.onRowValueChanged(getValue(), row) |
|
|
|
TransactionRow.TYPE -> LiveData.TRANSACTION_TYPE |
|
|
|
dismiss() |
|
|
|
else -> throw PAIllegalStateException("row $row does not have an associated LiveData value") |
|
|
|
true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = isClearable |
|
|
|
EditableDataActivity.newInstanceForResult( |
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).isVisible = isDeletable |
|
|
|
this, |
|
|
|
|
|
|
|
liveData, |
|
|
|
|
|
|
|
requestCode = REQUEST_CODE_ADD_NEW_OBJECT |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener { |
|
|
|
|
|
|
|
this.delegate.onRowValueChanged(getValue(), row) |
|
|
|
|
|
|
|
dismiss() |
|
|
|
|
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = isClearable |
|
|
|
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionDelete).isVisible = isDeletable |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|