diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java deleted file mode 100644 index 4c5d5b5d80..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java +++ /dev/null @@ -1,94 +0,0 @@ -package info.nightscout.androidaps.plugins.general.overview.dialogs; - - -import android.content.Context; -import android.os.Bundle; -import androidx.fragment.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.widget.TextView; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.DecimalFormat; - -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.utils.NumberPicker; -import info.nightscout.androidaps.utils.SafeParse; -import info.nightscout.androidaps.utils.XdripCalibrations; - -public class CalibrationDialog extends DialogFragment implements View.OnClickListener { - private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class); - - NumberPicker bgNumber; - TextView unitsView; - - Context context; - - public CalibrationDialog() { - // Required empty public constructor - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - this.context = context; - } - - @Override - public void onDetach() { - super.onDetach(); - this.context = null; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.overview_calibration_dialog, container, false); - - getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); - getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - - view.findViewById(R.id.ok).setOnClickListener(this); - view.findViewById(R.id.cancel).setOnClickListener(this); - - String units = ProfileFunctions.getSystemUnits(); - Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); - - bgNumber = (NumberPicker) view.findViewById(R.id.overview_calibration_bg); - - if (units.equals(Constants.MMOL)) - bgNumber.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok)); - else - bgNumber.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); - - unitsView = (TextView) view.findViewById(R.id.overview_calibration_units); - unitsView.setText(units); - - setCancelable(true); - getDialog().setCanceledOnTouchOutside(false); - return view; - } - - @Override - public void onClick(View view) { - switch (view.getId()) { - case R.id.ok: - final Double bg = SafeParse.stringToDouble(bgNumber.getText()); - XdripCalibrations.confirmAndSendCalibration(bg, context); - dismiss(); - break; - case R.id.cancel: - dismiss(); - break; - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.kt new file mode 100644 index 0000000000..0e18ee72ff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.kt @@ -0,0 +1,66 @@ +package info.nightscout.androidaps.plugins.general.overview.dialogs + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.common.base.Joiner +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.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus +import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.OKDialog +import info.nightscout.androidaps.utils.XdripCalibrations +import kotlinx.android.synthetic.main.okcancel.* +import kotlinx.android.synthetic.main.overview_calibration_dialog.* +import java.text.DecimalFormat +import java.util.* + +class CalibrationDialog : DialogFragmentWithDate() { + + override fun onSaveInstanceState(savedInstanceState: Bundle) { + super.onSaveInstanceState(savedInstanceState) + savedInstanceState.putDouble("overview_calibration_bg", overview_calibration_bg.value) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + onCreateView() + return inflater.inflate(R.layout.overview_calibration_dialog, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val units = ProfileFunctions.getSystemUnits() + val bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData()?.glucose + ?: 0.0, units) + if (units == Constants.MMOL) + overview_calibration_bg.setParams(savedInstanceState?.getDouble("overview_calibration_bg") + ?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok) + else + overview_calibration_bg.setParams(savedInstanceState?.getDouble("overview_calibration_bg") + ?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok) + overview_calibration_units.text = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl) + } + + override fun submit() { + val units = ProfileFunctions.getSystemUnits() + val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl) + val actions: LinkedList = LinkedList() + val bg = overview_calibration_bg.value + actions.add("" + MainApp.gs(R.string.overview_calibration) + "") + actions.add(MainApp.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(bg) + " " + unitLabel) + if (bg > 0) { + activity?.let { activity -> + OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("
").join(actions))) { + XdripCalibrations.confirmAndSendCalibration(bg, context) + } + } + } else + OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/actions_care_dialog.xml b/app/src/main/res/layout/actions_care_dialog.xml index 28c05ee7b7..b78da379bd 100644 --- a/app/src/main/res/layout/actions_care_dialog.xml +++ b/app/src/main/res/layout/actions_care_dialog.xml @@ -40,7 +40,6 @@ android:textAppearance="?android:attr/textAppearanceLarge" /> - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + android:layout_gravity="center" + android:background="@color/dialogtitle" + android:orientation="horizontal" + android:padding="5dp"> + + + + + + + + + + android:width="120dp" + android:padding="10dp" + android:text="@string/treatments_wizard_bg_label" + android:textAppearance="@android:style/TextAppearance.Material.Small" + android:textStyle="bold" /> - + - - - - - - + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 216c21c379..a9952abfaf 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -44,6 +44,8 @@ #40bbaa #00695c + #303030 + #121212 #779ECB