Improve and refactor More & Reports fragments

feature/top10
Aurelien Hubert 7 years ago
parent 4b666468c8
commit 0946d3f3db
  1. 17
      app/src/main/java/net/pokeranalytics/android/ui/fragment/MoreFragment.kt
  2. 31
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ReportsFragment.kt
  3. 15
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/ReportRow.kt

@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_stats.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.rowrepresentable.MoreTabRow
import net.pokeranalytics.android.ui.activity.BankrollActivity
import net.pokeranalytics.android.ui.activity.SettingsActivity
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
@ -15,6 +14,7 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.MoreTabRow
class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
@ -29,12 +29,17 @@ class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource,
fragment.arguments = bundle
return fragment
}
val rowRepresentation: List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.addAll(MoreTabRow.values())
rows
}
}
private lateinit var moreAdapter: RowRepresentableAdapter
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList()
// Life Cycle
@ -50,7 +55,7 @@ class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource,
// Rows
override fun adapterRows(): List<RowRepresentable>? {
return rowRepresentables
return rowRepresentation
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
@ -67,8 +72,6 @@ class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource,
* Init data
*/
private fun initData() {
rowRepresentables.addAll(MoreTabRow.values())
moreAdapter = RowRepresentableAdapter(this, this)
}
/**
@ -76,6 +79,8 @@ class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource,
*/
private fun initUI() {
moreAdapter = RowRepresentableAdapter(this, this)
val viewManager = LinearLayoutManager(requireContext())
recyclerView.apply {

@ -7,9 +7,14 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_stats.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.ReportRow
class ReportsFragment : PokerAnalyticsFragment() {
class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
companion object {
@ -22,9 +27,18 @@ class ReportsFragment : PokerAnalyticsFragment() {
fragment.arguments = bundle
return fragment
}
val rowRepresentation: List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.addAll(ReportRow.getRows())
rows
}
}
// Life Cycle
private lateinit var reportsAdapter: RowRepresentableAdapter
// Life Cycle
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_reports, container, false)
@ -36,14 +50,19 @@ class ReportsFragment : PokerAnalyticsFragment() {
initUI()
}
// Rows
override fun adapterRows(): List<RowRepresentable>? {
return rowRepresentation
}
// Business
// Business
/**
* Init data
*/
private fun initData() {
}
/**
@ -51,12 +70,14 @@ class ReportsFragment : PokerAnalyticsFragment() {
*/
private fun initUI() {
reportsAdapter = RowRepresentableAdapter(this, this)
val viewManager = LinearLayoutManager(requireContext())
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
//adapter = statsAdapter
adapter = reportsAdapter
}
}

@ -17,9 +17,22 @@ enum class ReportRow : RowRepresentable {
TOURNAMENT_TYPES,
VARIANT;
companion object {
/**
* Return the report rows
*/
fun getRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.comparison))
rows.addAll(values())
return rows
}
}
override val resId: Int?
get() {
return when(this) {
return when (this) {
BLINDS -> R.string.blinds
BUY_IN -> R.string.buyin
DAY_OF_WEEKS -> R.string.day_of_the_week

Loading…
Cancel
Save