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 package info.nightscout.androidaps.dialogs
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -9,9 +10,10 @@ import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.core.databinding.DialogErrorBinding
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import kotlinx.android.synthetic.main.dialog_error.* import info.nightscout.androidaps.utils.T
import javax.inject.Inject import javax.inject.Inject
class ErrorDialog : DaggerDialogFragment() { class ErrorDialog : DaggerDialogFragment() {
@ -24,8 +26,16 @@ class ErrorDialog : DaggerDialogFragment() {
var title: String = "" var title: String = ""
var sound: Int = 0 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?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View {
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE) dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
isCancelable = true isCancelable = true
@ -37,21 +47,27 @@ class ErrorDialog : DaggerDialogFragment() {
sound = bundle.getInt("sound", R.raw.error) sound = bundle.getInt("sound", R.raw.error)
} }
aapsLogger.debug("Error dialog displayed") 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?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
error_title.text = title binding.title.text = title
overview_error_ok.setOnClickListener { binding.ok.setOnClickListener {
aapsLogger.debug("USER ENTRY: Error dialog ok button pressed") aapsLogger.debug("USER ENTRY: Error dialog ok button pressed")
dismiss() dismiss()
} }
overview_error_mute.setOnClickListener { binding.mute.setOnClickListener {
aapsLogger.debug("USER ENTRY: Error dialog mute button pressed") aapsLogger.debug("USER ENTRY: Error dialog mute button pressed")
stopAlarm() 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() startAlarm()
} }
@ -69,12 +85,18 @@ class ErrorDialog : DaggerDialogFragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
overview_error_status.text = status binding.status.text = status
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
} }
override fun dismiss() { override fun dismiss() {
super.dismissAllowingStateLoss() super.dismissAllowingStateLoss()
helperActivity?.finish() helperActivity?.finish()
loopHandler.removeCallbacksAndMessages(null)
stopAlarm() stopAlarm()
} }

View file

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

View file

@ -262,6 +262,7 @@
<string name="history_group_prime">Prime</string> <string name="history_group_prime">Prime</string>
<string name="history_group_alarm">Alarms</string> <string name="history_group_alarm">Alarms</string>
<string name="history_group_glucose">Glucose</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_never_contacted">Never contacted</string>-->
<!-- <string name="medtronic_pump_status_waking_up">Waking up</string>--> <!-- <string name="medtronic_pump_status_waking_up">Waking up</string>-->