swiperefresh for loop and aps

This commit is contained in:
osodebailar 2022-04-24 18:03:09 +02:00
parent 4a991e4f38
commit dc4febb6e4
5 changed files with 142 additions and 68 deletions

View file

@ -1,15 +1,12 @@
package info.nightscout.androidaps.plugins.aps.loop package info.nightscout.androidaps.plugins.aps.loop
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.*
import android.view.View
import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.LoopFragmentBinding import info.nightscout.androidaps.databinding.LoopFragmentBinding
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
@ -18,6 +15,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
@ -34,6 +32,8 @@ class LoopFragment : DaggerFragment() {
@Inject lateinit var loop: Loop @Inject lateinit var loop: Loop
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
private val ID_MENU_RUN = 1
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
private var _binding: LoopFragmentBinding? = null private var _binding: LoopFragmentBinding? = null
@ -42,8 +42,11 @@ class LoopFragment : DaggerFragment() {
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(
savedInstanceState: Bundle?): View { inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
setHasOptionsMenu(true)
_binding = LoopFragmentBinding.inflate(inflater, container, false) _binding = LoopFragmentBinding.inflate(inflater, container, false)
return binding.root return binding.root
} }
@ -51,12 +54,33 @@ class LoopFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.run.setOnClickListener { with(binding.swipeRefresh) {
binding.lastrun.text = rh.gs(R.string.executing) setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
Thread { loop.invoke("Loop button", true) }.start() setOnRefreshListener {
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
Thread { loop.invoke("Loop swiperefresh", true) }.start()
}
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
menu.removeItem(ID_MENU_RUN)
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
menu.setGroupDividerEnabled(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
ID_MENU_RUN -> {
binding.lastrun.text = rh.gs(R.string.executing)
Thread { loop.invoke("Loop menu", true) }.start()
true
}
else -> false
}
@Synchronized @Synchronized
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
@ -64,16 +88,16 @@ class LoopFragment : DaggerFragment() {
.toObservable(EventLoopUpdateGui::class.java) .toObservable(EventLoopUpdateGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventLoopSetLastRunGui::class.java) .toObservable(EventLoopSetLastRunGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
clearGUI() clearGUI()
binding.lastrun.text = it.text binding.lastrun.text = it.text
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
updateGUI() updateGUI()
sp.putBoolean(R.string.key_objectiveuseloop, true) sp.putBoolean(R.string.key_objectiveuseloop, true)
@ -117,6 +141,7 @@ class LoopFragment : DaggerFragment() {
allConstraints.getMostLimitedReasons(aapsLogger) allConstraints.getMostLimitedReasons(aapsLogger)
} ?: "" } ?: ""
binding.constraints.text = constraints binding.constraints.text = constraints
binding.swipeRefresh.isRefreshing = false
} }
} }
@ -133,5 +158,6 @@ class LoopFragment : DaggerFragment() {
binding.tbrexecutionTime.text = "" binding.tbrexecutionTime.text = ""
binding.tbrsetbypump.text = "" binding.tbrsetbypump.text = ""
binding.smbsetbypump.text = "" binding.smbsetbypump.text = ""
binding.swipeRefresh.isRefreshing = false
} }
} }

View file

@ -2,14 +2,10 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.view.LayoutInflater import android.view.*
import android.view.View
import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
@ -18,6 +14,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter import info.nightscout.androidaps.utils.JSONFormatter
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import org.json.JSONArray import org.json.JSONArray
@ -37,14 +35,19 @@ class OpenAPSAMAFragment : DaggerFragment() {
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var jsonFormatter: JSONFormatter @Inject lateinit var jsonFormatter: JSONFormatter
private val ID_MENU_RUN = 1
private var _binding: OpenapsamaFragmentBinding? = null private var _binding: OpenapsamaFragmentBinding? = null
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(
savedInstanceState: Bundle?): View { inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
setHasOptionsMenu(true)
_binding = OpenapsamaFragmentBinding.inflate(inflater, container, false) _binding = OpenapsamaFragmentBinding.inflate(inflater, container, false)
return binding.root return binding.root
} }
@ -52,11 +55,34 @@ class OpenAPSAMAFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.run.setOnClickListener { with(binding.swipeRefresh) {
openAPSAMAPlugin.invoke("OpenAPSAMA button", false) setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
setOnRefreshListener {
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
openAPSAMAPlugin.invoke("OpenAPSAMA swiperefresh", false)
}
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
menu.removeItem(ID_MENU_RUN)
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
menu.setGroupDividerEnabled(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
ID_MENU_RUN -> {
binding.lastrun.text = rh.gs(R.string.executing)
openAPSAMAPlugin.invoke("OpenAPSAMA menu", false)
true
}
else -> false
}
@Synchronized @Synchronized
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
@ -65,14 +91,14 @@ class OpenAPSAMAFragment : DaggerFragment() {
.toObservable(EventOpenAPSUpdateGui::class.java) .toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java) .toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
updateResultGUI(it.text) updateResultGUI(it.text)
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
updateGUI() updateGUI()
} }
@ -118,6 +144,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
openAPSAMAPlugin.lastAutosensResult.let { openAPSAMAPlugin.lastAutosensResult.let {
binding.autosensdata.text = jsonFormatter.format(it.json()) binding.autosensdata.text = jsonFormatter.format(it.json())
} }
binding.swipeRefresh.isRefreshing = false
} }
private fun updateResultGUI(text: String) { private fun updateResultGUI(text: String) {
@ -131,5 +158,6 @@ class OpenAPSAMAFragment : DaggerFragment() {
binding.scriptdebugdata.text = "" binding.scriptdebugdata.text = ""
binding.request.text = "" binding.request.text = ""
binding.lastrun.text = "" binding.lastrun.text = ""
binding.swipeRefresh.isRefreshing = false
} }
} }

View file

@ -3,9 +3,7 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.view.LayoutInflater import android.view.*
import android.view.View
import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
@ -39,13 +37,16 @@ class OpenAPSSMBFragment : DaggerFragment() {
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var jsonFormatter: JSONFormatter @Inject lateinit var jsonFormatter: JSONFormatter
private val ID_MENU_RUN = 1
private var _binding: OpenapsamaFragmentBinding? = null private var _binding: OpenapsamaFragmentBinding? = null
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
setHasOptionsMenu(true)
_binding = OpenapsamaFragmentBinding.inflate(inflater, container, false) _binding = OpenapsamaFragmentBinding.inflate(inflater, container, false)
return binding.root return binding.root
} }
@ -53,11 +54,34 @@ class OpenAPSSMBFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.run.setOnClickListener { with(binding.swipeRefresh) {
activePlugin.activeAPS.invoke("OpenAPSSMB button", false) setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
setOnRefreshListener {
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
activePlugin.activeAPS.invoke("OpenAPSSMB swiperefresh", false)
}
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
menu.removeItem(ID_MENU_RUN)
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
menu.setGroupDividerEnabled(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
ID_MENU_RUN -> {
binding.lastrun.text = rh.gs(R.string.executing)
activePlugin.activeAPS.invoke("OpenAPSSMB menu", false)
true
}
else -> false
}
@Synchronized @Synchronized
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
@ -65,14 +89,14 @@ class OpenAPSSMBFragment : DaggerFragment() {
.toObservable(EventOpenAPSUpdateGui::class.java) .toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java) .toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({
updateResultGUI(it.text) updateResultGUI(it.text)
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
updateGUI() updateGUI()
} }
@ -122,6 +146,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
openAPSSMBPlugin.lastAutosensResult.let { openAPSSMBPlugin.lastAutosensResult.let {
binding.autosensdata.text = jsonFormatter.format(it.json()) binding.autosensdata.text = jsonFormatter.format(it.json())
} }
binding.swipeRefresh.isRefreshing = false
} }
@Synchronized @Synchronized
@ -137,5 +162,6 @@ class OpenAPSSMBFragment : DaggerFragment() {
binding.scriptdebugdata.text = "" binding.scriptdebugdata.text = ""
binding.request.text = "" binding.request.text = ""
binding.lastrun.text = "" binding.lastrun.text = ""
binding.swipeRefresh.isRefreshing = false
} }
} }

View file

@ -1,22 +1,20 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools = "http://schemas.android.com/tools"
android:id = "@+id/swipeRefresh"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context=".plugins.aps.loop.LoopFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="2dp" android:paddingTop="2dp">
tools:context=".plugins.aps.loop.LoopFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.button.MaterialButton
style="@style/GrayButton"
android:id="@+id/run"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/openapsma_run" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -515,4 +513,7 @@
</LinearLayout> </LinearLayout>
</ScrollView> </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View file

@ -1,29 +1,20 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools = "http://schemas.android.com/tools"
android:id = "@+id/swipeRefresh"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context=".plugins.aps.openAPSAMA.OpenAPSAMAFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="2dp" android:paddingTop="2dp">
tools:context=".plugins.aps.openAPSAMA.OpenAPSAMAFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
style="@style/GrayButton"
android:id="@+id/run"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/openapsma_run" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -580,4 +571,6 @@
</LinearLayout> </LinearLayout>
</ScrollView> </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>