From 2a9bc52a724a61cdbecc40bb352d6a6e553070d8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 11 Feb 2023 13:45:26 +0100 Subject: [PATCH] NSC: fix issues with updating GUI --- .../plugins/sync/nsShared/NSClientFragment.kt | 21 +++---------------- ...nsert.kt => EventNSClientUpdateGuiData.kt} | 2 +- .../plugins/sync/nsclient/NSClientPlugin.kt | 4 ++-- .../sync/nsclientV3/NSClientV3Plugin.kt | 4 ++-- .../plugins/sync/xdrip/XdripFragment.kt | 12 ----------- .../main/res/layout/ns_client_fragment.xml | 9 -------- .../src/main/res/layout/xdrip_fragment.xml | 9 -------- plugins/sync/src/main/res/values/strings.xml | 2 -- 8 files changed, 8 insertions(+), 55 deletions(-) rename plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/{EventNSClientUpdateGuiInsert.kt => EventNSClientUpdateGuiData.kt} (58%) diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NSClientFragment.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NSClientFragment.kt index 1066836576..3efa325dd4 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NSClientFragment.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NSClientFragment.kt @@ -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 } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiInsert.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiData.kt similarity index 58% rename from plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiInsert.kt rename to plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiData.kt index a7a66fda5c..1b2f2ed858 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiInsert.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/events/EventNSClientUpdateGuiData.kt @@ -2,4 +2,4 @@ package info.nightscout.plugins.sync.nsShared.events import info.nightscout.rx.events.EventUpdateGui -class EventNSClientUpdateGuiInsert(val position: Int) : EventUpdateGui() \ No newline at end of file +class EventNSClientUpdateGuiData : EventUpdateGui() \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt index 4ca26cb0e0..01421ddc4a 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt @@ -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()) } } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt index 4f2c1cc477..d9bd1abcc8 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -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()) } } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripFragment.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripFragment.kt index a52ea25e47..5502011cc3 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripFragment.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripFragment.kt @@ -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) } diff --git a/plugins/sync/src/main/res/layout/ns_client_fragment.xml b/plugins/sync/src/main/res/layout/ns_client_fragment.xml index aef12ce167..9720ddd1eb 100644 --- a/plugins/sync/src/main/res/layout/ns_client_fragment.xml +++ b/plugins/sync/src/main/res/layout/ns_client_fragment.xml @@ -44,15 +44,6 @@ android:layout_height="wrap_content" android:text="@string/paused" /> - - - - NSClient malfunction. Consider NS and NSClient restart. - ns_client_autoscroll ns_client_paused ns_log_app_started_event @@ -57,7 +56,6 @@ NSClient NSCI URL: - Autoscroll Restart NSClient Nightscout URL