Fixes issue where the number of session bar graph was not displayed initially

split
Laurent 5 years ago
parent d377072158
commit 0f44c9f06a
  1. 1
      app/src/main/java/net/pokeranalytics/android/ui/activity/GraphActivity.kt
  2. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ComparisonChartFragment.kt
  3. 48
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/ComparisonReportFragment.kt
  5. 40
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/ProgressReportFragment.kt
  6. 2
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/GraphViewModel.kt
  7. 6
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/ReportHolder.kt

@ -64,7 +64,6 @@ class GraphActivity : BaseActivity(), ViewModelHolder {
initUI() initUI()
} }
/** /**
* Init UI * Init UI
*/ */

@ -38,6 +38,7 @@ class ComparisonChartFragment : BaseFragment(), StaticRowRepresentableDataSource
private lateinit var viewPagerAdapter: ComparisonChartPagerAdapter private lateinit var viewPagerAdapter: ComparisonChartPagerAdapter
private var comparisonChartMenu: Menu? = null private var comparisonChartMenu: Menu? = null
private var _binding: FragmentComparisonChartBinding? = null private var _binding: FragmentComparisonChartBinding? = null
private val binding get() = _binding!! private val binding get() = _binding!!

@ -31,29 +31,39 @@ import timber.log.Timber
class GraphFragment : RealmFragment(), OnChartValueSelectedListener { class GraphFragment : RealmFragment(), OnChartValueSelectedListener {
private lateinit var graphDataProvider: GraphDataProvider
private val stat: Stat
get() {
return this.graphDataProvider.stat
}
companion object { companion object {
/** fun newInstance(defaultStyle: Graph.Style? = null): GraphFragment {
* Create new instance
*/
fun newInstance(style: Graph.Style): GraphFragment {
val fragment = GraphFragment() val fragment = GraphFragment()
val bundle = Bundle() val bundle = Bundle()
bundle.putSerializable(BundleKey.STYLE.value, style.ordinal) defaultStyle?.let {
bundle.putInt(BundleKey.STYLE.value, defaultStyle.ordinal)
}
fragment.arguments = bundle fragment.arguments = bundle
return fragment return fragment
} }
} }
private var style: Graph.Style = Graph.Style.LINE /***
* The view model
*/
private lateinit var graphDataProvider: GraphDataProvider
private val stat: Stat
get() {
return this.graphDataProvider.stat
}
private var _defaultStyle: Graph.Style? = null
/***
* Uses forced style first, or the style set
*/
private val style: Graph.Style
get() {
return this.graphDataProvider.style ?: this._defaultStyle ?: throw PAIllegalStateException("Graph style undefined")
}
private lateinit var legendView: LegendView private lateinit var legendView: LegendView
@ -83,8 +93,12 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener {
} }
private fun initData() { private fun initData() {
val styleOrdinal = this.arguments?.getInt(BundleKey.STYLE.value) ?: throw PAIllegalStateException("Missing style key in bundle")
this.style = Graph.Style.values()[styleOrdinal] this.arguments?.let { bundle ->
if (bundle.containsKey(BundleKey.STYLE.value)) {
this._defaultStyle = Graph.Style.values()[bundle.getInt(BundleKey.STYLE.value)]
}
}
this.graphDataProvider = (requireActivity() as ViewModelHolder).model as GraphDataProvider this.graphDataProvider = (requireActivity() as ViewModelHolder).model as GraphDataProvider
} }
@ -102,8 +116,8 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener {
this.binding.legendContainer.addView(this.legendView) this.binding.legendContainer.addView(this.legendView)
} }
fun reload(style: Graph.Style) { fun reload() {
this.style = style Timber.d("isAdded = $isAdded, isDetached = $isDetached")
if (isAdded && !isDetached) { if (isAdded && !isDetached) {
loadGraph() loadGraph()
} }

@ -30,7 +30,7 @@ class ComparisonReportFragment : AbstractReportFragment() {
_binding = null _binding = null
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
super.onCreateView(inflater, container, savedInstanceState) super.onCreateView(inflater, container, savedInstanceState)
_binding = FragmentReportDetailsBinding.inflate(inflater, container, false) _binding = FragmentReportDetailsBinding.inflate(inflater, container, false)
return binding.root return binding.root

@ -40,6 +40,8 @@ class ProgressReportFragment : AbstractReportFragment() {
companion object { companion object {
private const val GRAPH_TAG = "graph"
/** /**
* Creates new instance * Creates new instance
*/ */
@ -63,15 +65,16 @@ class ProgressReportFragment : AbstractReportFragment() {
// Life Cycle // Life Cycle
override fun onDestroyView() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
super.onDestroyView()
_binding = null
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState) super.onCreateView(inflater, container, savedInstanceState)
_binding = FragmentProgressReportBinding.inflate(inflater, container, false) _binding = FragmentProgressReportBinding.inflate(inflater, container, false)
return binding.root
val fragmentTransaction = childFragmentManager.beginTransaction()
this.graphFragment = GraphFragment.newInstance()
fragmentTransaction.add(R.id.graphContainer, this.graphFragment, GRAPH_TAG)
fragmentTransaction.commit()
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -79,17 +82,24 @@ class ProgressReportFragment : AbstractReportFragment() {
initUI() initUI()
} }
override fun onDestroyView() {
// childFragmentManager.findFragmentByTag(GRAPH_TAG)?.let { fragment ->
// val fragmentTransaction = childFragmentManager.beginTransaction()
// fragmentTransaction.remove(fragment)
// fragmentTransaction.commit()
// }
super.onDestroyView()
_binding = null
}
/** /**
* Init UI * Init UI
*/ */
private fun initUI() { private fun initUI() {
val chipGroup = binding.chipGroup val chipGroup = binding.chipGroup
val fragmentManager = parentActivity?.supportFragmentManager
val fragmentTransaction = fragmentManager?.beginTransaction()
this.graphFragment = GraphFragment.newInstance(Graph.Style.LINE)
fragmentTransaction?.add(R.id.graphContainer, this.graphFragment)
fragmentTransaction?.commit()
this.stat.aggregationTypes.firstOrNull()?.let { this.stat.aggregationTypes.firstOrNull()?.let {
this.reports[it] = this.selectedReport this.reports[it] = this.selectedReport
@ -208,11 +218,13 @@ class ProgressReportFragment : AbstractReportFragment() {
when (ds) { when (ds) {
is LineDataSet -> { is LineDataSet -> {
this.reportViewModel.setLineDataSet(ds) this.reportViewModel.setLineDataSet(ds)
graphFragment.reload(Graph.Style.LINE) this.reportViewModel.style = Graph.Style.LINE
graphFragment.reload()
} }
is BarDataSet -> { is BarDataSet -> {
this.reportViewModel.setBarDataSet(ds) this.reportViewModel.setBarDataSet(ds)
graphFragment.reload(Graph.Style.BAR) this.reportViewModel.style = Graph.Style.BAR
graphFragment.reload()
} }
else -> throw PAIllegalStateException("unmanaged data set") else -> throw PAIllegalStateException("unmanaged data set")
} }

@ -19,7 +19,7 @@ open class GraphViewModel : ViewModel(), GraphDataProvider {
/*** /***
* The graph style * The graph style
*/ */
var style: Graph.Style? = null override var style: Graph.Style? = null
/*** /***
* The displayed stat * The displayed stat

@ -6,6 +6,7 @@ import com.github.mikephil.charting.data.LineDataSet
import net.pokeranalytics.android.calculus.AxisFormatting import net.pokeranalytics.android.calculus.AxisFormatting
import net.pokeranalytics.android.calculus.Report import net.pokeranalytics.android.calculus.Report
import net.pokeranalytics.android.calculus.Stat import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.ui.graph.Graph
interface ReportHolder { interface ReportHolder {
@ -17,6 +18,11 @@ interface GraphDataProvider {
var stat: Stat var stat: Stat
var axisFormatting: AxisFormatting var axisFormatting: AxisFormatting
/***
* If no style has been given to the GraphFragment by default, this style is used
*/
var style: Graph.Style?
fun lineDataSet(context: Context) : LineDataSet fun lineDataSet(context: Context) : LineDataSet
fun multiLineDataSet(context: Context) : List<LineDataSet> fun multiLineDataSet(context: Context) : List<LineDataSet>
fun barDataSet(context: Context) : BarDataSet fun barDataSet(context: Context) : BarDataSet

Loading…
Cancel
Save