Refactor BottomSheet with type management

dev_raz_wip
Aurelien Hubert 7 years ago
parent 9a4f194564
commit b33693488d
  1. 2
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDateFragment.kt
  3. 60
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt
  4. 28
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleListFragment.kt
  5. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt
  6. 42
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetListFragment.kt
  7. 0
      app/src/main/res/layout/bottom_sheet_double_edit_text.xml
  8. 0
      app/src/main/res/layout/bottom_sheet_double_list.xml
  9. 13
      app/src/main/res/layout/bottom_sheet_list.xml

@ -54,7 +54,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
BLINDS -> BottomSheetType.LIST
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.DOUBLE_LIST
DATE -> BottomSheetType.DATE
}

@ -6,12 +6,9 @@ import android.view.View
import kotlinx.android.synthetic.main.bottom_sheet_date.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.TimeFrame
class BottomSheetDateFragment : BottomSheetFragment() {
private var timeFrame: TimeFrame = TimeFrame()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
@ -20,7 +17,8 @@ class BottomSheetDateFragment : BottomSheetFragment() {
override fun clickOnCheck() {
super.clickOnCheck()
valueDelegate.setValue(timeFrame, row)
//TODO: Change that
valueDelegate.setValue("", row)
dismiss()
}
@ -29,7 +27,6 @@ class BottomSheetDateFragment : BottomSheetFragment() {
*/
private fun initData() {
val data = getData()
timeFrame = if (data is TimeFrame) data else TimeFrame()
}
/**

@ -0,0 +1,60 @@
package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import kotlinx.android.synthetic.main.bottom_sheet_double_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DisplayableDelegate
class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDelegate {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
}
override fun clickOnCheck() {
super.clickOnCheck()
valueDelegate.setValue("", row)
dismiss()
}
override fun onStart() {
super.onStart()
smallBlind.requestFocus()
}
override fun data(position: Int): DisplayableDataSource {
return Game()
}
override fun onRowSelected(position: Int) {
}
override fun size(): Int {
return 0
}
/**
* Init data
*/
private fun initData() {
val data = getData()
}
/**
* Init UI
*/
private fun initUI() {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_double_edit_text, view?.bottomSheetContainer, true)
}
}

@ -1,23 +1,20 @@
package net.pokeranalytics.android.ui.fragment.components
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.bottom_sheet_game.*
import kotlinx.android.synthetic.main.bottom_sheet_double_list.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.components.DataListAdapter
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DisplayableDelegate
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
class BottomSheetDoubleListFragment : BottomSheetFragment(), DisplayableDelegate {
private var game: Game = Game()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -27,12 +24,14 @@ class BottomSheetDoubleListFragment : BottomSheetFragment(), DisplayableDelegate
override fun clickOnCheck() {
super.clickOnCheck()
valueDelegate.setValue(game, row)
//TODO: Change that
valueDelegate.setValue("", row)
dismiss()
}
override fun data(position: Int): DisplayableDataSource {
return game
//TODO: Change that
return Game()
}
override fun onRowSelected(position: Int) {
@ -47,15 +46,15 @@ class BottomSheetDoubleListFragment : BottomSheetFragment(), DisplayableDelegate
*/
private fun initData() {
val data = getData()
game = if (data is Game) data else Game()
game.title = "Test"
//game = if (data is Game) data else Game()
//game.title = "Test"
}
/**
* Init UI
*/
private fun initUI() {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_game, view?.bottomSheetContainer, true)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_double_list, view?.bottomSheetContainer, true)
val viewManager = LinearLayoutManager(requireContext())
val dataAdapter = DataListAdapter(this, R.layout.row_bottom_sheet_title)
@ -65,17 +64,6 @@ class BottomSheetDoubleListFragment : BottomSheetFragment(), DisplayableDelegate
layoutManager = viewManager
adapter = dataAdapter
}
}
inner class TitleObject(var title: String) : DynamicRowInterface {
override fun localizedTitle(context: Context): String {
return title
}
override var viewType: Int = 0
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
}
}

@ -52,6 +52,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment(), BottomSheetInterfa
BottomSheetType.DATE -> BottomSheetDateFragment()
BottomSheetType.LIST -> BottomSheetListFragment()
BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment()
BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment()
else -> BottomSheetFragment()
}

@ -3,15 +3,16 @@ package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import kotlinx.android.synthetic.main.bottom_sheet_blinds.*
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.bottom_sheet_double_list.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.components.DataListAdapter
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DisplayableDelegate
class BottomSheetListFragment : BottomSheetFragment() {
private var session: Session = Session()
class BottomSheetListFragment : BottomSheetFragment(), DisplayableDelegate {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -21,13 +22,23 @@ class BottomSheetListFragment : BottomSheetFragment() {
override fun clickOnCheck() {
super.clickOnCheck()
valueDelegate.setValue(session, row)
valueDelegate.setValue("", row)
dismiss()
}
override fun onStart() {
super.onStart()
smallBlind.requestFocus()
}
override fun data(position: Int): DisplayableDataSource {
return Game()
}
override fun onRowSelected(position: Int) {
}
override fun size(): Int {
return 0
}
/**
@ -35,7 +46,6 @@ class BottomSheetListFragment : BottomSheetFragment() {
*/
private fun initData() {
val data = getData()
session = if (data is Session) data else Session()
}
/**
@ -43,13 +53,15 @@ class BottomSheetListFragment : BottomSheetFragment() {
*/
private fun initUI() {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_blinds, view?.bottomSheetContainer, true)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_list, view?.bottomSheetContainer, true)
bigBlind.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
clickOnCheck()
}
true
val viewManager = LinearLayoutManager(requireContext())
val dataAdapter = DataListAdapter(this, R.layout.row_bottom_sheet_title)
gameNameRecyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = dataAdapter
}
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/gameNameRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp" />
</LinearLayout>
Loading…
Cancel
Save