parent
9845193db3
commit
5e2959e883
@ -0,0 +1,57 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import com.github.mikephil.charting.data.Entry |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.calculus.Stat |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
import net.pokeranalytics.android.ui.fragment.GraphFragment |
||||||
|
|
||||||
|
class GraphActivity : PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
private enum class IntentKey(val keyName: String) { |
||||||
|
STAT("STAT"), |
||||||
|
ENTRIES("ENTRIES"), |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
/** |
||||||
|
* Default constructor |
||||||
|
*/ |
||||||
|
fun newInstance(context: Context, stat: Stat, entries: Array<out Entry>) { |
||||||
|
val intent = Intent(context, GraphActivity::class.java) |
||||||
|
intent.putExtra(IntentKey.STAT.keyName, stat.name) |
||||||
|
intent.putExtra(IntentKey.ENTRIES.keyName, entries) |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_editable_data) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
val stat = Stat.valueOf(intent.getStringExtra(IntentKey.STAT.keyName)) |
||||||
|
val entries = intent.getParcelableArrayExtra(IntentKey.ENTRIES.keyName) |
||||||
|
|
||||||
|
val fragmentManager = supportFragmentManager |
||||||
|
val fragmentTransaction = fragmentManager.beginTransaction() |
||||||
|
val fragment = GraphFragment() |
||||||
|
|
||||||
|
fragmentTransaction.add(R.id.container, fragment) |
||||||
|
fragmentTransaction.commit() |
||||||
|
fragment.setData(stat, entries) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,59 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.os.Parcelable |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import com.github.mikephil.charting.data.Entry |
||||||
|
import com.github.mikephil.charting.data.LineData |
||||||
|
import com.github.mikephil.charting.data.LineDataSet |
||||||
|
import kotlinx.android.synthetic.main.fragment_graph.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.calculus.Stat |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
||||||
|
|
||||||
|
interface GraphDataSource { |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
class GraphFragment : PokerAnalyticsFragment() { |
||||||
|
|
||||||
|
lateinit var dataSource: GraphDataSource |
||||||
|
lateinit var entries: Array<Parcelable> |
||||||
|
lateinit var stat: Stat |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
fun setData(stat: Stat, entries: Array<Parcelable>) { |
||||||
|
this.stat = stat |
||||||
|
this.entries = entries |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(R.layout.fragment_graph, container, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
(this.entries.toList() as MutableList<Entry>).let { entries -> |
||||||
|
|
||||||
|
val dataSet = LineDataSet(entries, stat.name) |
||||||
|
val lineData = LineData(listOf(dataSet)) |
||||||
|
this.chart.data = lineData |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:id="@+id/container" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
</FrameLayout> |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
<com.github.mikephil.charting.charts.LineChart |
||||||
|
android:id="@+id/chart" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue