Skip to content

Commit

Permalink
working time formate
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyodhiambo committed Jun 22, 2024
1 parent 29ea75c commit ce3b5b6
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.brandyodhiambo.common.domain.model

data class TimeFormate(
val formate:Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.brandyodhiambo.common.domain.repository

import androidx.lifecycle.LiveData
import com.brandyodhiambo.common.domain.model.TimeFormate

interface TimeFormateRepository {

suspend fun insertTimeFormate(timeFormate: TimeFormate)
fun getTimeFormate(): LiveData<TimeFormate?>
suspend fun deleteTimeFormate(timeFormate: TimeFormate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Constants {
const val REMINDER_TABLE = "reminder_table"
const val GOAL_TABLE = "goal_table"
const val SELECTED_DRINK_TABLE = "selected_drink_table"
const val TIME_FORMATE_TABLE = "time_formate_table"

const val LEVEL_TABLE = "level_table"
const val REPORT_TABLE = "report_table"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.brandyodhiambo.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import com.brandyodhiambo.entity.TimeFormateEntity

@Dao
interface TimeFormateDao {

@Insert
suspend fun insertTimeFormate(timeFormateEntity: TimeFormateEntity)

@Query("SELECT * FROM time_formate_table")
fun getTimeFormate():LiveData<TimeFormateEntity>

@Delete
suspend fun deleteTimeFormate(timeFormateEntity: TimeFormateEntity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.brandyodhiambo.dao.MonthlyStatisticsDao
import com.brandyodhiambo.dao.ReminderTimeDao
import com.brandyodhiambo.dao.SelectedDrinkDao
import com.brandyodhiambo.dao.SleepTimeDao
import com.brandyodhiambo.dao.TimeFormateDao
import com.brandyodhiambo.dao.WakeTimeDao
import com.brandyodhiambo.dao.WeeklyStatisticDao
import com.brandyodhiambo.entity.AchievementEntity
Expand Down Expand Up @@ -60,4 +61,5 @@ abstract class QuenchDatabase : RoomDatabase() {
abstract fun weeklyStatisticsDao(): WeeklyStatisticDao
abstract fun monthlyStatisticsDao(): MonthlyStatisticsDao
abstract fun achievementDao(): AchievementDao
abstract fun timeFormateDao():TimeFormateDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ object DatabaseModule {
@Singleton
fun provideAchievementDao(database: QuenchDatabase) = database.achievementDao()

@Provides
@Singleton
fun provideTimeFormateDao(database: QuenchDatabase) = database.timeFormateDao()

@Provides
@Singleton
fun provideGson(): Gson {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.brandyodhiambo.entity

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.brandyodhiambo.Constants.TIME_FORMATE_TABLE

@Entity(tableName = TIME_FORMATE_TABLE)
data class TimeFormateEntity(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val formate: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,15 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.core.content.ContextCompat
import androidx.hilt.navigation.compose.hiltViewModel
import com.brandyodhiambo.common.R
import com.brandyodhiambo.common.domain.model.Days
Expand All @@ -88,6 +81,7 @@ import com.brandyodhiambo.home.presentation.component.TimeSetterDialog
import com.chargemap.compose.numberpicker.Hours
import com.ramcosta.composedestinations.annotation.Destination

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Destination
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fun WakeTimePickerInHours(
HoursNumberPicker(
dividersColor = MaterialTheme.colorScheme.onBackground,
value = currentPickerValueText,
hoursRange = 0..23,
hoursRange = 0..12,
onValueChange = {
onCurrentPickerValueTextChange(it)
onTimeWakeSelected(it)
Expand Down
2 changes: 2 additions & 0 deletions feature/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ android {
dependencies {
implementation(project(Module.designsystem))
implementation(project(Module.common))
implementation(project(Module.database))


implementation(project(mapOf("path" to ":feature:home")))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.brandyodhiambo.settings.data.mapper

import com.brandyodhiambo.common.domain.model.TimeFormate
import com.brandyodhiambo.entity.TimeFormateEntity

internal fun TimeFormateEntity.toTimeFormate(): TimeFormate {
return TimeFormate(
formate = formate
)
}

internal fun TimeFormate.toTimeFormateEntity(): TimeFormateEntity {
return TimeFormateEntity(
formate = formate
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.brandyodhiambo.settings.data.repository

import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import com.brandyodhiambo.common.domain.model.TimeFormate
import com.brandyodhiambo.common.domain.repository.TimeFormateRepository
import com.brandyodhiambo.dao.TimeFormateDao
import com.brandyodhiambo.settings.data.mapper.toTimeFormate
import com.brandyodhiambo.settings.data.mapper.toTimeFormateEntity

class TimeFormateRepositoryImpl(
private val timeFormateDao: TimeFormateDao
):TimeFormateRepository {
override suspend fun insertTimeFormate(timeFormate: TimeFormate) {
timeFormateDao.insertTimeFormate(timeFormate.toTimeFormateEntity())
}

override fun getTimeFormate(): LiveData<TimeFormate?> {
return timeFormateDao.getTimeFormate().map {
it.toTimeFormate()
}
}

override suspend fun deleteTimeFormate(timeFormate: TimeFormate) {
timeFormateDao.deleteTimeFormate(timeFormate.toTimeFormateEntity())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.brandyodhiambo.settings.di

import com.brandyodhiambo.common.domain.repository.TimeFormateRepository
import com.brandyodhiambo.dao.TimeFormateDao
import com.brandyodhiambo.settings.data.repository.TimeFormateRepositoryImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object SettingModule {
@Provides
@Singleton
fun provideTimeFormateRepository(timeFormateDao: TimeFormateDao):TimeFormateRepository{
return TimeFormateRepositoryImpl(timeFormateDao)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel
import com.brandyodhiambo.common.R
import com.brandyodhiambo.designsystem.components.NotificationSwitcher
import com.brandyodhiambo.settings.presentation.component.CustomReminderDialog
Expand All @@ -62,9 +63,10 @@ interface AddReminderNavigator {
@Destination
@Composable
fun AddReminderScreen(
navigator: AddReminderNavigator
navigator: AddReminderNavigator,
settingsViewModel: SettingsViewModel = hiltViewModel()
) {
val repeateModeDialog = remember { mutableStateOf(false) }
val repeateModeDialog = settingsViewModel.repeatModeDialog.value
Scaffold(
topBar = {
TopAppBarAddReminder(navigator = navigator)
Expand Down Expand Up @@ -129,7 +131,7 @@ fun AddReminderScreen(
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onBackground
)
IconButton(onClick = { repeateModeDialog.value = true }) {
IconButton(onClick = { settingsViewModel.setRepeatModeDialog(true)}) {
Icon(
painter = painterResource(id = R.drawable.ic_chevron_right),
tint = MaterialTheme.colorScheme.onBackground,
Expand Down Expand Up @@ -179,13 +181,15 @@ fun AddReminderScreen(
)
}

if (repeateModeDialog.value) {
Dialog(onDismissRequest = { repeateModeDialog.value }) {
if (repeateModeDialog) {
Dialog(onDismissRequest = { settingsViewModel.setRepeatModeDialog(false)}) {
val repeatMode = listOf("Once", "Mon to Fri", "Daily", "Custom")
CustomReminderDialog(
openDialog = repeateModeDialog,
items = repeatMode,
title = "Repeat Mode"
title = "Repeat Mode",
onCustomReminderDialog = {
settingsViewModel.setRepeatModeDialog(value = false)
}
)
}
}
Expand Down Expand Up @@ -231,7 +235,10 @@ fun TopAppBarAddReminder(navigator: AddReminderNavigator) {
@Composable
fun ReminderTimePickerInHours() {
Column(
modifier = Modifier.fillMaxWidth().height(200.dp).padding(16.dp),
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.padding(16.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand Down
Loading

0 comments on commit ce3b5b6

Please sign in to comment.