package dev.kaderli.magsend.activity

import android.os.Bundle
import android.widget.TextView
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import dev.kaderli.magsend.R

class CalibrationActivity : BaseSensorActivity() {
  private lateinit var calibrationValue: TextView
  private lateinit var chart: LineChart
  private var data = ArrayList<Entry>()

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    calibrationValue = findViewById(R.id.calibrationValue)
    chart = findViewById(R.id.chart)
    calibrationValue.text = getString(R.string.calibration_value, 0f)
  }

  override fun getLayoutId(): Int {
    return R.layout.activity_calibration
  }

  override fun sensorValueReceived(magneticFieldStrength: Float) {
    calibrationValue.text = getString(R.string.calibration_value, magneticFieldStrength)
    data.add(Entry(data.size.toFloat(), magneticFieldStrength))
    val dataSet = LineDataSet(data, "Test")
    chart.data = LineData(dataSet)
    chart.invalidate()
  }
}
