|
|
|
|
@ -73,50 +73,38 @@ class HistoryViewModel(application: Application) : AndroidViewModel(application)
|
|
|
|
|
repository = HistoryRepository(dao)
|
|
|
|
|
websites = repository.websites
|
|
|
|
|
|
|
|
|
|
val filters = listOf(dao.getAllHistory(), sortOrder, sortType, websiteFilter, statusFilter, queryFilter, typeFilter)
|
|
|
|
|
paginatedItems = combine(filters) { f ->
|
|
|
|
|
val sortOrder = f[1] as SORTING
|
|
|
|
|
val sortType = f[2] as HistorySortType
|
|
|
|
|
val website = f[3] as String
|
|
|
|
|
val status = f[4] as HistoryStatus
|
|
|
|
|
val query = f[5] as String
|
|
|
|
|
val type = f[6] as String
|
|
|
|
|
|
|
|
|
|
var pager = Pager(
|
|
|
|
|
val filtersFlow = combine(
|
|
|
|
|
combine(sortOrder, sortType, websiteFilter, ::Triple),
|
|
|
|
|
combine(statusFilter, queryFilter, typeFilter, ::Triple)
|
|
|
|
|
) { (order, sort, site), (status, query, type) ->
|
|
|
|
|
HistoryFilters(
|
|
|
|
|
sortOrder = order,
|
|
|
|
|
sortType = sort,
|
|
|
|
|
website = site,
|
|
|
|
|
status = status,
|
|
|
|
|
query = query,
|
|
|
|
|
type = type
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paginatedItems = filtersFlow.flatMapLatest { f ->
|
|
|
|
|
Pager(
|
|
|
|
|
config = PagingConfig(pageSize = 20, initialLoadSize = 20, prefetchDistance = 1),
|
|
|
|
|
pagingSourceFactory = {
|
|
|
|
|
repository.getPaginatedSource(query, type, website, sortType, sortOrder)
|
|
|
|
|
repository.getPaginatedSource(f.query, f.type, f.website, f.sortType, f.sortOrder)
|
|
|
|
|
}
|
|
|
|
|
).flow
|
|
|
|
|
|
|
|
|
|
when(status) {
|
|
|
|
|
HistoryStatus.DELETED -> {
|
|
|
|
|
pager = pager.map {
|
|
|
|
|
it.filter { it2 ->
|
|
|
|
|
it2.downloadPath.any { it3 ->
|
|
|
|
|
!FileUtil.exists(it3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
).flow.map { pagingData ->
|
|
|
|
|
when (f.status) {
|
|
|
|
|
HistoryStatus.DELETED -> pagingData.filter { item ->
|
|
|
|
|
item.downloadPath.any { !FileUtil.exists(it) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HistoryStatus.NOT_DELETED -> {
|
|
|
|
|
pager = pager.map {
|
|
|
|
|
it.filter { it2 ->
|
|
|
|
|
it2.downloadPath.any { it3 ->
|
|
|
|
|
FileUtil.exists(it3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HistoryStatus.NOT_DELETED -> pagingData.filter { item ->
|
|
|
|
|
item.downloadPath.any { FileUtil.exists(it) }
|
|
|
|
|
}
|
|
|
|
|
else -> pagingData
|
|
|
|
|
}
|
|
|
|
|
else -> {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
totalCount.value = repository.getFilteredIDs(query, type, website, sortType, sortOrder, status).count()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pager
|
|
|
|
|
}.flatMapLatest { it }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun setSorting(sort: HistorySortType){
|
|
|
|
|
|