Start bottom sheet customization

dev_raz_wip
Aurelien Hubert 7 years ago
parent 1d8fd2aff5
commit e7d1b1a231
  1. 2
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicListAdapter.kt
  2. 28
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  3. 137
      app/src/main/java/net/pokeranalytics/android/ui/fragment/BottomSheetFragment.kt
  4. 11
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  5. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  6. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetType.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/util/PokerAnalyticsFragment.kt

@ -6,7 +6,7 @@ import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.realm.Realm.init import io.realm.Realm.init
interface EditableDataDelegate : DynamicRowDelegate { interface EditableDataDelegate {
fun setValue(value: Any, row: DynamicRowInterface) fun setValue(value: Any, row: DynamicRowInterface)
} }

@ -2,8 +2,15 @@ package net.pokeranalytics.android.ui.adapter.components
import android.content.Context import android.content.Context
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.BottomSheetType
interface DynamicRowInterface {
fun localizedTitle(context: Context): String
var viewType: Int
var bottomSheetType: BottomSheetType
}
class SectionRow(stringRes: Int) : DynamicRowInterface { class SectionRow(stringRes: Int) : DynamicRowInterface {
var stringRes: Int = stringRes var stringRes: Int = stringRes
@ -13,14 +20,7 @@ class SectionRow(stringRes: Int) : DynamicRowInterface {
} }
override var viewType: Int = 0 override var viewType: Int = 0
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
}
interface DynamicRowInterface {
fun localizedTitle(context: Context): String
var viewType: Int
} }
enum class SessionRow(val resId: Int) : DynamicRowInterface { enum class SessionRow(val resId: Int) : DynamicRowInterface {
@ -39,6 +39,14 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
} }
} }
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
BLINDS -> BottomSheetType.BLINDS
GAME -> BottomSheetType.GAME
DATE -> BottomSheetType.DATE
}
}
} }
enum class BankrollRow(val resId: Int) : DynamicRowInterface { enum class BankrollRow(val resId: Int) : DynamicRowInterface {
@ -51,7 +59,7 @@ enum class BankrollRow(val resId: Int) : DynamicRowInterface {
} }
override var viewType: Int = 1 override var viewType: Int = 1
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
} }
enum class BusinessObjectRowType(val resId: Int) : DynamicRowInterface { enum class BusinessObjectRowType(val resId: Int) : DynamicRowInterface {
@ -66,5 +74,5 @@ enum class BusinessObjectRowType(val resId: Int) : DynamicRowInterface {
} }
override var viewType: Int = RowViewType.TITLE.ordinal override var viewType: Int = RowViewType.TITLE.ordinal
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
} }

@ -1,21 +1,76 @@
package net.pokeranalytics.android.ui.fragment package net.pokeranalytics.android.ui.fragment
import android.app.DatePickerDialog
import android.os.Bundle import android.os.Bundle
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.android.synthetic.main.fragment_bottom_sheet_container.*
import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.view.* import android.view.*
import android.view.inputmethod.InputMethodManager import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.bottom_sheet_blinds.*
import kotlinx.android.synthetic.main.bottom_sheet_date.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.ui.adapter.components.EditableDataDelegate
import net.pokeranalytics.android.ui.fragment.components.BottomSheetType
import timber.log.Timber
import android.widget.DatePicker
import net.pokeranalytics.android.util.DatePickerFragment
import net.pokeranalytics.android.util.TimePickerFragment
import java.util.*
class BottomSheetFragment : BottomSheetDialogFragment() { class BottomSheetFragment : BottomSheetDialogFragment() {
private var row: DynamicRowInterface? = null
private var valueDelegate: EditableDataDelegate? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(
net.pokeranalytics.android.R.layout.fragment_bottom_sheet,
container,
false
) as ConstraintLayout
row?.let {
when (it.bottomSheetType) {
BottomSheetType.BANKROLL -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_bankroll,
view.bottomSheetContainer,
true
)
BottomSheetType.BLINDS -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_blinds,
view.bottomSheetContainer,
true
)
BottomSheetType.DATE -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_date,
view.bottomSheetContainer,
true
)
BottomSheetType.GAME -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_game,
view.bottomSheetContainer,
true
)
BottomSheetType.LOCATION -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_location,
view.bottomSheetContainer,
true
)
BottomSheetType.TABLE_SIZE -> inflater.inflate(
net.pokeranalytics.android.R.layout.bottom_sheet_table_size,
view.bottomSheetContainer,
true
)
else -> {
}
}
}
return inflater.inflate(net.pokeranalytics.android.R.layout.fragment_bottom_sheet_container, container, false) return view
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -23,46 +78,80 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
initUI() initUI()
} }
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
// To display correctly the keyboard
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
}
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
// Open the keyboard // Open the keyboard
/* row?.let {
val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager when (it.bottomSheetType) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) BottomSheetType.BLINDS -> {
editText.requestFocus() smallBlind.requestFocus()
*/ }
else -> {
}
}
}
} }
/**
* Actions:
* - Add / Add ?
* - Clear / Garbage ?
* - Done / Check ?
* -
*/
override fun onDismiss(dialog: DialogInterface?) { override fun onDismiss(dialog: DialogInterface?) {
super.onDismiss(dialog) super.onDismiss(dialog)
val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0) // Return the value
row?.let {
valueDelegate?.setValue("Test", it)
}
} }
/** /**
* Init UI * Init UI
*/ */
private fun initUI() { private fun initUI() {
close.setOnClickListener {
dismiss() row?.let {
//bottomSheetToolbar.title = row?.localizedTitle(requireContext())
bottomSheetToolbar.inflateMenu(net.pokeranalytics.android.R.menu.bottom_sheet_menu)
bottomSheetToolbar.setOnMenuItemClickListener {
false
}
}
row?.let {
when (it.bottomSheetType) {
BottomSheetType.DATE -> initDateUI()
else -> {}
}
} }
} }
/** /**
* * Init date UI
*/ */
fun displayDataForRow() { private fun initDateUI() {
startDate.setOnClickListener {
val dateFragment = DatePickerFragment()
dateFragment.show(fragmentManager, "datePicker")
} }
endDate.setOnClickListener {
val timeFragment = TimePickerFragment()
timeFragment.show(fragmentManager, "timePicker")
}
}
/**
* Init
*/
fun init(row: DynamicRowInterface, valueDelegate: EditableDataDelegate) {
this.row = row
this.valueDelegate = valueDelegate
}
} }

@ -18,9 +18,10 @@ import net.pokeranalytics.android.ui.adapter.NewSessionAdapter
import net.pokeranalytics.android.ui.adapter.components.DynamicListAdapter import net.pokeranalytics.android.ui.adapter.components.DynamicListAdapter
import net.pokeranalytics.android.ui.adapter.components.DynamicRowCallback import net.pokeranalytics.android.ui.adapter.components.DynamicRowCallback
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.ui.adapter.components.EditableDataDelegate
import net.pokeranalytics.android.util.PokerAnalyticsFragment import net.pokeranalytics.android.util.PokerAnalyticsFragment
class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback { class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, EditableDataDelegate {
private lateinit var newSession: Session private lateinit var newSession: Session
@ -30,13 +31,17 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
initData() initData()
initUI() initUI()
} }
override fun onRowSelected(row: DynamicRowInterface) { override fun onRowSelected(row: DynamicRowInterface) {
val bottomSheetFragment = openBottomSheet(row) val bottomSheetFragment = openBottomSheet()
bottomSheetFragment.init(row, this)
}
override fun setValue(value: Any, row: DynamicRowInterface) {
Toast.makeText(requireContext(), "Callback for ${row.localizedTitle(requireContext())} ($value)", Toast.LENGTH_SHORT).show()
} }
private fun initData() { private fun initData() {

@ -45,7 +45,7 @@ class SettingsFragment : PokerAnalyticsFragment(), DynamicRowDelegate, DynamicRo
} }
override fun onRowSelected(row: DynamicRowInterface) { override fun onRowSelected(row: DynamicRowInterface) {
val bottomSheetFragment = openBottomSheet(row) //val bottomSheetFragment = openBottomSheet(row)
} }
/** /**

@ -0,0 +1,13 @@
package net.pokeranalytics.android.ui.fragment.components
enum class BottomSheetType {
NONE,
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
DATE
}

@ -27,8 +27,7 @@ open class PokerAnalyticsFragment: Fragment() {
/** /**
* Open the bottom sheet * Open the bottom sheet
*/ */
fun openBottomSheet(row: DynamicRowInterface): BottomSheetFragment { fun openBottomSheet(): BottomSheetFragment {
//TODO: Give the data to display in the bottom sheet here
val bottomSheetFragment = BottomSheetFragment() val bottomSheetFragment = BottomSheetFragment()
bottomSheetFragment.show(fragmentManager, "bottomSheet") bottomSheetFragment.show(fragmentManager, "bottomSheet")
return bottomSheetFragment return bottomSheetFragment

Loading…
Cancel
Save