NSC: fix issues with updating GUI

This commit is contained in:
Milos Kozak 2023-02-11 13:45:26 +01:00
parent 67fe7889aa
commit 2a9bc52a72
8 changed files with 8 additions and 55 deletions

View file

@ -20,7 +20,6 @@ import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.entities.UserEntry
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.db.PersistenceLayer
import info.nightscout.interfaces.logging.UserEntryLogger
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.databinding.NsClientFragmentBinding
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.EventNSClientUpdateGuiStatus
import info.nightscout.rx.AapsSchedulers
@ -98,11 +97,6 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment {
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)
}
binding.paused.isChecked = sp.getBoolean(R.string.key_ns_paused, false)
binding.paused.setOnCheckedChangeListener { _, isChecked ->
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() {
super.onResume()
disposable += rxBus
.toObservable(EventNSClientUpdateGuiInsert::class.java)
.toObservable(EventNSClientUpdateGuiData::class.java)
.observeOn(aapsSchedulers.main)
.subscribe(
{
logAdapter.notifyItemInserted(it.position)
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)
}
}
_binding?.recyclerview?.swapAdapter(RecyclerViewAdapter(nsClientPlugin?.listLog ?: arrayListOf()), true)
}, fabricPrivacy::logException
)
disposable += rxBus
@ -240,7 +226,6 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment {
private fun updateStatus() {
if (_binding == null) return
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.status.text = nsClientPlugin?.status
}

View file

@ -2,4 +2,4 @@ package info.nightscout.plugins.sync.nsShared.events
import info.nightscout.rx.events.EventUpdateGui
class EventNSClientUpdateGuiInsert(val position: Int) : EventUpdateGui()
class EventNSClientUpdateGuiData : EventUpdateGui()

View file

@ -29,7 +29,7 @@ import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.NSClientFragment
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
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.nsclient.data.AlarmAck
import info.nightscout.plugins.sync.nsclient.extensions.toJson
@ -160,11 +160,11 @@ class NSClientPlugin @Inject constructor(
private fun addToLog(ev: EventNSClientNewLog) {
synchronized(listLog) {
listLog.add(0, ev)
rxBus.send(EventNSClientUpdateGuiInsert(0))
// remove the first line if log is too large
if (listLog.size >= Constants.MAX_LOG_LINES) {
listLog.removeAt(listLog.size - 1)
}
rxBus.send(EventNSClientUpdateGuiData())
}
}

View file

@ -39,7 +39,7 @@ import info.nightscout.plugins.sync.nsShared.NSClientFragment
import info.nightscout.plugins.sync.nsShared.NsIncomingDataProcessor
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
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.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
@ -292,11 +292,11 @@ class NSClientV3Plugin @Inject constructor(
private fun addToLog(ev: EventNSClientNewLog) {
synchronized(listLog) {
listLog.add(0, ev)
rxBus.send(EventNSClientUpdateGuiInsert(0))
// remove the first line if log is too large
if (listLog.size >= Constants.MAX_LOG_LINES) {
listLog.removeAt(listLog.size - 1)
}
rxBus.send(EventNSClientUpdateGuiData())
}
}

View file

@ -7,7 +7,6 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.core.view.MenuProvider
import androidx.lifecycle.Lifecycle
import dagger.android.support.DaggerFragment
@ -62,16 +61,6 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment {
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
}.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) {
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)
@ -116,7 +105,6 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment {
private fun updateGui() {
if (_binding == null) return
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()
binding.queue.text = if (size >= 0) size.toString() else rh.gs(info.nightscout.core.ui.R.string.value_unavailable_short)
}

View file

@ -44,15 +44,6 @@
android:layout_height="wrap_content"
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

View file

@ -14,15 +14,6 @@
android:gravity="center_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

View file

@ -47,7 +47,6 @@
<string name="ns_malfunction">NSClient malfunction. Consider NS and NSClient restart.</string>
<!-- 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_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_short_name">NSCI</string>
<string name="ns_client_url">URL:</string>
<string name="ns_client_autoscroll">Autoscroll</string>
<string name="restart">Restart</string>
<string name="ns_client_internal_title">NSClient</string>
<string name="ns_client_url_title">Nightscout URL</string>