Skip to content

Commit

Permalink
🚚 Rename BlockRepository to CensorshipRepository
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Colman Lopes <[email protected]>
  • Loading branch information
LeoColman committed Oct 25, 2024
1 parent 364f377 commit 4a318cc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.test.swipeUp
import br.com.colman.kotest.FunSpec
import br.com.colman.petals.navigation.Page
import br.com.colman.petals.use.io.input.UseImporter
import br.com.colman.petals.use.repository.BlockRepository
import br.com.colman.petals.use.repository.CensorshipRepository
import br.com.colman.petals.use.repository.BlockType
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FileDataPart
Expand Down Expand Up @@ -60,8 +60,8 @@ class ScreenshotTakerTest : FunSpec({
locales.forEach { (lang, country) ->
activity?.setLocale(Locale(lang, country))

val blockRepository by koin.inject<BlockRepository>()
blockRepository.setBlockCensure(BlockType.Today, true)
val censorshipRepository by koin.inject<CensorshipRepository>()
censorshipRepository.setBlockCensure(BlockType.Today, true)

waitForIdle()
takeScreenshot("1.png", lang, country)
Expand All @@ -76,8 +76,8 @@ class ScreenshotTakerTest : FunSpec({
locales.forEach { (lang, country) ->
activity?.setLocale(Locale(lang, country))

val blockRepository by koin.inject<BlockRepository>()
blockRepository.setBlockCensure(BlockType.Today, true)
val censorshipRepository by koin.inject<CensorshipRepository>()
censorshipRepository.setBlockCensure(BlockType.Today, true)

waitForIdle()

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/br/com/colman/petals/KoinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import br.com.colman.petals.hittimer.HitTimerRepository
import br.com.colman.petals.settings.SettingsMigrations
import br.com.colman.petals.settings.SettingsRepository
import br.com.colman.petals.use.pause.repository.PauseRepository
import br.com.colman.petals.use.repository.BlockRepository
import br.com.colman.petals.use.repository.CensorshipRepository
import br.com.colman.petals.use.repository.UseRepository
import org.koin.dsl.module

Expand All @@ -37,5 +37,5 @@ val KoinModule = module {
single { HitTimerRepository(get()) }
single { SettingsRepository(get<Context>().settingsDatastore) }
single { SettingsMigrations(get<Context>().settingsDatastore) }
single { BlockRepository(get<Context>().blockDataStore) }
single { CensorshipRepository(get<Context>().blockDataStore) }
}
18 changes: 9 additions & 9 deletions app/src/main/kotlin/br/com/colman/petals/use/UseBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import androidx.compose.ui.unit.dp
import br.com.colman.petals.R
import br.com.colman.petals.R.string.amount_grams_short
import br.com.colman.petals.settings.SettingsRepository
import br.com.colman.petals.use.repository.BlockRepository
import br.com.colman.petals.use.repository.CensorshipRepository
import br.com.colman.petals.use.repository.BlockType
import br.com.colman.petals.use.repository.BlockType.AllTime
import br.com.colman.petals.use.repository.BlockType.ThisMonth
Expand All @@ -73,14 +73,14 @@ import java.time.LocalTime

@Composable
fun StatsBlocks(uses: List<Use>) {
val blockRepository = koinInject<BlockRepository>()
val censorshipRepository = koinInject<CensorshipRepository>()
val settingsRepository = koinInject<SettingsRepository>()

val isTodayCensored by blockRepository.isTodayCensored.collectAsState(true)
val isThisWeekCensored by blockRepository.isThisWeekCensored.collectAsState(true)
val isThisMonthCensored by blockRepository.isThisMonthCensored.collectAsState(true)
val isThisYearCensored by blockRepository.isThisYearCensored.collectAsState(true)
val isAllTimeCensored by blockRepository.isAllTimeCensored.collectAsState(true)
val isTodayCensored by censorshipRepository.isTodayCensored.collectAsState(true)
val isThisWeekCensored by censorshipRepository.isThisWeekCensored.collectAsState(true)
val isThisMonthCensored by censorshipRepository.isThisMonthCensored.collectAsState(true)
val isThisYearCensored by censorshipRepository.isThisYearCensored.collectAsState(true)
val isAllTimeCensored by censorshipRepository.isAllTimeCensored.collectAsState(true)
val isDayExtended by settingsRepository.isDayExtended.collectAsState(false)

Row(Modifier.horizontalScroll(rememberScrollState()).width(Max).testTag("StatsBlockMainRow")) {
Expand Down Expand Up @@ -133,15 +133,15 @@ private fun UseBlock(
isCensored: Boolean = true
) {
val settingsRepository = koinInject<SettingsRepository>()
val blockRepository = koinInject<BlockRepository>()
val censorshipRepository = koinInject<CensorshipRepository>()

val currencyIcon by settingsRepository.currencyIcon.collectAsState("$")

Card(modifier.padding(8.dp).defaultMinSize(145.dp), elevation = 4.dp) {
Column(Modifier.padding(8.dp), spacedBy(4.dp)) {
Row(Modifier.padding(8.dp).fillMaxWidth(), Center, CenterVertically) {
Text(stringResource(blockType.resourceId), fontWeight = Bold)
IconButton({ blockRepository.setBlockCensure(blockType, !isCensored) }) {
IconButton({ censorshipRepository.setBlockCensure(blockType, !isCensored) }) {
CensureIcon(isCensored)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import br.com.colman.petals.use.repository.BlockType.Today
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking

class BlockRepository(
class CensorshipRepository(
private val datastore: DataStore<Preferences>
) {
val isTodayCensored = datastore.data.map { it[Today.preferencesKey] ?: false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import io.kotest.engine.spec.tempfile
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.flow.first

class BlockRepositoryTest : FunSpec({
class CensorshipRepositoryTest : FunSpec({
val datastore: DataStore<Preferences> = PreferenceDataStoreFactory.create { tempfile(suffix = ".preferences_pb") }
val target = BlockRepository(datastore)
val target = CensorshipRepository(datastore)

test("Defaults block censor to false") {
BlockType.entries.forEach { blockType ->
Expand Down

0 comments on commit 4a318cc

Please sign in to comment.