diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java index d174f170f5..2b8b79db2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java @@ -69,4 +69,8 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface { @Override public long roundDateToSec(long date) { return MainApp.getDbHelper().roundDateToSec(date); } + + @NotNull @Override public List getProfileSwitchData(long from, boolean ascending) { + return MainApp.getDbHelper().getProfileSwitchData(from, ascending); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt index 886c0ec34e..9f76f7f79c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt @@ -156,7 +156,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { R.id.profileswitch_date, R.id.profileswitch_name -> { val args = Bundle() args.putLong("time", (v.tag as ProfileSwitch).date) - args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) + args.putInt("mode", ProfileViewerDialog.Mode.DB_PROFILE.ordinal) val pvd = ProfileViewerDialog() pvd.arguments = args pvd.show(childFragmentManager, "ProfileViewDialog") diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index df60da2067..56e48bd894 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.core.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlinx.android.synthetic.main.close.* @@ -24,12 +25,14 @@ class ProfileViewerDialog : DaggerDialogFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var databaseHelper: DatabaseHelperInterface private var time: Long = 0 enum class Mode(val i: Int) { RUNNING_PROFILE(1), - CUSTOM_PROFILE(2) + CUSTOM_PROFILE(2), + DB_PROFILE(3) } private var mode: Mode = Mode.RUNNING_PROFILE @@ -79,6 +82,14 @@ class ProfileViewerDialog : DaggerDialogFragment() { date = "" profileview_datelayout.visibility = View.GONE } + + Mode.DB_PROFILE -> { + val profileList = databaseHelper.getProfileSwitchData(time, true) + profile = if (profileList.isNotEmpty()) profileList[0].profileObject else null + profileName = if (profileList.isNotEmpty()) profileList[0].customizedName else null + date = if (profileList.isNotEmpty()) dateUtil.dateAndTimeString(profileList[0].date) else null + profileview_datelayout.visibility = View.VISIBLE + } } profileview_noprofile.visibility = View.VISIBLE diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/DatabaseHelperInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/DatabaseHelperInterface.kt index fbaab3d3db..66cf3e3d2f 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/DatabaseHelperInterface.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/DatabaseHelperInterface.kt @@ -1,11 +1,7 @@ package info.nightscout.androidaps.interfaces import com.j256.ormlite.dao.CloseableIterator -import info.nightscout.androidaps.db.BgReading -import info.nightscout.androidaps.db.CareportalEvent -import info.nightscout.androidaps.db.DanaRHistoryRecord -import info.nightscout.androidaps.db.DbRequest -import info.nightscout.androidaps.db.TDD +import info.nightscout.androidaps.db.* interface DatabaseHelperInterface { @@ -21,4 +17,5 @@ interface DatabaseHelperInterface { fun deleteDbRequestbyMongoId(action: String, _id: String) fun getDbRequestInterator(): CloseableIterator fun roundDateToSec(date: Long): Long + fun getProfileSwitchData(from: Long, ascending: Boolean): List } \ No newline at end of file