NSC: fix issues with updating GUI
This commit is contained in:
parent
67fe7889aa
commit
2a9bc52a72
|
@ -20,7 +20,6 @@ import info.nightscout.core.ui.dialogs.OKDialog
|
||||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||||
import info.nightscout.database.entities.UserEntry
|
import info.nightscout.database.entities.UserEntry
|
||||||
import info.nightscout.interfaces.Config
|
import info.nightscout.interfaces.Config
|
||||||
import info.nightscout.interfaces.Constants
|
|
||||||
import info.nightscout.interfaces.db.PersistenceLayer
|
import info.nightscout.interfaces.db.PersistenceLayer
|
||||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
|
@ -30,7 +29,7 @@ import info.nightscout.interfaces.utils.HtmlHelper
|
||||||
import info.nightscout.plugins.sync.R
|
import info.nightscout.plugins.sync.R
|
||||||
import info.nightscout.plugins.sync.databinding.NsClientFragmentBinding
|
import info.nightscout.plugins.sync.databinding.NsClientFragmentBinding
|
||||||
import info.nightscout.plugins.sync.databinding.NsClientLogItemBinding
|
import info.nightscout.plugins.sync.databinding.NsClientLogItemBinding
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiInsert
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiQueue
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiQueue
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
||||||
import info.nightscout.rx.AapsSchedulers
|
import info.nightscout.rx.AapsSchedulers
|
||||||
|
@ -98,11 +97,6 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
binding.autoscroll.isChecked = sp.getBoolean(R.string.key_ns_client_autoscroll, true)
|
|
||||||
binding.autoscroll.setOnCheckedChangeListener { _, isChecked ->
|
|
||||||
sp.putBoolean(R.string.key_ns_client_autoscroll, isChecked)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.paused.isChecked = sp.getBoolean(R.string.key_ns_paused, false)
|
binding.paused.isChecked = sp.getBoolean(R.string.key_ns_paused, false)
|
||||||
binding.paused.setOnCheckedChangeListener { _, isChecked ->
|
binding.paused.setOnCheckedChangeListener { _, isChecked ->
|
||||||
uel.log(if (isChecked) UserEntry.Action.NS_PAUSED else UserEntry.Action.NS_RESUME, UserEntry.Sources.NSClient)
|
uel.log(if (isChecked) UserEntry.Action.NS_PAUSED else UserEntry.Action.NS_RESUME, UserEntry.Sources.NSClient)
|
||||||
|
@ -198,19 +192,11 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
.toObservable(EventNSClientUpdateGuiInsert::class.java)
|
.toObservable(EventNSClientUpdateGuiData::class.java)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{
|
{
|
||||||
logAdapter.notifyItemInserted(it.position)
|
_binding?.recyclerview?.swapAdapter(RecyclerViewAdapter(nsClientPlugin?.listLog ?: arrayListOf()), true)
|
||||||
if (sp.getBoolean(R.string.key_ns_client_autoscroll, true))
|
|
||||||
_binding?.recyclerview?.scrollToPosition(it.position)
|
|
||||||
nsClientPlugin?.listLog?.let { listLog ->
|
|
||||||
synchronized(listLog) {
|
|
||||||
if (listLog.size > Constants.MAX_LOG_LINES)
|
|
||||||
logAdapter.notifyItemRemoved(listLog.size - 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, fabricPrivacy::logException
|
}, fabricPrivacy::logException
|
||||||
)
|
)
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
|
@ -240,7 +226,6 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment {
|
||||||
private fun updateStatus() {
|
private fun updateStatus() {
|
||||||
if (_binding == null) return
|
if (_binding == null) return
|
||||||
binding.paused.isChecked = sp.getBoolean(R.string.key_ns_paused, false)
|
binding.paused.isChecked = sp.getBoolean(R.string.key_ns_paused, false)
|
||||||
//if (sp.getBoolean(R.string.key_ns_client_autoscroll, true)) binding.logScrollview.fullScroll(ScrollView.FOCUS_DOWN)
|
|
||||||
binding.url.text = nsClientPlugin?.address
|
binding.url.text = nsClientPlugin?.address
|
||||||
binding.status.text = nsClientPlugin?.status
|
binding.status.text = nsClientPlugin?.status
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.plugins.sync.nsShared.events
|
||||||
|
|
||||||
import info.nightscout.rx.events.EventUpdateGui
|
import info.nightscout.rx.events.EventUpdateGui
|
||||||
|
|
||||||
class EventNSClientUpdateGuiInsert(val position: Int) : EventUpdateGui()
|
class EventNSClientUpdateGuiData : EventUpdateGui()
|
|
@ -29,7 +29,7 @@ import info.nightscout.plugins.sync.R
|
||||||
import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiInsert
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
||||||
import info.nightscout.plugins.sync.nsclient.data.AlarmAck
|
import info.nightscout.plugins.sync.nsclient.data.AlarmAck
|
||||||
import info.nightscout.plugins.sync.nsclient.extensions.toJson
|
import info.nightscout.plugins.sync.nsclient.extensions.toJson
|
||||||
|
@ -160,11 +160,11 @@ class NSClientPlugin @Inject constructor(
|
||||||
private fun addToLog(ev: EventNSClientNewLog) {
|
private fun addToLog(ev: EventNSClientNewLog) {
|
||||||
synchronized(listLog) {
|
synchronized(listLog) {
|
||||||
listLog.add(0, ev)
|
listLog.add(0, ev)
|
||||||
rxBus.send(EventNSClientUpdateGuiInsert(0))
|
|
||||||
// remove the first line if log is too large
|
// remove the first line if log is too large
|
||||||
if (listLog.size >= Constants.MAX_LOG_LINES) {
|
if (listLog.size >= Constants.MAX_LOG_LINES) {
|
||||||
listLog.removeAt(listLog.size - 1)
|
listLog.removeAt(listLog.size - 1)
|
||||||
}
|
}
|
||||||
|
rxBus.send(EventNSClientUpdateGuiData())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
||||||
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
|
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
|
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiInsert
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiData
|
||||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGuiStatus
|
||||||
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
|
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
|
||||||
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
|
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
|
||||||
|
@ -292,11 +292,11 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
private fun addToLog(ev: EventNSClientNewLog) {
|
private fun addToLog(ev: EventNSClientNewLog) {
|
||||||
synchronized(listLog) {
|
synchronized(listLog) {
|
||||||
listLog.add(0, ev)
|
listLog.add(0, ev)
|
||||||
rxBus.send(EventNSClientUpdateGuiInsert(0))
|
|
||||||
// remove the first line if log is too large
|
// remove the first line if log is too large
|
||||||
if (listLog.size >= Constants.MAX_LOG_LINES) {
|
if (listLog.size >= Constants.MAX_LOG_LINES) {
|
||||||
listLog.removeAt(listLog.size - 1)
|
listLog.removeAt(listLog.size - 1)
|
||||||
}
|
}
|
||||||
|
rxBus.send(EventNSClientUpdateGuiData())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ScrollView
|
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
|
@ -62,16 +61,6 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment {
|
||||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||||
}.root
|
}.root
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
binding.autoscroll.isChecked = sp.getBoolean(R.string.key_ns_client_autoscroll, true)
|
|
||||||
binding.autoscroll.setOnCheckedChangeListener { _, isChecked ->
|
|
||||||
sp.putBoolean(R.string.key_ns_client_autoscroll, isChecked)
|
|
||||||
updateGui()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
menu.add(Menu.FIRST, ID_MENU_CLEAR_LOG, 0, rh.gs(R.string.clear_log)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
menu.add(Menu.FIRST, ID_MENU_CLEAR_LOG, 0, rh.gs(R.string.clear_log)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||||
menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||||
|
@ -116,7 +105,6 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment {
|
||||||
private fun updateGui() {
|
private fun updateGui() {
|
||||||
if (_binding == null) return
|
if (_binding == null) return
|
||||||
binding.log.text = xdripPlugin.textLog()
|
binding.log.text = xdripPlugin.textLog()
|
||||||
if (sp.getBoolean(R.string.key_ns_client_autoscroll, true)) binding.logScrollview.fullScroll(ScrollView.FOCUS_DOWN)
|
|
||||||
val size = dataSyncSelector.queueSize()
|
val size = dataSyncSelector.queueSize()
|
||||||
binding.queue.text = if (size >= 0) size.toString() else rh.gs(info.nightscout.core.ui.R.string.value_unavailable_short)
|
binding.queue.text = if (size >= 0) size.toString() else rh.gs(info.nightscout.core.ui.R.string.value_unavailable_short)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,15 +44,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/paused" />
|
android:text="@string/paused" />
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/autoscroll"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="20dp"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:text="@string/ns_client_autoscroll"
|
|
||||||
tools:ignore="RtlHardcoded" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -14,15 +14,6 @@
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/autoscroll"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="20dp"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:text="@string/ns_client_autoscroll"
|
|
||||||
tools:ignore="RtlHardcoded" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
<string name="ns_malfunction">NSClient malfunction. Consider NS and NSClient restart.</string>
|
<string name="ns_malfunction">NSClient malfunction. Consider NS and NSClient restart.</string>
|
||||||
|
|
||||||
<!-- NSClient -->
|
<!-- NSClient -->
|
||||||
<string name="key_ns_client_autoscroll" translatable="false">ns_client_autoscroll</string>
|
|
||||||
<string name="key_ns_paused" translatable="false">ns_client_paused</string>
|
<string name="key_ns_paused" translatable="false">ns_client_paused</string>
|
||||||
<string name="key_ns_log_app_started_event" translatable="false">ns_log_app_started_event</string>
|
<string name="key_ns_log_app_started_event" translatable="false">ns_log_app_started_event</string>
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@
|
||||||
<string name="ns_client">NSClient</string>
|
<string name="ns_client">NSClient</string>
|
||||||
<string name="ns_client_short_name">NSCI</string>
|
<string name="ns_client_short_name">NSCI</string>
|
||||||
<string name="ns_client_url">URL:</string>
|
<string name="ns_client_url">URL:</string>
|
||||||
<string name="ns_client_autoscroll">Autoscroll</string>
|
|
||||||
<string name="restart">Restart</string>
|
<string name="restart">Restart</string>
|
||||||
<string name="ns_client_internal_title">NSClient</string>
|
<string name="ns_client_internal_title">NSClient</string>
|
||||||
<string name="ns_client_url_title">Nightscout URL</string>
|
<string name="ns_client_url_title">Nightscout URL</string>
|
||||||
|
|
Loading…
Reference in a new issue