From 026d6039dc5945156c49638d9fb0e083a53392b4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 2 Feb 2021 21:04:44 +0100 Subject: [PATCH] SmsCommunicatorOtpActivity -> jetpack --- .../general/tidepool/TidepoolFragment.kt | 37 ++++++++++++++----- app/src/main/res/layout/tidepool_fragment.xml | 30 +++++++-------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt index e11ee70a93..a3ac2622df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import android.widget.ScrollView import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.TidepoolFragmentBinding import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload @@ -29,16 +30,23 @@ class TidepoolFragment : DaggerFragment() { private var disposable: CompositeDisposable = CompositeDisposable() - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.tidepool_fragment, container, false) + private var _binding: TidepoolFragmentBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + _binding = TidepoolFragmentBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - tidepool_login.setOnClickListener { tidepoolUploader.doLogin(false) } - tidepool_uploadnow.setOnClickListener { rxBus.send(EventTidepoolDoUpload()) } - tidepool_removeall.setOnClickListener { rxBus.send(EventTidepoolResetData()) } - tidepool_resertstart.setOnClickListener { sp.putLong(R.string.key_tidepool_last_end, 0) } + binding.login.setOnClickListener { tidepoolUploader.doLogin(false) } + binding.uploadnow.setOnClickListener { rxBus.send(EventTidepoolDoUpload()) } + binding.removeall.setOnClickListener { rxBus.send(EventTidepoolResetData()) } + binding.resertstart.setOnClickListener { sp.putLong(R.string.key_tidepool_last_end, 0) } } @Synchronized @@ -48,11 +56,12 @@ class TidepoolFragment : DaggerFragment() { .toObservable(EventTidepoolUpdateGUI::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ + if (_binding == null) return@subscribe tidepoolPlugin.updateLog() - tidepool_log?.text = tidepoolPlugin.textLog - tidepool_status?.text = tidepoolUploader.connectionStatus.name - tidepool_log?.text = tidepoolPlugin.textLog - tidepool_logscrollview?.fullScroll(ScrollView.FOCUS_DOWN) + binding.log.text = tidepoolPlugin.textLog + binding.status.text = tidepoolUploader.connectionStatus.name + binding.log.text = tidepoolPlugin.textLog + binding.logscrollview.fullScroll(ScrollView.FOCUS_DOWN) }, { fabricPrivacy.logException(it) }) } @@ -61,4 +70,12 @@ class TidepoolFragment : DaggerFragment() { super.onPause() disposable.clear() } + + @Synchronized + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + } diff --git a/app/src/main/res/layout/tidepool_fragment.xml b/app/src/main/res/layout/tidepool_fragment.xml index 2640e96893..ef426f3f1a 100644 --- a/app/src/main/res/layout/tidepool_fragment.xml +++ b/app/src/main/res/layout/tidepool_fragment.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent">