From c7df607d9754e0f5a20cf06b30b0a7f1f6447215 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Wed, 20 May 2020 23:59:14 +0200 Subject: [PATCH] Some UI candy --- .../androidaps/db/DatabaseHelper.java | 25 +++++ .../general/openhumans/OpenHumansFragment.kt | 91 ++++++++++++++++++- .../openhumans/OpenHumansLoginActivity.kt | 8 +- .../general/openhumans/OpenHumansUploader.kt | 45 +++++---- app/src/main/res/drawable/open_humans.xml | 10 ++ .../res/layout/activity_open_humans_login.xml | 18 +++- .../main/res/layout/fragment_open_humans.xml | 67 ++++++++++++-- app/src/main/res/values/strings.xml | 7 ++ 8 files changed, 234 insertions(+), 37 deletions(-) create mode 100644 app/src/main/res/drawable/open_humans.xml diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 25c6939bbf..a041add2e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -2049,4 +2049,29 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } return Collections.emptyList(); } + + public long getOHQueueSize() { + try { + return getDaoOpenHumansQueue().countOf(); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return 0L; + } + + public long getCountOfAllRows() { + try { + return getDaoBgReadings().countOf() + + getDaoCareportalEvents().countOf() + + getDaoExtendedBolus().countOf() + + getDaoCareportalEvents().countOf() + + getDaoProfileSwitch().countOf() + + getDaoTDD().countOf() + + getDaoTemporaryBasal().countOf() + + getDaoTempTargets().countOf(); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return 0L; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt index 89ae94a813..347d08d008 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt @@ -6,18 +6,101 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button +import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer +import androidx.work.WorkInfo +import androidx.work.WorkManager +import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.events.Event +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.utils.plusAssign +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.schedulers.Schedulers +import java.util.concurrent.TimeUnit class OpenHumansFragment : Fragment() { + private var viewsCreated = false + private var login: Button? = null + private var logout: Button? = null + private var memberId: TextView? = null + private var queueSize: TextView? = null + private var workerState: TextView? = null + private var queueSizeValue = 0L + private val compositeDisposable = CompositeDisposable() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + compositeDisposable += RxBus.toObservable(UpdateQueueEvent::class.java) + .throttleLatest(5, TimeUnit.SECONDS) + .observeOn(Schedulers.io()) + .map { MainApp.getDbHelper().ohQueueSize } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + queueSizeValue = it + updateGUI() + } + compositeDisposable += RxBus.toObservable(UpdateViewEvent::class.java) + .observeOn(Schedulers.io()) + .map { MainApp.getDbHelper().ohQueueSize } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + queueSizeValue = it + updateGUI() + } + WorkManager.getInstance(MainApp.instance()).getWorkInfosForUniqueWorkLiveData(OpenHumansUploader.WORK_NAME).observe(this, Observer> { + val workInfo = it.lastOrNull() + if (workInfo == null) { + workerState?.visibility = View.GONE + } else { + workerState?.visibility = View.VISIBLE + workerState?.text = getString(R.string.worker_state, workInfo.state.toString()) + } + }) + } + + override fun onDestroy() { + compositeDisposable.clear() + super.onDestroy() + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { val view = inflater.inflate(R.layout.fragment_open_humans, container, false) - val button = view.findViewById