Add Filter to hide Loop entries

I didn't find an easy way to filter with SQL query, so I filtered manually the list, probably not the best solution...
This commit is contained in:
Philoul 2021-03-25 23:47:03 +01:00
parent 854715955a
commit b329971d9a
3 changed files with 69 additions and 11 deletions

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
@ -28,6 +29,7 @@ import info.nightscout.androidaps.utils.extensions.*
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
class TreatmentsUserEntryFragment : DaggerFragment() { class TreatmentsUserEntryFragment : DaggerFragment() {
@ -66,14 +68,24 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
} }
} }
} }
binding.showLoop.setOnCheckedChangeListener { _, _ ->
rxBus.send(EventTreatmentUpdateGui())
}
} }
fun swapAdapter() { fun swapAdapter() {
if (binding.showLoop.isChecked)
disposable.add( repository disposable.add( repository
.getAllUserEntries() .getAllUserEntries()
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) } .subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) }
) )
else
disposable.add( repository
.getAllUserEntries()
.observeOn(aapsSchedulers.main)
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(filterUserEntries(list)), true) }
)
} }
@Synchronized @Synchronized
@ -85,6 +97,11 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ swapAdapter() }, fabricPrivacy::logException)) .subscribe({ swapAdapter() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentUpdateGui::class.java)
.observeOn(aapsSchedulers.io)
.debounce(1L, TimeUnit.SECONDS)
.subscribe({ swapAdapter() }, fabricPrivacy::logException))
} }
@Synchronized @Synchronized
@ -165,6 +182,13 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
} }
override fun getItemCount(): Int = entries.size override fun getItemCount(): Int = entries.size
}
fun filterUserEntries(list: List<UserEntry>): List<UserEntry> {
val filteredList = mutableListOf<UserEntry>()
for (ue in list) {
if (! ue.isLoop()) filteredList.add(ue)
}
return filteredList
} }
} }

View file

@ -1,19 +1,45 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment"> tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.ui.SingleClickButton <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/ue_export_to_xml" android:id="@+id/ue_export_to_xml"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:drawableStart="@drawable/ic_header_export" android:drawableStart="@drawable/ic_header_export"
android:text="@string/ue_export_to_csv" /> android:text="@string/ue_export_to_csv" />
<CheckBox
android:id="@+id/show_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:checked="false"
android:paddingEnd="5dp"
tools:ignore="RtlSymmetry" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:contentDescription="@string/show_calculation"
app:srcCompat="@drawable/ic_loop_closed_white" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview" android:id="@+id/recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -180,4 +180,12 @@ data class UserEntry(
Pump, Pump,
Aaps Aaps
} }
fun isLoop(): Boolean {
var result = false
for (v in values) {
if (v.unit == Units.Source && Sources.fromText(v.sValue).equals(Sources.Loop)) result = true
}
return result
}
} }