Factorize code + cleanup

dev
Laurent 7 years ago
parent f290b21a31
commit 6124358f0c
  1. 7
      app/src/main/java/net/pokeranalytics/android/ui/activity/ProgressReportActivity.kt
  2. 37
      app/src/main/java/net/pokeranalytics/android/ui/activity/TableReportActivity.kt
  3. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CalendarDetailsFragment.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ReportsFragment.kt
  5. 11
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/AbstractReportFragment.kt
  6. 18
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/ComparisonReportFragment.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/ComposableTableReportFragment.kt
  8. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/ProgressReportFragment.kt
  9. 16
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/TableReportFragment.kt

@ -12,7 +12,7 @@ import net.pokeranalytics.android.ui.activity.components.ReportActivity
import net.pokeranalytics.android.ui.fragment.report.ProgressReportFragment import net.pokeranalytics.android.ui.fragment.report.ProgressReportFragment
class StatisticsDetailsParameters(var stat: Stat, var report: Report, var title: String? = null) class StatisticsDetailsParameters(var stat: Stat, var report: Report, var title: String)
class ProgressReportActivity : PokerAnalyticsActivity() { class ProgressReportActivity : PokerAnalyticsActivity() {
@ -25,14 +25,14 @@ class ProgressReportActivity : PokerAnalyticsActivity() {
/** /**
* Default constructor * Default constructor
*/ */
fun newInstance(context: Context, stat: Stat, report: Report, displayAggregationChoices: Boolean = true, title: String? = null) { fun newInstance(context: Context, stat: Stat, report: Report, displayAggregationChoices: Boolean = true, title: String) {
this.parameters = StatisticsDetailsParameters(stat, report, title) this.parameters = StatisticsDetailsParameters(stat, report, title)
this.displayAggregationChoices = displayAggregationChoices this.displayAggregationChoices = displayAggregationChoices
val intent = Intent(context, ProgressReportActivity::class.java) val intent = Intent(context, ProgressReportActivity::class.java)
context.startActivity(intent) context.startActivity(intent)
} }
fun newInstanceForResult(fragment: Fragment, stat: Stat, report: Report, displayAggregationChoices: Boolean = true, title: String? = null) { fun newInstanceForResult(fragment: Fragment, stat: Stat, report: Report, displayAggregationChoices: Boolean = true, title: String) {
this.parameters = StatisticsDetailsParameters(stat, report, title) this.parameters = StatisticsDetailsParameters(stat, report, title)
this.displayAggregationChoices = displayAggregationChoices this.displayAggregationChoices = displayAggregationChoices
val intent = Intent(fragment.context, ProgressReportActivity::class.java) val intent = Intent(fragment.context, ProgressReportActivity::class.java)
@ -58,6 +58,7 @@ class ProgressReportActivity : PokerAnalyticsActivity() {
fragmentTransaction.commit() fragmentTransaction.commit()
parameters?.let { parameters?.let {
statisticDetailsFragment.setData(it.stat, it.report, displayAggregationChoices, it.title) statisticDetailsFragment.setData(it.stat, it.report, displayAggregationChoices, it.title)
parameters = null parameters = null
} }

@ -7,33 +7,6 @@ import net.pokeranalytics.android.ui.fragment.report.TableReportFragment
class TableReportActivity : ReportActivity() { class TableReportActivity : ReportActivity() {
// companion object {
// const val DEFAULT_REQUEST_CODE = 1000
//
// // Unparcel fails when setting a custom Parcelable object on Entry so we use a static reference to passe objects
// private var report: Report? = null
// private var reportTitle: String = ""
//
// /**
// * Default constructor
// */
// fun newInstance(context: Context, report: Report, reportTitle: String) {
// this.report = report
// this.reportTitle = reportTitle
// val intent = Intent(context, TableReportActivity::class.java)
// context.startActivity(intent)
// }
//
// fun newInstanceForResult(fragment: Fragment, report: Report, reportTitle: String) {
// this.report = report
// this.reportTitle = reportTitle
//
// val intent = Intent(fragment.requireContext(), TableReportActivity::class.java)
// fragment.startActivityForResult(intent, DEFAULT_REQUEST_CODE)
// }
//
// }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_table_report) setContentView(R.layout.activity_table_report)
@ -45,10 +18,12 @@ class TableReportActivity : ReportActivity() {
*/ */
private fun initUI() { private fun initUI() {
val fragmentTransaction = supportFragmentManager.beginTransaction() report?.let {
val fragment = TableReportFragment.newInstance(report, reportTitle) val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.add(R.id.reportDetailsContainer, fragment) val fragment = TableReportFragment.newInstance(it, reportTitle)
fragmentTransaction.commit() fragmentTransaction.add(R.id.reportDetailsContainer, fragment)
fragmentTransaction.commit()
}
report = null report = null
} }

@ -150,10 +150,12 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when (row) { when (row) {
is GraphRow -> { is GraphRow -> {
row.report?.let { report -> val report = row.report
row.stat?.let { stat -> val stat = row.stat
ProgressReportActivity.newInstance(requireContext(), stat, report, false, row.title)
} if (report != null && stat != null) {
val title = row.title ?: stat.localizedTitle(requireContext())
ProgressReportActivity.newInstance(requireContext(), stat, report, false, title)
} }
} }
} }

@ -201,7 +201,9 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
// TableReportActivity.newInstance(requireContext(), report, reportName) // TableReportActivity.newInstance(requireContext(), report, reportName)
} }
Calculator.Options.Display.PROGRESS -> { Calculator.Options.Display.PROGRESS -> {
ProgressReportActivity.newInstanceForResult(this@ReportsFragment, options.stats.first(), report) val stat = options.stats.first()
val title = stat.localizedTitle(requireContext())
ProgressReportActivity.newInstanceForResult(this@ReportsFragment, stat, report, title = title)
} }
Calculator.Options.Display.COMPARISON -> { Calculator.Options.Display.COMPARISON -> {
// ComparisonReportActivity.newInstance(requireContext(), report, reportName) // ComparisonReportActivity.newInstance(requireContext(), report, reportName)

@ -40,7 +40,18 @@ abstract class AbstractReportFragment : DataManagerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
parentActivity = activity as PokerAnalyticsActivity parentActivity = activity as PokerAnalyticsActivity
// Avoid a bug during setting the titleResId
toolbar.title = ""
parentActivity.setSupportActionBar(toolbar)
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
setHasOptionsMenu(true)
toolbar.title = reportTitle
} }
override fun saveData() { override fun saveData() {

@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.fragment_progress_report.toolbar
import kotlinx.android.synthetic.main.fragment_report_details.* import kotlinx.android.synthetic.main.fragment_report_details.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Report import net.pokeranalytics.android.calculus.Report
@ -14,16 +13,14 @@ import net.pokeranalytics.android.ui.adapter.ReportPagerAdapter
class ComparisonReportFragment : AbstractReportFragment() { class ComparisonReportFragment : AbstractReportFragment() {
companion object { companion object {
fun newInstance(report: Report?, reportTitle: String): ComparisonReportFragment {
fun newInstance(report: Report, reportTitle: String): ComparisonReportFragment {
val fragment = ComparisonReportFragment() val fragment = ComparisonReportFragment()
fragment.reportTitle = reportTitle fragment.reportTitle = reportTitle
report?.let { fragment.setReport(report)
fragment.setReport(it)
}
val bundle = Bundle() val bundle = Bundle()
fragment.arguments = bundle fragment.arguments = bundle
return fragment return fragment
} }
} }
@ -49,15 +46,6 @@ class ComparisonReportFragment : AbstractReportFragment() {
*/ */
private fun initUI() { private fun initUI() {
// Avoid a bug during setting the titleResId
toolbar.title = ""
parentActivity.setSupportActionBar(toolbar)
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
setHasOptionsMenu(true)
toolbar.title = reportTitle
val reportPagerAdapter = ReportPagerAdapter(requireContext(), parentActivity.supportFragmentManager, selectedReport) val reportPagerAdapter = ReportPagerAdapter(requireContext(), parentActivity.supportFragmentManager, selectedReport)
viewPager.adapter = reportPagerAdapter viewPager.adapter = reportPagerAdapter
viewPager.offscreenPageLimit = 3 viewPager.offscreenPageLimit = 3

@ -212,7 +212,8 @@ open class ComposableTableReportFragment : RealmFragment(), StaticRowRepresentab
if (!isDetached) { if (!isDetached) {
hideLoader() hideLoader()
report?.let { report?.let {
ProgressReportActivity.newInstance(requireContext(), stat, it) val title = stat.localizedTitle(requireContext())
ProgressReportActivity.newInstance(requireContext(), stat, it, title = title)
} }
} }
} }

@ -64,7 +64,7 @@ class ProgressReportFragment : AbstractReportFragment() {
/** /**
* Set data * Set data
*/ */
fun setData(stat: Stat, report: Report, displayAggregationChoices: Boolean, title: String? = null) { fun setData(stat: Stat, report: Report, displayAggregationChoices: Boolean, title: String) {
this.stat = stat this.stat = stat
this.setReport(report) this.setReport(report)
this.displayAggregationChoices = displayAggregationChoices this.displayAggregationChoices = displayAggregationChoices
@ -80,13 +80,6 @@ class ProgressReportFragment : AbstractReportFragment() {
*/ */
private fun initUI() { private fun initUI() {
// Avoid a bug during setting the titleResId
toolbar.title = ""
parentActivity.setSupportActionBar(toolbar)
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
setHasOptionsMenu(true)
val fragmentManager = parentActivity.supportFragmentManager val fragmentManager = parentActivity.supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction() val fragmentTransaction = fragmentManager.beginTransaction()
graphFragment = GraphFragment() graphFragment = GraphFragment()
@ -100,7 +93,6 @@ class ProgressReportFragment : AbstractReportFragment() {
} }
} }
toolbar.title = this.reportTitle ?: stat.localizedTitle(requireContext())
val aggregationTypes = stat.aggregationTypes val aggregationTypes = stat.aggregationTypes
aggregationTypes.forEachIndexed { index, type -> aggregationTypes.forEachIndexed { index, type ->

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_progress_report.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Report import net.pokeranalytics.android.calculus.Report
@ -14,12 +13,10 @@ class TableReportFragment : AbstractReportFragment() {
companion object { companion object {
fun newInstance(report: Report? = null, title: String? = null): TableReportFragment { fun newInstance(report: Report, title: String): TableReportFragment {
val fragment = TableReportFragment() val fragment = TableReportFragment()
fragment.reportTitle = title fragment.reportTitle = title
report?.let { fragment.setReport(report)
fragment.setReport(it)
}
val bundle = Bundle() val bundle = Bundle()
fragment.arguments = bundle fragment.arguments = bundle
return fragment return fragment
@ -38,15 +35,6 @@ class TableReportFragment : AbstractReportFragment() {
private fun initUI() { private fun initUI() {
// Avoid a bug during setting the titleResId
toolbar.title = ""
parentActivity.setSupportActionBar(toolbar)
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
setHasOptionsMenu(true)
toolbar.title = reportTitle
val fragmentTransaction = parentActivity.supportFragmentManager.beginTransaction() val fragmentTransaction = parentActivity.supportFragmentManager.beginTransaction()
val fragment = ComposableTableReportFragment.newInstance(this.selectedReport) val fragment = ComposableTableReportFragment.newInstance(this.selectedReport)
fragmentTransaction.add(R.id.tableReportContainer, fragment) fragmentTransaction.add(R.id.tableReportContainer, fragment)

Loading…
Cancel
Save