From 02098a7aa982458a0fcbcc25b0fb69c78a031e03 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 11 Oct 2022 00:52:12 +0200 Subject: [PATCH] Rearrange filtering steps --- .../repository/RepositoryImpl.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 124c385..4c7a03d 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -66,16 +66,19 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap } else { if (appSettingsService.isItemCachingEnabled()) { fromDB = true + val dbItems = getDBItems().filter { + displayedItems == ItemType.ALL || + (it.unread && displayedItems == ItemType.UNREAD) || + (it.starred && displayedItems == ItemType.STARRED) + } + if (tagFilter != null) { + dbItems.filter { it.tags.contains(tagFilter!!.tag) } + } + if (sourceFilter != null) { + dbItems.filter { it.sourcetitle == sourceFilter!!.title } + } fetchedItems = SelfossModel.StatusAndData.succes( - getDBItems().filter { - displayedItems == ItemType.ALL || - (it.unread && displayedItems == ItemType.UNREAD) || - (it.starred && displayedItems == ItemType.STARRED) - }.filter { - tagFilter == null || it.tags.contains(tagFilter!!.tag) - }.filter { - sourceFilter == null || it.sourcetitle == sourceFilter!!.title - }.map { it.toView() } + dbItems.map { it.toView() } ) } }