AndroidAPS/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt

90 lines
4 KiB
Kotlin
Raw Normal View History

2019-12-09 19:03:26 +01:00
package info.nightscout.androidaps.activities
2021-08-11 19:01:19 +02:00
import android.annotation.SuppressLint
2019-12-09 19:03:26 +01:00
import android.os.Bundle
2022-03-21 19:23:37 +01:00
import android.widget.TextView
2019-12-09 19:03:26 +01:00
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
2021-01-22 14:20:56 +01:00
import info.nightscout.androidaps.databinding.ActivityStatsBinding
2021-02-09 17:57:28 +01:00
import info.nightscout.androidaps.logging.UserEntryLogger
2019-12-09 19:03:26 +01:00
import info.nightscout.androidaps.utils.ActivityMonitor
2022-09-29 16:33:14 +02:00
import info.nightscout.androidaps.utils.FabricPrivacy
2020-04-08 14:03:57 +02:00
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
2022-09-29 16:33:14 +02:00
import info.nightscout.androidaps.utils.rx.AapsSchedulers
2022-05-27 12:12:12 +02:00
import info.nightscout.androidaps.utils.stats.DexcomTirCalculator
2019-12-31 14:40:06 +01:00
import info.nightscout.androidaps.utils.stats.TddCalculator
import info.nightscout.androidaps.utils.stats.TirCalculator
2022-09-29 16:33:14 +02:00
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign
2019-12-28 22:51:04 +01:00
import javax.inject.Inject
2019-12-09 19:03:26 +01:00
class StatsActivity : NoSplashAppCompatActivity() {
2021-01-18 22:47:55 +01:00
2019-12-30 00:53:44 +01:00
@Inject lateinit var tddCalculator: TddCalculator
2019-12-31 14:40:06 +01:00
@Inject lateinit var tirCalculator: TirCalculator
2022-05-27 12:12:12 +02:00
@Inject lateinit var dexcomTirCalculator: DexcomTirCalculator
2019-12-31 09:41:02 +01:00
@Inject lateinit var activityMonitor: ActivityMonitor
2021-02-09 17:57:28 +01:00
@Inject lateinit var uel: UserEntryLogger
2022-09-29 16:33:14 +02:00
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var fabricPrivacy: FabricPrivacy
2019-12-28 22:51:04 +01:00
2021-01-22 14:20:56 +01:00
private lateinit var binding: ActivityStatsBinding
2022-09-29 16:33:14 +02:00
private val disposable = CompositeDisposable()
2021-01-22 14:20:56 +01:00
2021-08-11 19:01:19 +02:00
@SuppressLint("SetTextI18n")
2019-12-09 19:03:26 +01:00
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
2021-01-22 14:20:56 +01:00
binding = ActivityStatsBinding.inflate(layoutInflater)
setContentView(binding.root)
2019-12-09 19:03:26 +01:00
2022-03-21 19:23:37 +01:00
binding.tdds.addView(TextView(this).apply { text = getString(R.string.tdd) + ": " + rh.gs(R.string.calculation_in_progress) })
binding.tir.addView(TextView(this).apply { text = getString(R.string.tir) + ": " + rh.gs(R.string.calculation_in_progress) })
binding.activity.addView(TextView(this).apply { text = getString(R.string.activitymonitor) + ": " + rh.gs(R.string.calculation_in_progress) })
2021-08-11 19:01:19 +02:00
2022-09-29 16:33:14 +02:00
disposable += Single.fromCallable { tddCalculator.stats(this) }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribe({
binding.tdds.removeAllViews()
binding.tdds.addView(it)
}, fabricPrivacy::logException)
disposable += Single.fromCallable { tirCalculator.stats(this) }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribe({
binding.tir.removeAllViews()
binding.tir.addView(it)
}, fabricPrivacy::logException)
disposable += Single.fromCallable { dexcomTirCalculator.stats(this) }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribe({
binding.dexcomTir.removeAllViews()
binding.dexcomTir.addView(it)
}, fabricPrivacy::logException)
disposable += Single.fromCallable { activityMonitor.stats(this) }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribe({
binding.activity.removeAllViews()
binding.activity.addView(it)
}, fabricPrivacy::logException)
2019-12-09 19:03:26 +01:00
2021-01-22 14:20:56 +01:00
binding.ok.setOnClickListener { finish() }
binding.reset.setOnClickListener {
2021-11-02 09:53:16 +01:00
OKDialog.showConfirmation(this, rh.gs(R.string.doyouwantresetstats)) {
uel.log(Action.STAT_RESET, Sources.Stats)
2019-12-31 09:41:02 +01:00
activityMonitor.reset()
2019-12-09 19:03:26 +01:00
recreate()
2021-01-22 14:20:56 +01:00
}
2019-12-09 19:03:26 +01:00
}
}
2022-09-29 16:33:14 +02:00
override fun onPause() {
super.onPause()
disposable.clear()
}
2019-12-09 19:03:26 +01:00
}