From fe128191630fb57387c5d46e819e13adcf5a1b6a Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 8 Oct 2022 17:14:12 +0200 Subject: [PATCH 1/6] Correct database source title --- .../bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt index 9407a79..e6e2a81 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt @@ -65,6 +65,6 @@ fun SelfossModel.Item.toEntity(): ITEM = this.thumbnail, this.icon, this.link, - this.title.getHtmlDecoded(), + this.sourcetitle.getHtmlDecoded(), this.tags.joinToString(",") ) \ No newline at end of file -- 2.34.1 From 1d1c121aab6c1f50350f9940ea045152d8090319 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 8 Oct 2022 17:15:22 +0200 Subject: [PATCH 2/6] Filter items from database according to tag and source --- .../apps/readerforselfossv2/repository/RepositoryImpl.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 f2635eb..124c385 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 @@ -71,6 +71,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap 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() } ) } -- 2.34.1 From d0a982f385ca6e74ac740498a2291b6711330931 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 8 Oct 2022 17:15:41 +0200 Subject: [PATCH 3/6] Add tests for offline filtering --- .../repository/RepositoryTest.kt | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index decac9d..b1cc19e 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -173,6 +173,60 @@ class RepositoryTest() { verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} } + @Test + fun `Get newer items without connectivity and tag filter`() { + val itemParameter1 = FakeItemParameters() + val itemParameter2 = FakeItemParameters() + val itemParameter3 = FakeItemParameters() + itemParameter2.tags = "Test, Stuff" + itemParameter3.tags = "Other, Tag" + coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( + generateTestDBItems(itemParameter1), + generateTestDBItems(itemParameter2), + generateTestDBItems(itemParameter3) + ) + + every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) + every { appSettingsService.isItemCachingEnabled() } returns true + + val repository = Repository(api, appSettingsService, connectivityStatus, db) + repository.tagFilter = SelfossModel.Tag("Test", "red", 3) + runBlocking { + repository.getNewerItems() + } + + assertSame(repository.items.size, 1) + coVerify(exactly = 0) { api.getItems("unread", 0, null, null, null, null, any()) } + verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} + } + + @Test + fun `Get newer items without connectivity and source filter`() { + val itemParameter1 = FakeItemParameters() + val itemParameter2 = FakeItemParameters() + val itemParameter3 = FakeItemParameters() + itemParameter2.sourcetitle = "Test" + itemParameter3.sourcetitle = "Other" + coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( + generateTestDBItems(itemParameter1), + generateTestDBItems(itemParameter2), + generateTestDBItems(itemParameter3) + ) + + every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) + every { appSettingsService.isItemCachingEnabled() } returns true + + val repository = Repository(api, appSettingsService, connectivityStatus, db) + repository.sourceFilter = SelfossModel.Source(1, "Test", listOf("tags"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png") + runBlocking { + repository.getNewerItems() + } + + assertSame(repository.items.size, 1) + coVerify(exactly = 0) { api.getItems("unread", 0, null, null, null, null, any()) } + verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} + } + @Test fun `Get older items`() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns @@ -998,6 +1052,6 @@ class FakeItemParameters() { val thumbnail = null val icon = "ba79e238383ce83c23a169929c8906ef.png" val link = "https://ilblogdellasci.wordpress.com/2022/09/09/etica-della-ricerca-sotto-i-riflettori/" - val sourcetitle = "La Chimica e la Società" - val tags = "Chimica, Testing" + var sourcetitle = "La Chimica e la Società" + var tags = "Chimica, Testing" } \ No newline at end of file -- 2.34.1 From 02098a7aa982458a0fcbcc25b0fb69c78a031e03 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 11 Oct 2022 00:52:12 +0200 Subject: [PATCH 4/6] 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() } ) } } -- 2.34.1 From 208babbce32f9bac2484c8070bd4b08006e0a8f2 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 14 Oct 2022 00:03:20 +0200 Subject: [PATCH 5/6] Correct tests --- .../repository/RepositoryTest.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index b1cc19e..61109d5 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -179,12 +179,12 @@ class RepositoryTest() { val itemParameter2 = FakeItemParameters() val itemParameter3 = FakeItemParameters() itemParameter2.tags = "Test, Stuff" + itemParameter2.id = "2" itemParameter3.tags = "Other, Tag" - coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( - generateTestDBItems(itemParameter1), - generateTestDBItems(itemParameter2), + itemParameter3.id = "3" + coEvery { db.itemsQueries.items().executeAsList() } returns generateTestDBItems(itemParameter1) + + generateTestDBItems(itemParameter2) + generateTestDBItems(itemParameter3) - ) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true @@ -206,12 +206,12 @@ class RepositoryTest() { val itemParameter2 = FakeItemParameters() val itemParameter3 = FakeItemParameters() itemParameter2.sourcetitle = "Test" + itemParameter2.id = "2" itemParameter3.sourcetitle = "Other" - coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( - generateTestDBItems(itemParameter1), - generateTestDBItems(itemParameter2), - generateTestDBItems(itemParameter3) - ) + itemParameter3.id = "3" + coEvery { db.itemsQueries.items().executeAsList() } returns generateTestDBItems(itemParameter1) + + generateTestDBItems(itemParameter2) + + generateTestDBItems(itemParameter3) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true -- 2.34.1 From 8bfe14c01944afef1fcae13875a1777c1db2b419 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 14 Oct 2022 00:10:35 +0200 Subject: [PATCH 6/6] Actually filter database items --- .../apps/readerforselfossv2/repository/RepositoryImpl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 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 4c7a03d..e0ae5e0 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,16 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap } else { if (appSettingsService.isItemCachingEnabled()) { fromDB = true - val dbItems = getDBItems().filter { + var 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) } + dbItems = dbItems.filter { it.tags.split(',').contains(tagFilter!!.tag) } } if (sourceFilter != null) { - dbItems.filter { it.sourcetitle == sourceFilter!!.title } + dbItems = dbItems.filter { it.sourcetitle == sourceFilter!!.title } } fetchedItems = SelfossModel.StatusAndData.succes( dbItems.map { it.toView() } -- 2.34.1