diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt index 5bc3ceadce..b4476d3722 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/DataSyncSelectorXdripImpl.kt @@ -150,21 +150,21 @@ class DataSyncSelectorXdripImpl @Inject constructor( private fun sendEntries(force: Boolean, progress: String) { if (preparedEntries.isNotEmpty() && (preparedEntries.size >= 100 || force)) { - xdripPlugin.sendToXdrip("entries", preparedEntries, progress) + xdripPlugin.sendToXdrip("entries", preparedEntries.toList(), progress) preparedEntries.clear() } } private fun sendTreatments(force: Boolean, progress: String) { if (preparedTreatments.isNotEmpty() && (preparedTreatments.size >= 100 || force)) { - xdripPlugin.sendToXdrip("treatments", preparedTreatments, progress) + xdripPlugin.sendToXdrip("treatments", preparedTreatments.toList(), progress) preparedTreatments.clear() } } private fun sendFoods(force: Boolean, progress: String) { if (preparedFoods.isNotEmpty() && (preparedFoods.size >= 100 || force)) { - xdripPlugin.sendToXdrip("food", preparedFoods, progress) + xdripPlugin.sendToXdrip("food", preparedFoods.toList(), progress) preparedFoods.clear() } } 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 ea20db536b..7e838af329 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 @@ -1,6 +1,8 @@ package info.nightscout.plugins.sync.xdrip import android.os.Bundle +import android.os.Handler +import android.os.HandlerThread import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -48,6 +50,7 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment { override var plugin: PluginBase? = null private val disposable = CompositeDisposable() + private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private var _binding: XdripFragmentBinding? = null @@ -78,7 +81,7 @@ class XdripFragment : DaggerFragment(), MenuProvider, PluginFragment { context?.let { context -> OKDialog.showConfirmation( context, rh.gs(R.string.ns_client), rh.gs(R.string.full_sync_comment), - Thread { dataSyncSelector.resetToNextFullSync() } + Runnable { handler.post { dataSyncSelector.resetToNextFullSync() } } ) } true diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripPlugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripPlugin.kt index 6b9149f5bc..c2a5d9a91f 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripPlugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/XdripPlugin.kt @@ -362,7 +362,7 @@ class XdripPlugin @Inject constructor( private fun sendEntries(dataPairs: List, progress: String) { val array = JSONArray() - for (dataPair in dataPairs.toList()) { + for (dataPair in dataPairs) { val data = (dataPair as DataSyncSelector.PairGlucoseValue).value.toXdripJson() array.put(data) } @@ -376,7 +376,7 @@ class XdripPlugin @Inject constructor( private fun sendFood(dataPairs: List, progress: String) { val array = JSONArray() - for (dataPair in dataPairs.toList()) { + for (dataPair in dataPairs) { val data = (dataPair as DataSyncSelector.PairFood).value.toJson(true) array.put(data) } @@ -390,7 +390,7 @@ class XdripPlugin @Inject constructor( private fun sendTreatments(dataPairs: List, progress: String) { val array = JSONArray() - for (dataPair in dataPairs.toList()) { + for (dataPair in dataPairs) { when (dataPair) { is DataSyncSelector.PairBolus -> dataPair.value.toJson(true, dateUtil) is DataSyncSelector.PairCarbs -> dataPair.value.toJson(true, dateUtil)