From 2290776faf958901cea3fa9f9851436df1818e54 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Thu, 23 May 2024 19:49:46 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Updated=20default=20censorship?= =?UTF-8?q?=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed the default censorship for day, week, month, year and all time periods from true to false in the BlockRepository. Additionally updated the CensureIcon and BlockText Composables in UseBlock to correctly reflect their censorship states. Closes #581 Signed-off-by: Leonardo Colman Lopes --- .../main/kotlin/br/com/colman/petals/use/UseBlock.kt | 4 ++-- .../colman/petals/use/repository/BlockRepository.kt | 10 +++++----- .../petals/use/repository/BlockRepositoryTest.kt | 11 ++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt b/app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt index a47e4c65..5e94617c 100644 --- a/app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt +++ b/app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt @@ -152,11 +152,11 @@ private fun UseBlock( @Composable private fun CensureIcon(isCensored: Boolean) { - val chosenIcon = if (isCensored) TablerIcons.Eye else TablerIcons.EyeOff + val chosenIcon = if (isCensored) TablerIcons.EyeOff else TablerIcons.Eye Icon(chosenIcon, null, Modifier.size(18.dp)) } @Composable private fun BlockText(blockText: String, isCensored: Boolean) { - if (isCensored) Text(blockText) else Text(stringResource(R.string.censored)) + if (isCensored) Text(stringResource(R.string.censored)) else Text(blockText) } diff --git a/app/src/main/kotlin/br/com/colman/petals/use/repository/BlockRepository.kt b/app/src/main/kotlin/br/com/colman/petals/use/repository/BlockRepository.kt index 17480dd4..7b36ae71 100644 --- a/app/src/main/kotlin/br/com/colman/petals/use/repository/BlockRepository.kt +++ b/app/src/main/kotlin/br/com/colman/petals/use/repository/BlockRepository.kt @@ -17,11 +17,11 @@ import kotlinx.coroutines.runBlocking class BlockRepository( private val datastore: DataStore ) { - val isTodayCensored = datastore.data.map { it[Today.preferencesKey] ?: true } - val isThisWeekCensored = datastore.data.map { it[ThisWeek.preferencesKey] ?: true } - val isThisMonthCensored = datastore.data.map { it[ThisMonth.preferencesKey] ?: true } - val isThisYearCensored = datastore.data.map { it[ThisYear.preferencesKey] ?: true } - val isAllTimeCensored = datastore.data.map { it[AllTime.preferencesKey] ?: true } + val isTodayCensored = datastore.data.map { it[Today.preferencesKey] ?: false } + val isThisWeekCensored = datastore.data.map { it[ThisWeek.preferencesKey] ?: false } + val isThisMonthCensored = datastore.data.map { it[ThisMonth.preferencesKey] ?: false } + val isThisYearCensored = datastore.data.map { it[ThisYear.preferencesKey] ?: false } + val isAllTimeCensored = datastore.data.map { it[AllTime.preferencesKey] ?: false } fun setBlockCensure(blockType: BlockType, isCensored: Boolean): Unit = runBlocking { datastore.edit { it[blockType.preferencesKey] = isCensored } diff --git a/app/src/test/kotlin/br/com/colman/petals/use/repository/BlockRepositoryTest.kt b/app/src/test/kotlin/br/com/colman/petals/use/repository/BlockRepositoryTest.kt index 594def8b..38cb7d03 100644 --- a/app/src/test/kotlin/br/com/colman/petals/use/repository/BlockRepositoryTest.kt +++ b/app/src/test/kotlin/br/com/colman/petals/use/repository/BlockRepositoryTest.kt @@ -12,7 +12,7 @@ class BlockRepositoryTest : FunSpec({ val datastore: DataStore = PreferenceDataStoreFactory.create { tempfile(suffix = ".preferences_pb") } val target = BlockRepository(datastore) - test("Defaults block censor true") { + test("Defaults block censor to false") { BlockType.entries.forEach { blockType -> val isCensored = when (blockType) { BlockType.Today -> target.isTodayCensored.first() @@ -21,17 +21,18 @@ class BlockRepositoryTest : FunSpec({ BlockType.ThisYear -> target.isThisYearCensored.first() BlockType.AllTime -> target.isAllTimeCensored.first() } - isCensored shouldBe true + isCensored shouldBe false } } test("Changes today's block censure") { - target.setBlockCensure(BlockType.Today, false) target.isTodayCensored.first() shouldBe false + target.setBlockCensure(BlockType.Today, true) + target.isTodayCensored.first() shouldBe true } test("Persists specified block censure") { - target.setBlockCensure(BlockType.Today, false) - datastore.data.first()[BlockType.Today.preferencesKey] shouldBe false + target.setBlockCensure(BlockType.Today, true) + datastore.data.first()[BlockType.Today.preferencesKey] shouldBe true } })