2019-12-21 14:30:14 +01:00
|
|
|
package info.nightscout.androidaps.dialogs
|
2019-08-06 01:19:24 +02:00
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-12-21 14:30:14 +01:00
|
|
|
import android.view.Window
|
|
|
|
import android.view.WindowManager
|
2019-08-06 01:19:24 +02:00
|
|
|
import androidx.fragment.app.DialogFragment
|
2019-10-08 21:20:04 +02:00
|
|
|
import info.nightscout.androidaps.Constants
|
2019-08-06 01:19:24 +02:00
|
|
|
import info.nightscout.androidaps.MainApp
|
|
|
|
import info.nightscout.androidaps.R
|
2019-08-07 15:50:37 +02:00
|
|
|
import info.nightscout.androidaps.data.Profile
|
2019-08-06 01:19:24 +02:00
|
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
|
|
|
import info.nightscout.androidaps.utils.DateUtil
|
|
|
|
import kotlinx.android.synthetic.main.close.*
|
2019-12-21 14:30:14 +01:00
|
|
|
import kotlinx.android.synthetic.main.dialog_profileviewer.*
|
2019-10-08 21:20:04 +02:00
|
|
|
import org.json.JSONObject
|
2019-08-06 01:19:24 +02:00
|
|
|
|
|
|
|
class ProfileViewerDialog : DialogFragment() {
|
|
|
|
private var time: Long = 0
|
|
|
|
|
2019-08-07 15:50:37 +02:00
|
|
|
enum class Mode(val i: Int) {
|
|
|
|
RUNNING_PROFILE(1),
|
2019-12-21 14:30:14 +01:00
|
|
|
CUSTOM_PROFILE(2)
|
2019-08-07 15:50:37 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:20:04 +02:00
|
|
|
private var mode: Mode = Mode.RUNNING_PROFILE
|
|
|
|
private var customProfileJson: String = ""
|
|
|
|
private var customProfileName: String = ""
|
|
|
|
private var customProfileUnits: String = Constants.MGDL
|
2019-08-07 15:50:37 +02:00
|
|
|
|
2019-08-06 01:19:24 +02:00
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?): View? {
|
|
|
|
// load data from bundle
|
|
|
|
(savedInstanceState ?: arguments)?.let { bundle ->
|
|
|
|
time = bundle.getLong("time", 0)
|
2019-08-07 15:50:37 +02:00
|
|
|
mode = Mode.values()[bundle.getInt("mode", Mode.RUNNING_PROFILE.ordinal)]
|
2019-10-08 21:20:04 +02:00
|
|
|
customProfileJson = bundle.getString("customProfile", "")
|
|
|
|
customProfileUnits = bundle.getString("customProfileUnits", Constants.MGDL)
|
|
|
|
customProfileName = bundle.getString("customProfileName", "")
|
2019-08-06 01:19:24 +02:00
|
|
|
}
|
|
|
|
|
2019-12-21 14:30:14 +01:00
|
|
|
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
|
|
|
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
|
|
|
isCancelable = true
|
|
|
|
dialog?.setCanceledOnTouchOutside(false)
|
|
|
|
|
|
|
|
return inflater.inflate(R.layout.dialog_profileviewer, container, false)
|
2019-08-06 01:19:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
|
|
close.setOnClickListener { dismiss() }
|
|
|
|
|
2019-08-07 15:50:37 +02:00
|
|
|
val profile: Profile?
|
|
|
|
val profileName: String?
|
|
|
|
val date: String?
|
|
|
|
when (mode) {
|
|
|
|
Mode.RUNNING_PROFILE -> {
|
|
|
|
profile = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.profileObject
|
|
|
|
profileName = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.customizedName
|
|
|
|
date = DateUtil.dateAndTimeString(TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.date
|
2019-12-21 14:30:14 +01:00
|
|
|
?: 0)
|
2019-08-07 15:50:37 +02:00
|
|
|
profileview_datelayout.visibility = View.VISIBLE
|
|
|
|
}
|
2019-12-21 14:30:14 +01:00
|
|
|
|
|
|
|
Mode.CUSTOM_PROFILE -> {
|
2019-10-08 21:20:04 +02:00
|
|
|
profile = Profile(JSONObject(customProfileJson), customProfileUnits)
|
|
|
|
profileName = customProfileName
|
|
|
|
date = ""
|
|
|
|
profileview_datelayout.visibility = View.GONE
|
|
|
|
}
|
2019-08-07 15:50:37 +02:00
|
|
|
}
|
2019-08-06 01:19:24 +02:00
|
|
|
profileview_noprofile.visibility = View.VISIBLE
|
|
|
|
|
2019-08-07 15:50:37 +02:00
|
|
|
profile?.let {
|
2019-08-06 01:19:24 +02:00
|
|
|
profileview_units.text = it.units
|
|
|
|
profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia)
|
2019-08-07 15:50:37 +02:00
|
|
|
profileview_activeprofile.text = profileName
|
|
|
|
profileview_date.text = date
|
2019-08-06 01:19:24 +02:00
|
|
|
profileview_ic.text = it.icList
|
|
|
|
profileview_isf.text = it.isfList
|
|
|
|
profileview_basal.text = it.basalList
|
|
|
|
profileview_target.text = it.targetList
|
|
|
|
basal_graph.show(it)
|
|
|
|
|
|
|
|
profileview_noprofile.visibility = View.GONE
|
|
|
|
profileview_invalidprofile.visibility = if (it.isValid("ProfileViewDialog")) View.GONE else View.VISIBLE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-21 14:30:14 +01:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
2019-09-15 18:56:54 +02:00
|
|
|
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
2019-08-06 01:19:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(bundle: Bundle) {
|
|
|
|
super.onSaveInstanceState(bundle)
|
|
|
|
bundle.putLong("time", time)
|
2019-08-07 15:50:37 +02:00
|
|
|
bundle.putInt("mode", mode.ordinal)
|
2019-10-08 21:20:04 +02:00
|
|
|
bundle.putString("customProfile", customProfileJson)
|
|
|
|
bundle.putString("customProfileName", customProfileName)
|
|
|
|
bundle.putString("customProfileUnits", customProfileUnits)
|
2019-08-06 01:19:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|