Improve Calendar Details

feature/top10
Aurelien Hubert 7 years ago
parent 48a7102d8a
commit c0ce9d016d
  1. 6
      app/src/main/java/net/pokeranalytics/android/ui/activity/CalendarDetailsActivity.kt
  2. 78
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CalendarDetailsFragment.kt
  3. 24
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt

@ -17,7 +17,7 @@ class CalendarDetailsActivity : PokerAnalyticsActivity() {
var computedResults: ComputedResults? = null
var sessionTypeCondition: QueryCondition? = null
var title: String? = null
var detailsTitle: String? = null
/**
* Default constructor
@ -25,7 +25,7 @@ class CalendarDetailsActivity : PokerAnalyticsActivity() {
fun newInstance(context: Context, computedResults: ComputedResults, sessionTypeCondition: QueryCondition?, title: String?) {
this.computedResults = computedResults
this.sessionTypeCondition = sessionTypeCondition
this.title = title
this.detailsTitle = title
val intent = Intent(context, CalendarDetailsActivity::class.java)
context.startActivity(intent)
}
@ -44,7 +44,7 @@ class CalendarDetailsActivity : PokerAnalyticsActivity() {
private fun initUI() {
val calendarDetailsFragment = calendarDetailsFragment as CalendarDetailsFragment
calendarDetailsFragment.setData(computedResults, sessionTypeCondition)
calendarDetailsFragment.setData(computedResults, sessionTypeCondition, detailsTitle)
}

@ -19,11 +19,11 @@ import net.pokeranalytics.android.calculus.ComputedResults
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.comparison.Comparator
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.ui.activity.CalendarDetailsActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
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.extensions.toast
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
@ -46,6 +46,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
private lateinit var parentActivity: PokerAnalyticsActivity
private lateinit var statsAdapter: RowRepresentableAdapter
private var title: String? = ""
private var computedResults: ComputedResults? = null
private var sessionTypeCondition: QueryCondition? = null
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList()
@ -59,9 +60,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
launchStatComputation()
}
override fun adapterRows(): List<RowRepresentable>? {
@ -69,24 +68,14 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when(row) {
when (row) {
is GraphRow -> {
//TODO: Open graph details
toast("Open graph details")
}
}
}
/**
* Init data
*/
private fun initData() {
Timber.d("initData")
this.computedResults = CalendarDetailsActivity.computedResults
this.sessionTypeCondition = CalendarDetailsActivity.sessionTypeCondition
}
/**
* Init UI
*/
@ -101,11 +90,10 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
setHasOptionsMenu(true)
toolbar.title = CalendarDetailsActivity.title
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
when(tab.position) {
when (tab.position) {
0 -> sessionTypeCondition = null
1 -> sessionTypeCondition = QueryCondition.CASH
2 -> sessionTypeCondition = QueryCondition.TOURNAMENT
@ -120,15 +108,6 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
}
})
sessionTypeCondition?.let {
when(it) {
QueryCondition.CASH -> tabs.getTabAt(1)?.select()
QueryCondition.TOURNAMENT -> tabs.getTabAt(2)?.select()
else -> tabs.getTabAt(0)?.select()
}
}
statsAdapter = RowRepresentableAdapter(this, this)
val viewManager = LinearLayoutManager(requireContext())
@ -142,7 +121,26 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
}
/**
*
* Display data
*/
private fun displayData() {
title?.let {
toolbar.title = it
}
sessionTypeCondition?.let {
when (it) {
QueryCondition.CASH -> tabs.getTabAt(1)?.select()
QueryCondition.TOURNAMENT -> tabs.getTabAt(2)?.select()
else -> tabs.getTabAt(0)?.select()
}
}
}
/**
* Launch stat computation
*/
private fun launchStatComputation() {
@ -166,18 +164,22 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
Timber.d("Report take: ${System.currentTimeMillis() - startDate.time}ms")
report.results.firstOrNull()?.let {
rowRepresentables.clear()
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.net_result))
rowRepresentables.add(GraphRow(report, Stat.NETRESULT))
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.NETRESULT), computedResults.computedStat(Stat.HOURLY_RATE)))
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.LOCATIONS_PLAYED), computedResults.computedStat(Stat.LONGEST_STREAKS)))
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.NETRESULT), it.computedStat(Stat.HOURLY_RATE)))
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.LOCATIONS_PLAYED), it.computedStat(Stat.LONGEST_STREAKS)))
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.distribution))
rowRepresentables.add(GraphRow(report, Stat.NETRESULT))
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.WIN_RATIO), computedResults.computedStat(Stat.MAXIMUM_NETRESULT)))
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.WIN_RATIO), it.computedStat(Stat.MAXIMUM_NETRESULT)))
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.volume))
rowRepresentables.add(GraphRow(report, Stat.NETRESULT))
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DURATION), computedResults.computedStat(Stat.AVERAGE_DURATION)))
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DAYS_PLAYED), computedResults.computedStat(Stat.MAXIMUM_DURATION)))
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.DURATION), it.computedStat(Stat.AVERAGE_DURATION)))
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.DAYS_PLAYED), it.computedStat(Stat.MAXIMUM_DURATION)))
}
launch(Dispatchers.Main) {
statsAdapter.notifyDataSetChanged()
@ -189,10 +191,16 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
/**
* Set data
*/
fun setData(computedResults: ComputedResults?, sessionTypeCondition: QueryCondition?) {
fun setData(computedResults: ComputedResults?, sessionTypeCondition: QueryCondition?, title: String?) {
Timber.d("Set data")
//this.stat = stat
//this.entries = entries
this.computedResults = computedResults
this.sessionTypeCondition = sessionTypeCondition
this.title = title
displayData()
launchStatComputation()
}
}

@ -28,7 +28,6 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepres
import net.pokeranalytics.android.ui.view.rowrepresentable.GraphRow
import net.pokeranalytics.android.ui.view.rowrepresentable.StatDoubleRow
import net.pokeranalytics.android.ui.view.rowrepresentable.StatRow
import timber.log.Timber
/**
* An interface used to factor the configuration of RecyclerView.ViewHolder
@ -176,7 +175,7 @@ enum class RowViewType(private var layoutRes: Int) {
}
// Icon
itemView.findViewById<AppCompatImageView>(R.id.icon)?.let { imageView ->
itemView.findViewById<AppCompatImageView?>(R.id.icon)?.let { imageView ->
row.imageRes?.let { imageRes ->
imageView.setImageResource(imageRes)
}
@ -218,16 +217,16 @@ enum class RowViewType(private var layoutRes: Int) {
*/
inner class RowFollowUsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
itemView.findViewById<AppCompatImageView>(R.id.icon1).setOnClickListener {
itemView.findViewById<AppCompatImageView?>(R.id.icon1)?.setOnClickListener {
adapter.delegate?.onRowSelected(0, row)
}
itemView.findViewById<AppCompatImageView>(R.id.icon2).setOnClickListener {
itemView.findViewById<AppCompatImageView?>(R.id.icon2)?.setOnClickListener {
adapter.delegate?.onRowSelected(1, row)
}
itemView.findViewById<AppCompatImageView>(R.id.icon3).setOnClickListener {
itemView.findViewById<AppCompatImageView?>(R.id.icon3)?.setOnClickListener {
adapter.delegate?.onRowSelected(2, row)
}
itemView.findViewById<AppCompatImageView>(R.id.icon4).setOnClickListener {
itemView.findViewById<AppCompatImageView?>(R.id.icon4)?.setOnClickListener {
adapter.delegate?.onRowSelected(3, row)
}
}
@ -269,12 +268,7 @@ enum class RowViewType(private var layoutRes: Int) {
BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
if (row is StatDoubleRow) {
Timber.d("${row}")
Timber.d("${row.computedStat1}")
Timber.d("${row.computedStat2}")
// Stat 1
itemView.findViewById<AppCompatTextView?>(R.id.stat1Name)?.let { view ->
@ -351,25 +345,23 @@ enum class RowViewType(private var layoutRes: Int) {
}
}
itemView.findViewById<FrameLayout>(R.id.chartContainer)?.let {
itemView.findViewById<FrameLayout?>(R.id.chartContainer)?.let {
it.removeAllViews()
it.addView(chartView)
}
chartView.setStyle(false, context)
//chartView.setOnChartValueSelectedListener(this)
chartView.setTouchEnabled(false)
chartView.highlightValue((entries.size - 1).toFloat(), 0)
}
}
// Listener
val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, row)
}
itemView.findViewById<View?>(R.id.container)?.setOnClickListener(listener)
itemView.findViewById<FrameLayout?>(R.id.chartContainer)?.setOnClickListener(listener)
}
}

Loading…
Cancel
Save