Update dynamic row delegate

dev_raz_wip
Aurelien Hubert 7 years ago
parent 59349cbce1
commit ab27323e14
  1. 8
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicListAdapter.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/BottomSheetFragment.kt
  3. 12
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  4. 3
      app/src/main/java/net/pokeranalytics/android/util/PokerAnalyticsFragment.kt

@ -4,6 +4,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import io.realm.Realm.init
interface EditableDataDelegate : DynamicRowDelegate {
fun setValue(value: Any, row: DynamicRowInterface)
@ -27,16 +28,13 @@ interface DynamicRowDelegate {
}
interface DynamicRowCallback {
fun onRowSelected(row: DynamicRowInterface)
}
class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class DynamicListAdapter(var delegate: DynamicRowDelegate, var callBackDelegate: DynamicRowCallback? = null) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var rows: ArrayList<DynamicRowInterface> = ArrayList()
private var delegate: DynamicRowDelegate = delegate
var callback: ((row: DynamicRowInterface) -> Unit)? = null
init {
this.rows = delegate.adapterRows()
@ -58,7 +56,7 @@ class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<Re
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val dynamicRow = this.rows[position]
val listener = View.OnClickListener {
callback?.invoke(dynamicRow)
callBackDelegate?.onRowSelected(dynamicRow)
}
(holder as DynamicHolder).bind(dynamicRow, this.delegate, listener)
}

@ -27,10 +27,11 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
super.onStart()
// Open the keyboard
/*
val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
editText.requestFocus()
*/
}
/**
@ -61,7 +62,6 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
*/
fun displayDataForRow() {
}

@ -20,7 +20,7 @@ import net.pokeranalytics.android.ui.adapter.components.DynamicRowCallback
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.util.PokerAnalyticsFragment
class NewSessionFragment : PokerAnalyticsFragment() {
class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback {
private lateinit var newSession: Session
@ -35,6 +35,10 @@ class NewSessionFragment : PokerAnalyticsFragment() {
initUI()
}
override fun onRowSelected(row: DynamicRowInterface) {
val bottomSheetFragment = openBottomSheet(row)
}
private fun initData() {
newSession = Session()
}
@ -45,11 +49,7 @@ class NewSessionFragment : PokerAnalyticsFragment() {
private fun initUI() {
val viewManager = LinearLayoutManager(requireContext())
val newSessionAdapter = DynamicListAdapter(newSession)
newSessionAdapter.callback = {
val bottomSheetFragment = openBottomSheet()
}
val newSessionAdapter = DynamicListAdapter(newSession, this)
recyclerView.apply {
setHasFixedSize(true)

@ -3,6 +3,7 @@ package net.pokeranalytics.android.util
import android.os.Bundle
import androidx.fragment.app.Fragment
import io.realm.Realm
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.ui.fragment.BottomSheetFragment
open class PokerAnalyticsFragment: Fragment() {
@ -26,7 +27,7 @@ open class PokerAnalyticsFragment: Fragment() {
/**
* Open the bottom sheet
*/
fun openBottomSheet(): BottomSheetFragment {
fun openBottomSheet(row: DynamicRowInterface): BottomSheetFragment {
//TODO: Give the data to display in the bottom sheet here
val bottomSheetFragment = BottomSheetFragment()
bottomSheetFragment.show(fragmentManager, "bottomSheet")

Loading…
Cancel
Save