Add dao for Fragment
This commit is contained in:
parent
38fb53b4ce
commit
442e64e3f0
3 changed files with 23 additions and 10 deletions
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
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.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.Translator
|
import info.nightscout.androidaps.utils.Translator
|
||||||
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
|
@ -48,6 +49,9 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
private val millsToThePastFiltered = T.days(30).msecs()
|
||||||
|
private val millsToThePastUnFiltered = T.days(3).msecs()
|
||||||
|
|
||||||
private var _binding: TreatmentsUserEntryFragmentBinding? = null
|
private var _binding: TreatmentsUserEntryFragmentBinding? = null
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
// This property is only valid between onCreateView and
|
||||||
|
@ -75,17 +79,18 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun swapAdapter() {
|
fun swapAdapter() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
if (binding.showLoop.isChecked)
|
if (binding.showLoop.isChecked)
|
||||||
disposable.add( repository
|
disposable.add( repository
|
||||||
.getAllUserEntries()
|
.getUserEntryDataFromTime(now - millsToThePastUnFiltered)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) }
|
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) }
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
disposable.add( repository
|
disposable.add( repository
|
||||||
.getAllUserEntries()
|
.getUserEntryFilteredDataFromTime(now - millsToThePastFiltered)
|
||||||
.observeOn(aapsSchedulers.main)
|
.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
|
override fun getItemCount(): Int = entries.size
|
||||||
}
|
}
|
||||||
|
|
||||||
fun filterUserEntries(list: List<UserEntry>): List<UserEntry> {
|
|
||||||
val filteredList = mutableListOf<UserEntry>()
|
|
||||||
for (ue in list) {
|
|
||||||
if (! ue.source.equals(Sources.Loop)) filteredList.add(ue)
|
|
||||||
}
|
|
||||||
return filteredList
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -157,6 +157,14 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.userEntryDao.getAll()
|
database.userEntryDao.getAll()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>> =
|
||||||
|
database.userEntryDao.getUserEntryDataFromTime(timestamp)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getUserEntryFilteredDataFromTime(timestamp: Long): Single<List<UserEntry>> =
|
||||||
|
database.userEntryDao.getUserEntryFilteredDataFromTime(UserEntry.Sources.Loop, timestamp)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun insert(word: UserEntry) {
|
fun insert(word: UserEntry) {
|
||||||
database.userEntryDao.insert(word)
|
database.userEntryDao.insert(word)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import androidx.room.Insert
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
|
@ -16,4 +17,10 @@ interface UserEntryDao {
|
||||||
@Query("SELECT * FROM $TABLE_USER_ENTRY ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_USER_ENTRY ORDER BY id DESC")
|
||||||
fun getAll(): Single<List<UserEntry>>
|
fun getAll(): Single<List<UserEntry>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp ORDER BY id DESC")
|
||||||
|
fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp AND source != :excludeSource ORDER BY id DESC")
|
||||||
|
fun getUserEntryFilteredDataFromTime(excludeSource: Sources, timestamp: Long): Single<List<UserEntry>>
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue