updateGui to Rx
This commit is contained in:
parent
1cb0f27254
commit
e86094a250
3 changed files with 29 additions and 81 deletions
|
@ -1,22 +1,30 @@
|
||||||
package info.nightscout.androidaps.plugins.general.tidepool
|
package info.nightscout.androidaps.plugins.general.tidepool
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ScrollView
|
import android.widget.ScrollView
|
||||||
import com.squareup.otto.Subscribe
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI
|
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader
|
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData
|
||||||
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import kotlinx.android.synthetic.main.tidepool_fragment.*
|
import kotlinx.android.synthetic.main.tidepool_fragment.*
|
||||||
|
|
||||||
class TidepoolFragment : SubscriberFragment() {
|
class TidepoolFragment : Fragment() {
|
||||||
|
|
||||||
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
|
||||||
|
add(disposable)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.tidepool_fragment, container, false)
|
return inflater.inflate(R.layout.tidepool_fragment, container, false)
|
||||||
|
@ -28,21 +36,22 @@ class TidepoolFragment : SubscriberFragment() {
|
||||||
tidepool_uploadnow.setOnClickListener { RxBus.send(EventTidepoolDoUpload()) }
|
tidepool_uploadnow.setOnClickListener { RxBus.send(EventTidepoolDoUpload()) }
|
||||||
tidepool_removeall.setOnClickListener { RxBus.send(EventTidepoolResetData()) }
|
tidepool_removeall.setOnClickListener { RxBus.send(EventTidepoolResetData()) }
|
||||||
tidepool_resertstart.setOnClickListener { SP.putLong(R.string.key_tidepool_last_end, 0) }
|
tidepool_resertstart.setOnClickListener { SP.putLong(R.string.key_tidepool_last_end, 0) }
|
||||||
|
|
||||||
|
disposable.add(RxBus
|
||||||
|
.toObservable(EventTidepoolUpdateGUI::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.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)
|
||||||
|
}, {})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
override fun onStop() {
|
||||||
fun onStatusEvent(ev: EventNSClientUpdateGUI) {
|
super.onStop()
|
||||||
updateGUI()
|
disposable.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateGUI() {
|
|
||||||
this.activity?.runOnUiThread {
|
|
||||||
TidepoolPlugin.updateLog()
|
|
||||||
tidepool_log.text = TidepoolPlugin.textLog
|
|
||||||
tidepool_status.text = TidepoolUploader.connectionStatus.name
|
|
||||||
tidepool_log.text = TidepoolPlugin.textLog
|
|
||||||
tidepool_logscrollview.fullScroll(ScrollView.FOCUS_DOWN)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.tidepool;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ScrollView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader;
|
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData;
|
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
public class TidepoolJavaFragment extends SubscriberFragment {
|
|
||||||
private TextView logTextView;
|
|
||||||
private TextView statusTextView;
|
|
||||||
private ScrollView scrollView;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.tidepool_fragment, container, false);
|
|
||||||
|
|
||||||
view.findViewById(R.id.tidepool_login).setOnClickListener(v1 -> TidepoolUploader.INSTANCE.doLogin(false));
|
|
||||||
view.findViewById(R.id.tidepool_uploadnow).setOnClickListener(v2 -> RxBus.INSTANCE.send(new EventTidepoolDoUpload()));
|
|
||||||
view.findViewById(R.id.tidepool_removeall).setOnClickListener(v3 -> RxBus.INSTANCE.send(new EventTidepoolResetData()));
|
|
||||||
view.findViewById(R.id.tidepool_resertstart).setOnClickListener(v4 -> SP.putLong(R.string.key_tidepool_last_end, 0));
|
|
||||||
|
|
||||||
logTextView = view.findViewById(R.id.tidepool_log);
|
|
||||||
statusTextView = view.findViewById(R.id.tidepool_status);
|
|
||||||
scrollView = view.findViewById(R.id.tidepool_logscrollview);
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTidepoolUpdateGUI ignored) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
TidepoolPlugin.INSTANCE.updateLog();
|
|
||||||
statusTextView.setText(TidepoolUploader.INSTANCE.getConnectionStatus().name());
|
|
||||||
logTextView.setText(TidepoolPlugin.INSTANCE.getTextLog());
|
|
||||||
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ import android.text.Spanned
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
import info.nightscout.androidaps.events.EventNewBG
|
import info.nightscout.androidaps.events.EventNewBG
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
|
@ -13,6 +12,7 @@ import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader
|
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData
|
||||||
|
@ -122,7 +122,7 @@ object TidepoolPlugin : PluginBase(PluginDescription()
|
||||||
listLog.removeAt(0)
|
listLog.removeAt(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(EventTidepoolUpdateGUI())
|
RxBus.send(EventTidepoolUpdateGUI())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
|
|
Loading…
Reference in a new issue