move DialogFragmentWithDate

This commit is contained in:
Milos Kozak 2022-11-23 13:06:22 +01:00
parent 58a96ab6ce
commit 1670cd0c06
18 changed files with 89 additions and 30 deletions

View file

@ -0,0 +1,76 @@
package info.nightscout.automation.dialogs
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import androidx.fragment.app.FragmentManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.core.main.R
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
abstract class BaseDialog : DaggerDialogFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
//one shot guards
private var okClicked: AtomicBoolean = AtomicBoolean(false)
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
aapsLogger.debug(LTag.UI, "Dialog opened: ${this.javaClass.simpleName}")
}
fun onCreateViewGeneral() {
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
isCancelable = true
dialog?.setCanceledOnTouchOutside(false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
(view.findViewById(R.id.ok) as Button?)?.setOnClickListener {
synchronized(okClicked) {
if (okClicked.get()) {
aapsLogger.warn(LTag.UI, "guarding: ok already clicked for dialog: ${this.javaClass.simpleName}")
} else {
okClicked.set(true)
if (submit()) {
aapsLogger.debug(LTag.UI, "Submit pressed for Dialog: ${this.javaClass.simpleName}")
dismiss()
} else {
aapsLogger.debug(LTag.UI, "Submit returned false for Dialog: ${this.javaClass.simpleName}")
okClicked.set(false)
}
}
}
}
(view.findViewById(R.id.cancel) as Button?)?.setOnClickListener {
aapsLogger.debug(LTag.UI, "Cancel pressed for dialog: ${this.javaClass.simpleName}")
dismiss()
}
}
override fun show(manager: FragmentManager, tag: String?) {
try {
manager.beginTransaction().let {
it.add(this, tag)
it.commitAllowingStateLoss()
}
} catch (e: IllegalStateException) {
aapsLogger.debug(e.localizedMessage ?: "")
}
}
abstract fun submit(): Boolean
}

View file

@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.RadioButton
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.actions.Action
import info.nightscout.automation.databinding.AutomationDialogChooseActionBinding
@ -16,7 +15,7 @@ import info.nightscout.rx.bus.RxBus
import javax.inject.Inject
import kotlin.reflect.full.primaryConstructor
class ChooseActionDialog : DialogFragmentWithDate() {
class ChooseActionDialog : BaseDialog() {
@Inject lateinit var automationPlugin: AutomationPlugin
@Inject lateinit var rxBus: RxBus

View file

@ -5,13 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RadioButton
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.automation.databinding.AutomationDialogChooseOperationBinding
import info.nightscout.automation.triggers.TriggerConnector
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class ChooseOperationDialog : DialogFragmentWithDate() {
class ChooseOperationDialog : BaseDialog() {
@Inject lateinit var rh: ResourceHelper

View file

@ -6,14 +6,13 @@ import android.view.View
import android.view.ViewGroup
import android.widget.RadioButton
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.databinding.AutomationDialogChooseTriggerBinding
import info.nightscout.automation.triggers.Trigger
import javax.inject.Inject
import kotlin.reflect.full.primaryConstructor
class ChooseTriggerDialog : DialogFragmentWithDate() {
class ChooseTriggerDialog : BaseDialog() {
@Inject lateinit var automationPlugin: AutomationPlugin
@Inject lateinit var injector: HasAndroidInjector

View file

@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.automation.actions.Action
import info.nightscout.automation.actions.ActionDummy
import info.nightscout.automation.databinding.AutomationDialogActionBinding
@ -14,7 +13,7 @@ import info.nightscout.rx.bus.RxBus
import org.json.JSONObject
import javax.inject.Inject
class EditActionDialog : DialogFragmentWithDate() {
class EditActionDialog : BaseDialog() {
@Inject lateinit var rxBus: RxBus
@Inject lateinit var injector: HasAndroidInjector

View file

@ -10,7 +10,6 @@ import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.automation.AutomationEvent
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.R
@ -30,7 +29,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign
import javax.inject.Inject
class EditEventDialog : DialogFragmentWithDate() {
class EditEventDialog : BaseDialog() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBus

View file

@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.automation.databinding.AutomationDialogEditTriggerBinding
import info.nightscout.automation.events.EventAutomationUpdateTrigger
import info.nightscout.automation.events.EventTriggerChanged
@ -22,7 +21,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
import org.json.JSONObject
import javax.inject.Inject
class EditTriggerDialog : DialogFragmentWithDate() {
class EditTriggerDialog : BaseDialog() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBus

View file

@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.core.ui.dialogs.OKDialog

View file

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.core.ui.dialogs.OKDialog

View file

@ -10,7 +10,6 @@ import android.view.ViewGroup
import androidx.annotation.StringRes
import com.google.common.base.Joiner
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.extensions.fromConstant
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.dialogs
package info.nightscout.ui.dialogs
import android.os.Bundle
import android.text.format.DateFormat
@ -14,12 +14,11 @@ import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import dagger.android.support.DaggerDialogFragment
import info.nightscout.core.main.R
import info.nightscout.shared.extensions.toVisibility
import info.nightscout.shared.utils.DateUtil
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.extensions.toVisibility
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import java.util.Calendar
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
@ -53,7 +52,7 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
aapsLogger.debug(LTag.APS, "Dialog opened: ${this.javaClass.simpleName}")
aapsLogger.debug(LTag.UI, "Dialog opened: ${this.javaClass.simpleName}")
}
override fun onSaveInstanceState(savedInstanceState: Bundle) {
@ -128,10 +127,10 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
} else {
okClicked.set(true)
if (submit()) {
aapsLogger.debug(LTag.APS, "Submit pressed for Dialog: ${this.javaClass.simpleName}")
aapsLogger.debug(LTag.UI, "Submit pressed for Dialog: ${this.javaClass.simpleName}")
dismiss()
} else {
aapsLogger.debug(LTag.APS, "Submit returned false for Dialog: ${this.javaClass.simpleName}")
aapsLogger.debug(LTag.UI, "Submit returned false for Dialog: ${this.javaClass.simpleName}")
okClicked.set(false)
}
}

View file

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils

View file

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils

View file

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.pump.insertBolusTransaction
import info.nightscout.core.ui.dialogs.OKDialog

View file

@ -10,7 +10,6 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import com.google.common.base.Joiner
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils

View file

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils

View file

@ -8,7 +8,6 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import com.google.common.base.Joiner
import com.google.common.collect.Lists
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils

View file

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.common.base.Joiner
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.pump.insertBolusTransaction
import info.nightscout.core.pump.insertCarbsTransaction