temp
This commit is contained in:
parent
eba66da4a4
commit
034c16690f
4 changed files with 138 additions and 38 deletions
|
@ -4,6 +4,7 @@ import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.os.SystemClock
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -12,6 +13,7 @@ import android.widget.Button
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearSmoothScroller
|
import androidx.recyclerview.widget.LinearSmoothScroller
|
||||||
|
@ -21,6 +23,8 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.L
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog
|
import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog
|
||||||
|
import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProgressDialog
|
||||||
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
|
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||||
|
@ -101,6 +105,7 @@ class ObjectivesFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToCurrentObjective() {
|
private fun scrollToCurrentObjective() {
|
||||||
|
activity?.runOnUiThread {
|
||||||
for (i in 0 until ObjectivesPlugin.objectives.size) {
|
for (i in 0 until ObjectivesPlugin.objectives.size) {
|
||||||
val objective = ObjectivesPlugin.objectives[i]
|
val objective = ObjectivesPlugin.objectives[i]
|
||||||
if (!objective.isStarted || !objective.isAccomplished) {
|
if (!objective.isStarted || !objective.isAccomplished) {
|
||||||
|
@ -116,6 +121,7 @@ class ObjectivesFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class ObjectivesAdapter : RecyclerView.Adapter<ObjectivesAdapter.ViewHolder>() {
|
private inner class ObjectivesAdapter : RecyclerView.Adapter<ObjectivesAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
@ -205,66 +211,71 @@ class ObjectivesFragment : Fragment() {
|
||||||
holder.accomplished.text = MainApp.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
|
holder.accomplished.text = MainApp.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
|
||||||
holder.accomplished.setTextColor(-0x3e3e3f)
|
holder.accomplished.setTextColor(-0x3e3e3f)
|
||||||
holder.verify.setOnClickListener {
|
holder.verify.setOnClickListener {
|
||||||
holder.verify.visibility = View.INVISIBLE
|
|
||||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.accomplishedOn = DateUtil.now()
|
objective.accomplishedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
startUpdateTimer()
|
startUpdateTimer()
|
||||||
RxBus.send(EventObjectivesUpdateGui())
|
RxBus.send(EventObjectivesUpdateGui())
|
||||||
holder.verify.visibility = View.INVISIBLE
|
} else {
|
||||||
} else
|
// move out of UI thread
|
||||||
|
Thread {
|
||||||
|
NtpProgressDialog().show((context as AppCompatActivity).supportFragmentManager, "NtpCheck")
|
||||||
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.timedetection), 0))
|
||||||
SntpClient.ntpTime(object : SntpClient.Callback() {
|
SntpClient.ntpTime(object : SntpClient.Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
activity?.runOnUiThread {
|
|
||||||
holder.verify.visibility = View.VISIBLE
|
|
||||||
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
||||||
if (!networkConnected) {
|
if (!networkConnected) {
|
||||||
ToastUtils.showToastInUiThread(context, R.string.notconnected)
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 100))
|
||||||
} else if (success) {
|
} else if (success) {
|
||||||
if (objective.isCompleted(time)) {
|
if (objective.isCompleted(time)) {
|
||||||
objective.accomplishedOn = time
|
objective.accomplishedOn = time
|
||||||
scrollToCurrentObjective()
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.success), 100))
|
||||||
startUpdateTimer()
|
SystemClock.sleep(1000)
|
||||||
RxBus.send(EventObjectivesUpdateGui())
|
RxBus.send(EventObjectivesUpdateGui())
|
||||||
|
SystemClock.sleep(100)
|
||||||
|
scrollToCurrentObjective()
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToastInUiThread(context, R.string.requirementnotmet)
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.requirementnotmet), 100))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 100))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, NetworkChangeReceiver.isConnected())
|
}, NetworkChangeReceiver.isConnected())
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
holder.start.setOnClickListener {
|
holder.start.setOnClickListener {
|
||||||
holder.start.visibility = View.INVISIBLE
|
|
||||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.startedOn = DateUtil.now()
|
objective.startedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
startUpdateTimer()
|
startUpdateTimer()
|
||||||
RxBus.send(EventObjectivesUpdateGui())
|
RxBus.send(EventObjectivesUpdateGui())
|
||||||
holder.start.visibility = View.VISIBLE
|
|
||||||
} else
|
} else
|
||||||
|
// move out of UI thread
|
||||||
|
Thread {
|
||||||
|
NtpProgressDialog().show((context as AppCompatActivity).supportFragmentManager, "NtpCheck")
|
||||||
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.timedetection), 0))
|
||||||
SntpClient.ntpTime(object : SntpClient.Callback() {
|
SntpClient.ntpTime(object : SntpClient.Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
activity?.runOnUiThread {
|
|
||||||
holder.start.visibility = View.VISIBLE
|
|
||||||
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
||||||
if (!networkConnected) {
|
if (!networkConnected) {
|
||||||
ToastUtils.showToastInUiThread(context, R.string.notconnected)
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 100))
|
||||||
} else if (success) {
|
} else if (success) {
|
||||||
objective.startedOn = time
|
objective.startedOn = time
|
||||||
scrollToCurrentObjective()
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.success), 100))
|
||||||
startUpdateTimer()
|
SystemClock.sleep(1000)
|
||||||
RxBus.send(EventObjectivesUpdateGui())
|
RxBus.send(EventObjectivesUpdateGui())
|
||||||
|
SystemClock.sleep(100)
|
||||||
|
scrollToCurrentObjective()
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
|
RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 100))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, NetworkChangeReceiver.isConnected())
|
}, NetworkChangeReceiver.isConnected())
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
holder.unStart.setOnClickListener {
|
holder.unStart.setOnClickListener {
|
||||||
objective.startedOn = 0
|
objective.startedOn = 0
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package info.nightscout.androidaps.plugins.constraints.objectives.dialogs
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.SystemClock
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
|
||||||
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import kotlinx.android.synthetic.main.overview_bolusprogress_dialog.*
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
class NtpProgressDialog : DialogFragment() {
|
||||||
|
private val log = LoggerFactory.getLogger(L.UI)
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
private val DEFAULT_STATE = MainApp.gs(R.string.timedetection)
|
||||||
|
private var state: String = DEFAULT_STATE
|
||||||
|
private var percent = 0
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
dialog?.setTitle(String.format(MainApp.gs(R.string.objectives)))
|
||||||
|
isCancelable = false
|
||||||
|
|
||||||
|
state = savedInstanceState?.getString("state", DEFAULT_STATE) ?: DEFAULT_STATE
|
||||||
|
percent = savedInstanceState?.getInt("percent", 0) ?: 0
|
||||||
|
|
||||||
|
return inflater.inflate(R.layout.overview_bolusprogress_dialog, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
overview_bolusprogress_stop.setOnClickListener { dismiss() }
|
||||||
|
overview_bolusprogress_status.setText(state)
|
||||||
|
overview_bolusprogress_progressbar.setMax(100)
|
||||||
|
overview_bolusprogress_progressbar.setProgress(percent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
if (L.isEnabled(L.UI)) log.debug("onResume")
|
||||||
|
if (percent == 100) {
|
||||||
|
dismiss()
|
||||||
|
return
|
||||||
|
} else
|
||||||
|
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
|
|
||||||
|
disposable.add(toObservable(EventNtpStatus::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ event: EventNtpStatus ->
|
||||||
|
if (L.isEnabled(L.UI)) log.debug("Status: " + event.status + " Percent: " + event.percent)
|
||||||
|
overview_bolusprogress_status?.text = event.status
|
||||||
|
overview_bolusprogress_progressbar?.progress = event.percent
|
||||||
|
if (event.percent == 100) {
|
||||||
|
SystemClock.sleep(100)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
state = event.status
|
||||||
|
percent = event.percent
|
||||||
|
}) { FabricPrivacy.logException(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
if (L.isEnabled(L.UI)) log.debug("onPause")
|
||||||
|
super.onPause()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
outState.putString("state", state)
|
||||||
|
outState.putInt("percent", percent)
|
||||||
|
super.onSaveInstanceState(outState)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.constraints.objectives.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventNtpStatus(val status: String, val percent: Int) : Event()
|
|
@ -1633,5 +1633,6 @@
|
||||||
<string name="common_off">Off</string>
|
<string name="common_off">Off</string>
|
||||||
<string name="objectives_button_unfinish">Clear finished</string>
|
<string name="objectives_button_unfinish">Clear finished</string>
|
||||||
<string name="objectives_button_unstart">Clear started</string>
|
<string name="objectives_button_unstart">Clear started</string>
|
||||||
|
<string name="timedetection">Time detection</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Reference in a new issue