diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt index 084b4c5cd3..e67a367790 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt @@ -23,6 +23,7 @@ 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.FabricPrivacy +import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.UserEntryPresentationHelper import info.nightscout.androidaps.utils.alertDialogs.OKDialog @@ -48,6 +49,9 @@ class TreatmentsUserEntryFragment : DaggerFragment() { private val disposable = CompositeDisposable() + private val millsToThePastFiltered = T.days(30).msecs() + private val millsToThePastUnFiltered = T.days(3).msecs() + private var _binding: TreatmentsUserEntryFragmentBinding? = null // This property is only valid between onCreateView and @@ -75,17 +79,18 @@ class TreatmentsUserEntryFragment : DaggerFragment() { } fun swapAdapter() { + val now = System.currentTimeMillis() if (binding.showLoop.isChecked) disposable.add( repository - .getAllUserEntries() + .getUserEntryDataFromTime(now - millsToThePastUnFiltered) .observeOn(aapsSchedulers.main) .subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) } ) else disposable.add( repository - .getAllUserEntries() + .getUserEntryFilteredDataFromTime(now - millsToThePastFiltered) .observeOn(aapsSchedulers.main) - .subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(filterUserEntries(list)), true) } + .subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) } ) } @@ -145,11 +150,4 @@ class TreatmentsUserEntryFragment : DaggerFragment() { override fun getItemCount(): Int = entries.size } - fun filterUserEntries(list: List): List { - val filteredList = mutableListOf() - for (ue in list) { - if (! ue.source.equals(Sources.Loop)) filteredList.add(ue) - } - return filteredList - } } \ No newline at end of file diff --git a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt index 1e866dee24..58bd510d7b 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt @@ -157,6 +157,14 @@ open class AppRepository @Inject internal constructor( database.userEntryDao.getAll() .subscribeOn(Schedulers.io()) + fun getUserEntryDataFromTime(timestamp: Long): Single> = + database.userEntryDao.getUserEntryDataFromTime(timestamp) + .subscribeOn(Schedulers.io()) + + fun getUserEntryFilteredDataFromTime(timestamp: Long): Single> = + database.userEntryDao.getUserEntryFilteredDataFromTime(UserEntry.Sources.Loop, timestamp) + .subscribeOn(Schedulers.io()) + fun insert(word: UserEntry) { database.userEntryDao.insert(word) } diff --git a/database/src/main/java/info/nightscout/androidaps/database/daos/UserEntryDao.kt b/database/src/main/java/info/nightscout/androidaps/database/daos/UserEntryDao.kt index adb712f0e4..91e0add323 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/daos/UserEntryDao.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/daos/UserEntryDao.kt @@ -5,6 +5,7 @@ import androidx.room.Insert import androidx.room.Query import info.nightscout.androidaps.database.TABLE_USER_ENTRY import info.nightscout.androidaps.database.entities.UserEntry +import info.nightscout.androidaps.database.entities.UserEntry.Sources import io.reactivex.Single @Dao @@ -16,4 +17,10 @@ interface UserEntryDao { @Query("SELECT * FROM $TABLE_USER_ENTRY ORDER BY id DESC") fun getAll(): Single> + @Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp ORDER BY id DESC") + fun getUserEntryDataFromTime(timestamp: Long): Single> + + @Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp AND source != :excludeSource ORDER BY id DESC") + fun getUserEntryFilteredDataFromTime(excludeSource: Sources, timestamp: Long): Single> + } \ No newline at end of file