|
|
|
|
@ -10,18 +10,16 @@ import kotlinx.android.synthetic.main.bottom_sheet_game_list.* |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.LiveRowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Bottom Sheet List Game Fragment |
|
|
|
|
* Display a list of game + chips to choose the game limit |
|
|
|
|
*/ |
|
|
|
|
class BottomSheetListGameFragment : BottomSheetListFragment() { |
|
|
|
|
|
|
|
|
|
class BottomSheetListGameFragment : BottomSheetFragment(), LiveRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
private var limit: Int = -1 |
|
|
|
|
private var realmData: RealmResults<*>? = null |
|
|
|
|
private lateinit var dataAdapter: RowRepresentableAdapter |
|
|
|
|
private var limit: Int? = 0 |
|
|
|
|
private val values = ArrayList<Any?>() |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
@ -30,40 +28,10 @@ class BottomSheetListGameFragment : BottomSheetFragment(), LiveRowRepresentableD |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onResume() { |
|
|
|
|
super.onResume() |
|
|
|
|
dataAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getValue(): Any? { |
|
|
|
|
return values |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
|
|
|
|
realmData?.let { |
|
|
|
|
return it[position] as RowRepresentable |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun numberOfRows(): Int { |
|
|
|
|
realmData?.let { |
|
|
|
|
return it.size |
|
|
|
|
} |
|
|
|
|
return 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun viewTypeForPosition(position: Int): Int { |
|
|
|
|
return RowViewType.BOTTOM_SHEET_DATA.ordinal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun indexForRow(row: RowRepresentable): Int { |
|
|
|
|
realmData?.let { |
|
|
|
|
return it.indexOf(row) |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
realmData?.let { |
|
|
|
|
val selectedData = it[position] |
|
|
|
|
@ -73,16 +41,15 @@ class BottomSheetListGameFragment : BottomSheetFragment(), LiveRowRepresentableD |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
super.onRowSelected(position, row, fromAction) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init data |
|
|
|
|
*/ |
|
|
|
|
private fun initData() { |
|
|
|
|
override fun initData() { |
|
|
|
|
val bottomSheetData = getData() |
|
|
|
|
if (bottomSheetData.isNotEmpty() && bottomSheetData.size >= 2 && bottomSheetData[1].data != null) { |
|
|
|
|
this.limit = bottomSheetData[0].defaultValue as Int? ?: -1 |
|
|
|
|
this.limit = bottomSheetData[0].defaultValue as Int? |
|
|
|
|
this.realmData = bottomSheetData[1].data as RealmResults<*> |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -90,18 +57,18 @@ class BottomSheetListGameFragment : BottomSheetFragment(), LiveRowRepresentableD |
|
|
|
|
/** |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
override fun initUI() { |
|
|
|
|
|
|
|
|
|
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_game_list, view?.bottomSheetContainer, true) |
|
|
|
|
|
|
|
|
|
values.add(0, if (limit == -1) null else limit) |
|
|
|
|
values.add(0, limit) |
|
|
|
|
values.add(1, null) |
|
|
|
|
|
|
|
|
|
chipGroup.removeAllViews() |
|
|
|
|
Limit.values().forEach { |
|
|
|
|
val chip = Chip(requireContext()) |
|
|
|
|
chip.text = it.shortName |
|
|
|
|
chip.id = it.ordinal |
|
|
|
|
chip.text = it.shortName |
|
|
|
|
chip.isChecked = it.ordinal == limit |
|
|
|
|
chipGroup.addView(chip) |
|
|
|
|
} |
|
|
|
|
|