Skip to content

Commit

Permalink
♻️ Refactor a bit the Symptoms page
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Colman Lopes <dev@leonardo.colman.com.br>
  • Loading branch information
LeoColman committed Dec 28, 2024
1 parent be6a1b0 commit be00d0b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
23 changes: 12 additions & 11 deletions app/src/main/kotlin/br/com/colman/petals/KoinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ import org.koin.dsl.module
private val Context.settingsDatastore by preferencesDataStore("settings")
private val Context.blockDataStore by preferencesDataStore("block")

val KoinModule = module {
includes(AndroidModule, SqlDelightModule)
includes(UseIOModules)

single { UseRepository(get<Database>().useQueries) }
single { PauseRepository(get<Database>().pauseQueries) }
single { HitTimerRepository(get()) }
single { SettingsRepository(get<Context>().settingsDatastore) }
single { SettingsMigrations(get<Context>().settingsDatastore) }
single { CensorshipRepository(get<Context>().blockDataStore) }
}

private val AndroidModule = module {
single { get<Context>().resources }
Expand All @@ -58,3 +47,15 @@ private val SqlDelightModule = module {
}
single { Database(get()) }
}

val KoinModule = module {
includes(AndroidModule, SqlDelightModule)
includes(UseIOModules)

single { UseRepository(get<Database>().useQueries) }
single { PauseRepository(get<Database>().pauseQueries) }
single { HitTimerRepository(get()) }
single { SettingsRepository(get<Context>().settingsDatastore) }
single { SettingsMigrations(get<Context>().settingsDatastore) }
single { CensorshipRepository(get<Context>().blockDataStore) }
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/br/com/colman/petals/navigation/Page.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import br.com.colman.petals.hittimer.ComposeHitTimer
import br.com.colman.petals.navigation.Page.Usage
import br.com.colman.petals.settings.SettingsView
import br.com.colman.petals.statistics.StatisticsPage
import br.com.colman.petals.withdrawal.Symptoms
import br.com.colman.petals.withdrawal.SymptomsPage
import org.koin.compose.koinInject

enum class Page(
Expand All @@ -56,7 +56,7 @@ enum class Page(
) {
Usage(R.string.usage, { ImageVector.vectorResource(ic_cannabis) }, { Usage() }),
HitTimer(R.string.hit_timer, { Default.LockClock }, { ComposeHitTimer() }),
Symptoms(R.string.symptoms, { Default.MedicalServices }, { Symptoms() }),
Symptoms(R.string.symptoms, { Default.MedicalServices }, { SymptomsPage() }),
Stats(R.string.stats, { Default.GraphicEq }, { StatisticsPage(koinInject(), koinInject()) })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,32 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import br.com.colman.petals.R.string.symptoms_introduction
import br.com.colman.petals.use.repository.UseRepository
import br.com.colman.petals.withdrawal.data.ChartConfig
import br.com.colman.petals.withdrawal.view.WithdrawalChart
import java.time.LocalDateTime
import org.koin.compose.koinInject

@Composable
@Preview
fun Symptoms(
useRepository: UseRepository = koinInject()
) {
val scrollState = rememberScrollState()
fun SymptomsPage(useRepository: UseRepository = koinInject()) {
val lastUseDate by useRepository.getLastUseDate().collectAsState(null)

Column(Modifier.verticalScroll(scrollState).padding(8.dp, 8.dp, 8.dp, 64.dp), spacedBy(16.dp)) {
Symptoms(lastUseDate)
}

@Composable
@Preview
private fun SymptomsPreview() {
Symptoms(LocalDateTime.now().minusDays(10))
}

@Composable
private fun Symptoms(lastUseDate: LocalDateTime?) {
val verticalScroll = rememberScrollState()
Column(Modifier.verticalScroll(verticalScroll).padding(8.dp, 8.dp, 8.dp, 64.dp), spacedBy(16.dp)) {
Text(stringResource(symptoms_introduction))

ChartConfig.entries().forEach { chart ->
Expand All @@ -65,3 +75,4 @@ fun Symptoms(
}
}
}

0 comments on commit be00d0b

Please sign in to comment.