Skip to content

Commit

Permalink
Merge pull request #16 from brandy-kay/feature/alarm_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyodhiambo authored Aug 2, 2023
2 parents 2fde1e4 + 79e56f8 commit c4a3aa3
Show file tree
Hide file tree
Showing 26 changed files with 664 additions and 90 deletions.
3 changes: 0 additions & 3 deletions app/src/main/java/com/brandyodhiambo/quench/models/TabItem.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.brandyodhiambo.quench.models

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.runtime.Composable
import com.brandyodhiambo.home.presentation.home_screen.HomeScreen
import com.brandyodhiambo.quench.R
Expand All @@ -13,7 +11,6 @@ import com.ramcosta.composedestinations.navigation.DestinationsNavigator
typealias ComposableFun = @Composable (onClick: () -> Unit) -> Unit

sealed class TabItem(var icon: Int, var title: String, var screen: ComposableFun) {
@RequiresApi(Build.VERSION_CODES.O)
data class Home(val navigator: DestinationsNavigator) :
TabItem(R.drawable.ic_home, "Home", { HomeScreen() })

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.brandyodhiambo.common.domain.model

data class DailyStatistics(
val amountTaken: Float,
val day: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.brandyodhiambo.common.domain.model

data class MonthlyStatistics(
val amountTaken: Float,
val month: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.brandyodhiambo.common.domain.model

data class WeeklyStatistics(
val amountTaken: Float,
val week: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.brandyodhiambo.common.domain.repository

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

interface DailyStatisticsRepository {
suspend fun insertDailyStatistics(dailyStatistics: DailyStatistics)
suspend fun updateDailyStatistics(dailyStatistics: DailyStatistics)
suspend fun deleteDailyStatistics(dailyStatistics: DailyStatistics)
suspend fun deleteAllDailyStatistics()
fun getDailyStatistics(): LiveData<List<DailyStatistics>?>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.brandyodhiambo.common.domain.repository

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

interface MonthlyStatisticsRepository {

suspend fun insertMonthlyStatistics(monthlyStatistics: MonthlyStatistics)
suspend fun updateMonthlyStatistics(monthlyStatistics: MonthlyStatistics)
fun getMonthlyStatistics(): LiveData<List<MonthlyStatistics>?>
suspend fun deleteMonthlyStatistics(monthlyStatistics: MonthlyStatistics)
suspend fun deleteAllMonthlyStatistics()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.brandyodhiambo.common.domain.repository

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

interface WeeklyStatisticRepository {
suspend fun insertWeeklyStatistic(weeklyStatistic: WeeklyStatistics)
suspend fun updateWeeklyStatistic(weeklyStatistic: WeeklyStatistics)
fun getWeeklyStatistic(): LiveData<List<WeeklyStatistics>?>
suspend fun deleteWeeklyStatistic(weeklyStatistic: WeeklyStatistics)
suspend fun deleteAllWeeklyStatistic()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package com.brandyodhiambo.common.util

import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.TextStyle
import java.time.temporal.TemporalAdjusters
import java.time.temporal.WeekFields
import java.util.*

@SuppressLint("SimpleDateFormat")
Expand All @@ -24,5 +31,45 @@ fun String.toInitials(): String {
.reduce { acc, s -> acc + s }
}

fun isEndOfDay(dateTime: LocalDateTime): Boolean {
val endOfDay = LocalDateTime.of(dateTime.toLocalDate(), LocalTime.MAX)
return dateTime == endOfDay
}

fun isEndOfWeek(date: LocalDate): Boolean {
val endOfWeek = date.with(TemporalAdjusters.next(DayOfWeek.SUNDAY))
return date == endOfWeek
}

fun isEndOfMonth(date: LocalDate): Boolean {
val endOfMonth = date.with(TemporalAdjusters.lastDayOfMonth())
return date == endOfMonth
}

fun getCurrentDay(): String {
val now = LocalDateTime.now()
val currentDayOfWeek = now.dayOfWeek
return currentDayOfWeek.getDisplayName(TextStyle.FULL, Locale.getDefault())
}
fun getCurrentMonth(): String {
val now = LocalDateTime.now()
val currentMonth = now.month
return currentMonth.getDisplayName(TextStyle.FULL, Locale.getDefault())
}

fun getCurrentWeekNumber(): Int {
val now = LocalDate.now()
val weekFields = WeekFields.of(Locale.getDefault())
return now.get(weekFields.weekOfWeekBasedYear())
}

fun getCurrentYear(): String {
val now = LocalDateTime.now()
return now.year.toString()
}






5 changes: 4 additions & 1 deletion core/database/src/main/java/com/brandyodhiambo/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ object Constants {

const val LEVEL_TABLE = "level_table"
const val REPORT_TABLE = "report_table"
const val DAILY_STATISTICS_TABLE = "daily_statistics_table"
const val MONTHLY_STATISTICS_TABLE = "monthly_statistics_table"
const val WEEKLY_STATISTICS_TABLE = "weekly_statistics_table"

const val DATABASE_NAME = "water_reminder_db"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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.DailyStatisticsEntity

@Dao
interface DailyStatisticsDao {

@Insert
suspend fun insertDailyStatistic(dailyStatisticsEntity: DailyStatisticsEntity)

@Query("SELECT *FROM daily_statistics_table")
fun getDailyStatistics(): LiveData<List<DailyStatisticsEntity>?>

@Delete
suspend fun deleteDailyStatistic(dailyStatisticsEntity: DailyStatisticsEntity)

@Query("UPDATE daily_statistics_table SET amountTaken = :amountTaken, day = :day WHERE id = :id")
suspend fun updateDailyStatistic(id: Int, amountTaken: Float, day: String)

@Query("DELETE FROM daily_statistics_table")
suspend fun deleteAllDailyStatistics()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.MonthlyStatisticsEntity

@Dao
interface MonthlyStatisticsDao {
@Insert
suspend fun insertMonthlyStatistic(monthlyStatisticsEntity: MonthlyStatisticsEntity)

@Query("SELECT *FROM monthly_statistics_table")
fun getMonthlyStatistics(): LiveData<List<MonthlyStatisticsEntity>?>

@Delete
suspend fun deleteMonthlyStatistic(monthlyStatisticsEntity: MonthlyStatisticsEntity)

@Query("UPDATE monthly_statistics_table SET amountTaken = :amountTaken, month = :month WHERE id = :id")
suspend fun updateMonthlyStatistic(id: Int, amountTaken: Float, month: String)

@Query("DELETE FROM monthly_statistics_table")
suspend fun deleteAllMonthlyStatistics()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.WeeklyStatisticsEntity

@Dao
interface WeeklyStatisticDao {
@Insert
suspend fun insertWeeklyStatistic(weeklyStatisticsEntity: WeeklyStatisticsEntity)

@Query("SELECT *FROM weekly_statistics_table")
fun getWeeklyStatistics(): LiveData<List<WeeklyStatisticsEntity>?>

@Delete
suspend fun deleteWeeklyStatistic(weeklyStatisticsEntity: WeeklyStatisticsEntity)

@Query("UPDATE weekly_statistics_table SET amountTaken = :amountTaken, week = :week WHERE id = :id")
suspend fun updateWeeklyStatistic(id: Int, amountTaken: Float, week: String)

@Query("DELETE FROM weekly_statistics_table")
suspend fun deleteAllWeeklyStatistics()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.brandyodhiambo.converter.Converter
import com.brandyodhiambo.dao.DailyStatisticsDao
import com.brandyodhiambo.dao.GoalWaterIntakeDao
import com.brandyodhiambo.dao.IdealWaterIntakeDao
import com.brandyodhiambo.dao.LevelDao
import com.brandyodhiambo.dao.MonthlyStatisticsDao
import com.brandyodhiambo.dao.ReminderTimeDao
import com.brandyodhiambo.dao.SelectedDrinkDao
import com.brandyodhiambo.dao.SleepTimeDao
import com.brandyodhiambo.dao.WakeTimeDao
import com.brandyodhiambo.dao.WeeklyStatisticDao
import com.brandyodhiambo.entity.DailyStatisticsEntity
import com.brandyodhiambo.entity.GoalWaterIntakeEntity
import com.brandyodhiambo.entity.IdealWaterIntakeEntity
import com.brandyodhiambo.entity.LevelEntity
import com.brandyodhiambo.entity.MonthlyStatisticsEntity
import com.brandyodhiambo.entity.ReminderTimeEntity
import com.brandyodhiambo.entity.SelectedDrinkEntity
import com.brandyodhiambo.entity.SleepTimeEntity
import com.brandyodhiambo.entity.WakeTimeEntity

import com.brandyodhiambo.entity.WeeklyStatisticsEntity

@TypeConverters(Converter::class)
@Database(
entities = [SelectedDrinkEntity::class, WakeTimeEntity::class, IdealWaterIntakeEntity::class, GoalWaterIntakeEntity::class, SleepTimeEntity::class, LevelEntity::class, ReminderTimeEntity::class],
version = 3,
entities = [SelectedDrinkEntity::class, WakeTimeEntity::class, IdealWaterIntakeEntity::class, GoalWaterIntakeEntity::class, SleepTimeEntity::class, LevelEntity::class, ReminderTimeEntity::class, DailyStatisticsEntity::class, WeeklyStatisticsEntity::class, MonthlyStatisticsEntity::class],
version = 4,
exportSchema = false,
)
abstract class QuenchDatabase : RoomDatabase() {
Expand All @@ -34,4 +39,7 @@ abstract class QuenchDatabase : RoomDatabase() {
abstract fun goalWaterIntakeDao(): GoalWaterIntakeDao
abstract fun levelDao(): LevelDao
abstract fun reminderTimeDao(): ReminderTimeDao
abstract fun dailyStatisticsDao(): DailyStatisticsDao
abstract fun weeklyStatisticsDao(): WeeklyStatisticDao
abstract fun monthlyStatisticsDao(): MonthlyStatisticsDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ object DatabaseModule {
@Singleton
fun provideReminderTimeDao(database: QuenchDatabase) = database.reminderTimeDao()

@Provides
@Singleton
fun provideDailyStatisticsDao(database: QuenchDatabase) = database.dailyStatisticsDao()

@Provides
@Singleton
fun provideWeeklyStatisticsDao(database: QuenchDatabase) = database.weeklyStatisticsDao()

@Provides
@Singleton
fun provideMonthlyStatisticsDao(database: QuenchDatabase) = database.monthlyStatisticsDao()

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

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

@Entity(tableName = DAILY_STATISTICS_TABLE)
data class DailyStatisticsEntity(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val amountTaken: Float,
val day: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.brandyodhiambo.entity

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

@Entity(tableName = MONTHLY_STATISTICS_TABLE)
data class MonthlyStatisticsEntity(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val amountTaken: Float,
val month: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.brandyodhiambo.entity

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

@Entity(tableName = WEEKLY_STATISTICS_TABLE)
data class WeeklyStatisticsEntity(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val amountTaken: Float,
val week: String,
)
3 changes: 2 additions & 1 deletion feature/statistics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
Expand All @@ -50,6 +50,7 @@ android {
dependencies {
implementation(project(Module.designsystem))
implementation(project(Module.common))
implementation(project(Module.database))

// RamCosta Navigation
implementation("io.github.raamcosta.compose-destinations:core:1.5.20-beta")
Expand Down
Loading

0 comments on commit c4a3aa3

Please sign in to comment.