Add delete action for BottomSheet

dev
Aurelien Hubert 7 years ago
parent a23f23fb7c
commit 3b077e693f
  1. 1
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableAdapter.kt
  2. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  3. 10
      app/src/main/res/menu/toolbar_bottom_sheet.xml

@ -10,6 +10,7 @@ import net.pokeranalytics.android.ui.view.RowViewType
interface RowRepresentableDelegate { interface RowRepresentableDelegate {
fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean = false) {} fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean = false) {}
fun onRowValueChanged(value: Any?, row: RowRepresentable) {} fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
fun onRowDeleted(row: RowRepresentable) {}
} }
/** /**

@ -32,6 +32,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
var currentCurrency: Currency? = null var currentCurrency: Currency? = null
private var isClearable: Boolean = true private var isClearable: Boolean = true
private var isDeletable: Boolean = false
private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>? = null private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>? = null
companion object { companion object {
@ -44,7 +45,8 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
delegate: RowRepresentableDelegate, delegate: RowRepresentableDelegate,
rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>?, rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>?,
isClearable: Boolean? = true, isClearable: Boolean? = true,
currentCurrency: Currency? = null currentCurrency: Currency? = null,
isDeletable: Boolean? = false
): BottomSheetFragment { ): BottomSheetFragment {
val bottomSheetFragment = row.bottomSheetType.newInstance() val bottomSheetFragment = row.bottomSheetType.newInstance()
bottomSheetFragment.show(fragmentManager, "bottomSheet") bottomSheetFragment.show(fragmentManager, "bottomSheet")
@ -52,6 +54,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
bottomSheetFragment.delegate = delegate bottomSheetFragment.delegate = delegate
bottomSheetFragment.rowRepresentableEditDescriptors = rowRepresentableEditDescriptors bottomSheetFragment.rowRepresentableEditDescriptors = rowRepresentableEditDescriptors
bottomSheetFragment.isClearable = isClearable ?: true bottomSheetFragment.isClearable = isClearable ?: true
bottomSheetFragment.isDeletable = isDeletable ?: true
bottomSheetFragment.currentCurrency = currentCurrency bottomSheetFragment.currentCurrency = currentCurrency
return bottomSheetFragment return bottomSheetFragment
} }
@ -111,6 +114,13 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
dismiss() dismiss()
true true
} }
bottomSheetToolbar.menu.findItem(R.id.actionDelete).setOnMenuItemClickListener {
delegate.onRowDeleted(row)
dismiss()
true
}
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener { bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener {
when (row) { when (row) {
SessionRow.GAME -> EditableDataActivity.newInstanceForResult( SessionRow.GAME -> EditableDataActivity.newInstanceForResult(
@ -153,6 +163,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
} }
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = isClearable bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = isClearable
bottomSheetToolbar.menu.findItem(R.id.actionDelete).isVisible = isDeletable
} }
} }

@ -2,11 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/actionDelete"
android:icon="@drawable/ic_outline_delete"
android:orderInCategory="0"
android:title="@string/delete"
android:visible="false"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/actionClear" android:id="@+id/actionClear"
android:icon="@drawable/ic_baseline_not_interested"
android:orderInCategory="100" android:orderInCategory="100"
android:title="@string/clear" android:title="@string/clear"
android:icon="@drawable/ic_baseline_not_interested"
app:showAsAction="always" /> app:showAsAction="always" />
<item <item
android:id="@+id/actionAdd" android:id="@+id/actionAdd"
@ -20,4 +27,5 @@
android:orderInCategory="300" android:orderInCategory="300"
android:title="@string/done" android:title="@string/done"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
</menu> </menu>
Loading…
Cancel
Save