ErrorDialog improvemnts

This commit is contained in:
Milos Kozak 2020-12-14 14:20:02 +01:00
parent f5f4c655c5
commit 6cb62412c5
3 changed files with 54 additions and 15 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.dialogs
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -9,9 +10,10 @@ import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.core.databinding.DialogErrorBinding
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import kotlinx.android.synthetic.main.dialog_error.*
import info.nightscout.androidaps.utils.T
import javax.inject.Inject
class ErrorDialog : DaggerDialogFragment() {
@ -24,8 +26,16 @@ class ErrorDialog : DaggerDialogFragment() {
var title: String = ""
var sound: Int = 0
private var loopHandler = Handler()
private var _binding: DialogErrorBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
savedInstanceState: Bundle?): View {
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
isCancelable = true
@ -37,21 +47,27 @@ class ErrorDialog : DaggerDialogFragment() {
sound = bundle.getInt("sound", R.raw.error)
}
aapsLogger.debug("Error dialog displayed")
return inflater.inflate(R.layout.dialog_error, container, false)
_binding = DialogErrorBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
error_title.text = title
overview_error_ok.setOnClickListener {
binding.title.text = title
binding.ok.setOnClickListener {
aapsLogger.debug("USER ENTRY: Error dialog ok button pressed")
dismiss()
}
overview_error_mute.setOnClickListener {
binding.mute.setOnClickListener {
aapsLogger.debug("USER ENTRY: Error dialog mute button pressed")
stopAlarm()
}
binding.mute5min.setOnClickListener {
aapsLogger.debug("USER ENTRY: Error dialog mute 5 min button pressed")
stopAlarm()
loopHandler.postDelayed(this::startAlarm, T.mins(5).msecs())
}
startAlarm()
}
@ -69,12 +85,18 @@ class ErrorDialog : DaggerDialogFragment() {
override fun onResume() {
super.onResume()
overview_error_status.text = status
binding.status.text = status
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
override fun dismiss() {
super.dismissAllowingStateLoss()
helperActivity?.finish()
loopHandler.removeCallbacksAndMessages(null)
stopAlarm()
}

View file

@ -21,7 +21,7 @@
app:srcCompat="@drawable/ic_error_red_48dp" />
<TextView
android:id="@+id/error_title"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
@ -42,27 +42,43 @@
android:padding="5dp" />
<TextView
android:id="@+id/overview_error_status"
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center_horizontal" />
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<Button
android:id="@+id/overview_error_mute"
android:layout_width="wrap_content"
android:id="@+id/mute_5min"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text="@string/mute5min" />
<Button
android:id="@+id/mute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text="@string/mute" />
<Button
android:id="@+id/overview_error_ok"
android:layout_width="wrap_content"
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text="@string/ok" />
</LinearLayout>

View file

@ -262,6 +262,7 @@
<string name="history_group_prime">Prime</string>
<string name="history_group_alarm">Alarms</string>
<string name="history_group_glucose">Glucose</string>
<string name="mute5min">Mute for 5 minutes</string>
<!-- <string name="medtronic_pump_status_never_contacted">Never contacted</string>-->
<!-- <string name="medtronic_pump_status_waking_up">Waking up</string>-->