From 6d46c39fba6090d874a90f11c970fcb961964a7a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 21 Dec 2019 14:30:14 +0100 Subject: [PATCH] ProfileViewerDialog refactor --- .../androidaps/activities/SurveyActivity.kt | 6 +- .../ProfileViewerDialog.kt | 40 +- .../androidaps/dialogs/WizardDialog.kt | 2 +- .../general/overview/OverviewFragment.java | 2 +- .../plugins/pump/danaR/DanaRFragment.kt | 9 +- .../TreatmentsProfileSwitchFragment.kt | 2 +- app/src/main/res/layout/close.xml | 19 +- .../main/res/layout/dialog_profileviewer.xml | 426 ++++++++++++++++++ 8 files changed, 455 insertions(+), 51 deletions(-) rename app/src/main/java/info/nightscout/androidaps/{plugins/treatments/fragments => dialogs}/ProfileViewerDialog.kt (74%) create mode 100644 app/src/main/res/layout/dialog_profileviewer.xml diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt index d8ec286916..991ee72d0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -4,18 +4,14 @@ import android.os.Bundle import android.widget.ArrayAdapter import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.FirebaseDatabase -import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.data.defaultProfile.DefaultProfile import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions -import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog +import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.utils.* import kotlinx.android.synthetic.main.survey_fragment.* import org.slf4j.LoggerFactory -import java.util.* - class SurveyActivity : NoSplashAppCompatActivity() { private val log = LoggerFactory.getLogger(SurveyActivity::class.java) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt similarity index 74% rename from app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt rename to app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 69d89d0063..ef3b19d4d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -1,20 +1,20 @@ -package info.nightscout.androidaps.plugins.treatments.fragments +package info.nightscout.androidaps.dialogs import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.Window +import android.view.WindowManager import androidx.fragment.app.DialogFragment import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile -import info.nightscout.androidaps.interfaces.ProfileInterface -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import kotlinx.android.synthetic.main.close.* -import kotlinx.android.synthetic.main.profileviewer_fragment.* +import kotlinx.android.synthetic.main.dialog_profileviewer.* import org.json.JSONObject class ProfileViewerDialog : DialogFragment() { @@ -22,8 +22,7 @@ class ProfileViewerDialog : DialogFragment() { enum class Mode(val i: Int) { RUNNING_PROFILE(1), - PUMP_PROFILE(2), - CUSTOM_PROFILE(3) + CUSTOM_PROFILE(2) } private var mode: Mode = Mode.RUNNING_PROFILE @@ -42,17 +41,18 @@ class ProfileViewerDialog : DialogFragment() { customProfileName = bundle.getString("customProfileName", "") } - return inflater.inflate(R.layout.profileviewer_fragment, container, false) + 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) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) close.setOnClickListener { dismiss() } - profileview_reload.setOnClickListener { - ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("ProfileViewDialog", null) - dismiss() - } val profile: Profile? val profileName: String? @@ -62,22 +62,14 @@ class ProfileViewerDialog : DialogFragment() { profile = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.profileObject profileName = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.customizedName date = DateUtil.dateAndTimeString(TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.date - ?: 0) - profileview_reload.visibility = View.GONE + ?: 0) profileview_datelayout.visibility = View.VISIBLE } - Mode.PUMP_PROFILE -> { - profile = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profile?.getDefaultProfile() - profileName = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profileName - date = "" - profileview_reload.visibility = View.VISIBLE - profileview_datelayout.visibility = View.GONE - } - Mode.CUSTOM_PROFILE -> { + + Mode.CUSTOM_PROFILE -> { profile = Profile(JSONObject(customProfileJson), customProfileUnits) profileName = customProfileName date = "" - profileview_reload.visibility = View.GONE profileview_datelayout.visibility = View.GONE } } @@ -99,9 +91,9 @@ class ProfileViewerDialog : DialogFragment() { } } - override fun onResume() { + override fun onStart() { + super.onStart() dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) - super.onResume() } override fun onSaveInstanceState(bundle: Bundle) { diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index f8d3ec5899..c84bd4a0b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -163,7 +163,7 @@ class WizardDialog : DialogFragment() { disposable.clear() } - private fun onCheckedChanged(buttonView: CompoundButton, ignored: Boolean) { + private fun onCheckedChanged(buttonView: CompoundButton, @Suppress("UNUSED_PARAMETER") state: Boolean) { saveCheckedStates() treatments_wizard_ttcheckbox.isEnabled = treatments_wizard_bgcheckbox.isChecked && TreatmentsPlugin.getPlugin().tempTargetFromHistory != null if (buttonView.id == treatments_wizard_cobcheckbox.id) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 27ea3c1fde..be4e091462 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -105,7 +105,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCa import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin; import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog; +import info.nightscout.androidaps.dialogs.ProfileViewerDialog; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.utils.BolusWizard; import info.nightscout.androidaps.utils.DateUtil; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 3f58acf4d2..c953d62ac1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -24,7 +24,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptions import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog +import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.* import io.reactivex.android.schedulers.AndroidSchedulers @@ -59,9 +59,14 @@ class DanaRFragment : Fragment() { danar_history.setOnClickListener { startActivity(Intent(context, DanaRHistoryActivity::class.java)) } danar_viewprofile.setOnClickListener { fragmentManager?.let { fragmentManager -> + val profile = DanaRPump.getInstance().createConvertedProfile()?.getDefaultProfile() ?: return@let + val profileName = DanaRPump.getInstance().createConvertedProfile()?.getDefaultProfileName() ?: return@let val args = Bundle() args.putLong("time", DateUtil.now()) - args.putInt("mode", ProfileViewerDialog.Mode.PUMP_PROFILE.ordinal) + args.putInt("mode", ProfileViewerDialog.Mode.CUSTOM_PROFILE.ordinal) + args.putString("customProfile", profile.data.toString()) + args.putString("customProfileUnits", profile.units) + args.putString("customProfileName", profileName) val pvd = ProfileViewerDialog() pvd.arguments = args pvd.show(fragmentManager, "ProfileViewDialog") 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 c22b85117c..db911dcbb0 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 @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.treatments.fragments -import android.content.DialogInterface import android.graphics.Paint import android.os.Bundle import android.view.LayoutInflater @@ -17,6 +16,7 @@ import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.db.Source +import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventProfileNeedsUpdate import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.NSUpload diff --git a/app/src/main/res/layout/close.xml b/app/src/main/res/layout/close.xml index a500295275..682cf2bc22 100644 --- a/app/src/main/res/layout/close.xml +++ b/app/src/main/res/layout/close.xml @@ -1,25 +1,11 @@ - @@ -27,8 +13,7 @@ android:id="@+id/close" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="16dp" android:layout_marginEnd="16dp" style="@style/mdtp_ActionButton.Text" - android:text="@string/close_navigation" /> + android:text="@string/close" /> diff --git a/app/src/main/res/layout/dialog_profileviewer.xml b/app/src/main/res/layout/dialog_profileviewer.xml new file mode 100644 index 0000000000..0bcd6b3d5a --- /dev/null +++ b/app/src/main/res/layout/dialog_profileviewer.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +