Skip to content

Commit

Permalink
🐛 Updated default censorship settings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
LeoColman committed May 23, 2024
1 parent 7161a3d commit 2290776
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import kotlinx.coroutines.runBlocking
class BlockRepository(
private val datastore: DataStore<Preferences>
) {
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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BlockRepositoryTest : FunSpec({
val datastore: DataStore<Preferences> = 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()
Expand All @@ -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
}
})

0 comments on commit 2290776

Please sign in to comment.