Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
jvmTarget = "17"
Expand Down Expand Up @@ -138,6 +139,7 @@ dependencies {

// Leak Canary
debugImplementation(libs.leakcanary.android)
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}

ktlint {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.aritra.notify.core

import kotlinx.coroutines.CoroutineDispatcher

interface DispatcherProvider {
val main: CoroutineDispatcher
val io: CoroutineDispatcher
val default: CoroutineDispatcher
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/aritra/notify/core/DispatcherProviderImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.aritra.notify.core

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import javax.inject.Inject

class DispatcherProviderImpl @Inject constructor() : DispatcherProvider {
override val main: CoroutineDispatcher
get() = Dispatchers.Main
override val io: CoroutineDispatcher
get() = Dispatchers.IO
override val default: CoroutineDispatcher
get() = Dispatchers.Default
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.aritra.notify.data.converters

import androidx.room.TypeConverter
import java.time.LocalDateTime
import java.time.ZoneOffset

object LocalDateTimeConverter {

@TypeConverter
@JvmStatic
fun toDate(value: Long): LocalDateTime {
return LocalDateTime.ofEpochSecond(value, 0, ZoneOffset.UTC)
}

@TypeConverter
@JvmStatic
fun toString(date: LocalDateTime): Long {
return date.toEpochSecond(ZoneOffset.UTC)
}
}
8 changes: 7 additions & 1 deletion app/src/main/java/com/aritra/notify/data/dao/NoteDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ interface NoteDao {
@Query("SELECT * FROM note ORDER BY dateTime DESC")
fun getAllNotes(): Flow<List<Note>>

@Query("DELETE FROM note WHERE id = :noteId")
suspend fun deleteNoteById(noteId: Int)

@Query("SELECT * FROM note WHERE id = :noteId")
fun getNoteByIdFlow(noteId: Int): Flow<Note>

@Query("SELECT * FROM note WHERE id = :noteId")
fun getNoteById(noteId: Int): Flow<Note>
fun getNoteById(noteId: Int): Note?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertNote(noteModel: Note): Long
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/aritra/notify/data/dao/TrashNoteDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.aritra.notify.data.dao

import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Upsert
import com.aritra.notify.data.relations.TrashNoteWithNotes
import com.aritra.notify.domain.models.TrashNote

@Dao
interface TrashNoteDao {
@Query("SELECT * FROM TrashNote")
suspend fun getTrashNote(): List<TrashNote>

@Query("DELETE FROM TrashNote Where noteId = :noteId")
suspend fun deleteTrashNoteById(noteId: Int)

@Upsert
suspend fun upsertTrashNote(trashNote: TrashNote)

@Transaction
@Query("SELECT * FROM TrashNote ")
suspend fun getTrashNoteWithNote(): List<TrashNoteWithNotes>
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/aritra/notify/data/db/NoteDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.aritra.notify.data.converters.DateTypeConverter
import com.aritra.notify.data.converters.ListConverter
import com.aritra.notify.data.converters.LocalDateTimeConverter
import com.aritra.notify.data.converters.UriConverter
import com.aritra.notify.data.dao.NoteDao
import com.aritra.notify.data.dao.TrashNoteDao
import com.aritra.notify.domain.models.Note
import com.aritra.notify.domain.models.TrashNote

@Database(entities = [Note::class], version = 3)
@Database(entities = [Note::class, TrashNote::class], version = 4)
@TypeConverters(DateTypeConverter::class, UriConverter::class, ListConverter::class, LocalDateTimeConverter::class)
abstract class NoteDatabase : RoomDatabase() {

abstract fun noteDao(): NoteDao
abstract val trashNote: TrashNoteDao

companion object {
@Suppress("ktlint:standard:property-naming")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.aritra.notify.data.relations

import androidx.room.Embedded
import androidx.room.Relation
import com.aritra.notify.domain.models.Note
import com.aritra.notify.domain.models.TrashNote

data class TrashNoteWithNotes(
@Embedded val trashNote: TrashNote,
@Relation(
parentColumn = "noteId",
entityColumn = "id"
)
val note: Note,
)
19 changes: 19 additions & 0 deletions app/src/main/java/com/aritra/notify/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.aritra.notify.di

import android.app.Application
import android.content.Context
import androidx.room.Room
import com.aritra.notify.data.db.NoteDatabase
import com.aritra.notify.domain.repository.NoteRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
Expand All @@ -25,4 +28,20 @@ class AppModule {
fun provideRepository(application: Application): NoteRepository {
return NoteRepository(application)
}

@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): NoteDatabase {
return Room.databaseBuilder(
context.applicationContext,
NoteDatabase::class.java,
"Note_database"
)
.fallbackToDestructiveMigration()
.build()
}

@Provides
@Singleton
fun provideTrashNote(noteDatabase: NoteDatabase) = noteDatabase.trashNote
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/aritra/notify/di/DispatcherModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.aritra.notify.di

import com.aritra.notify.core.DispatcherProvider
import com.aritra.notify.core.DispatcherProviderImpl
import com.aritra.notify.domain.repository.trash.TrashNoteRepoImpl
import com.aritra.notify.domain.repository.trash.TrashNoteRepo
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
abstract class DispatcherModule {

@Binds
abstract fun bindDispatcherProvider(
dispatcherProvider: DispatcherProviderImpl,
): DispatcherProvider

@Binds
abstract fun bindTrashRepo(
trashNoteRepository: TrashNoteRepoImpl,
): TrashNoteRepo
}
17 changes: 7 additions & 10 deletions app/src/main/java/com/aritra/notify/di/ViewModelModule.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package com.aritra.notify.di

import com.aritra.notify.components.biometric.AppBioMetricManager
import com.aritra.notify.viewmodel.MainViewModel
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent

@Module
@InstallIn(ViewModelComponent::class)
class ViewModelModule {

@Provides
fun provideMainViewModel(
bioMetricManager: AppBioMetricManager,
dataStoreUtil: DataStoreUtil,
): MainViewModel {
return MainViewModel(bioMetricManager, dataStoreUtil)
}
// @Provides
// fun provideMainViewModel(
// bioMetricManager: AppBioMetricManager,
// dataStoreUtil: DataStoreUtil,
// ): MainViewModel {
// return MainViewModel(bioMetricManager, dataStoreUtil)
// }
}
8 changes: 3 additions & 5 deletions app/src/main/java/com/aritra/notify/domain/models/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ package com.aritra.notify.domain.models

import android.net.Uri
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.aritra.notify.data.converters.DateTypeConverter
import com.aritra.notify.data.converters.UriConverter
import com.aritra.notify.data.converters.ListConverter
import kotlinx.parcelize.Parcelize
import java.util.Date

@Parcelize
@Entity(tableName = "note")
@TypeConverters(DateTypeConverter::class, UriConverter::class, ListConverter::class)
data class Note(
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
var title: String,
var note: String,
var dateTime: Date?,
var image: List<Uri?>,
@ColumnInfo(defaultValue = "false")
var isMovedToTrash: Boolean = false,
) : Parcelable
12 changes: 12 additions & 0 deletions app/src/main/java/com/aritra/notify/domain/models/TrashNote.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.aritra.notify.domain.models

import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.LocalDateTime

@Entity
data class TrashNote(
@PrimaryKey(autoGenerate = true)
val noteId: Int = 0,
val dateTime: LocalDateTime = LocalDateTime.now(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ class NoteRepository @Inject constructor(application: Application) {
val database = NoteDatabase.getInstance(application)
noteDao = database.noteDao()
}

suspend fun deleteNoteById(noteId: Int) {
noteDao.deleteNoteById(noteId)
}
fun getAllNotesFromRoom(): Flow<List<Note>> = noteDao.getAllNotes()

fun getNoteByIdFromRoom(noteId: Int): Flow<Note> = noteDao.getNoteById(noteId)
fun getNoteByIdFromRoom(noteId: Int): Flow<Note> = noteDao.getNoteByIdFlow(noteId)

suspend fun insertNoteToRoom(note: Note): Long = noteDao.insertNote(note)

suspend fun insertListOfNotesToRoom(notes: List<Note>): List<Long> = noteDao.insertListOfNotes(notes)

fun getNoteById(noteId: Int): Note? {
return noteDao.getNoteById(noteId)
}
suspend fun updateNoteInRoom(note: Note) = noteDao.updateNote(note)

suspend fun deleteNoteFromRoom(note: Note) = noteDao.deleteNote(note)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aritra.notify.domain.repository.trash

import com.aritra.notify.data.relations.TrashNoteWithNotes
import com.aritra.notify.domain.models.TrashNote
import java.time.LocalDateTime

interface TrashNoteRepo {
suspend fun getTrashNotes(): List<TrashNote>
suspend fun deleteTrashNoteById(noteId: Int)
suspend fun upsertTrashNote(trashNote: TrashNote)
suspend fun getTrashNoteWithNote(): List<TrashNoteWithNotes>

/**
* @return list of ids for notes to delete to noteRepository
*/
suspend fun getTrashNotePeriodHasExceeded(localDateTime: LocalDateTime = LocalDateTime.now()): List<Int>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.aritra.notify.domain.repository.trash

import com.aritra.notify.data.dao.TrashNoteDao
import com.aritra.notify.data.relations.TrashNoteWithNotes
import com.aritra.notify.domain.models.TrashNote
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import javax.inject.Inject

class TrashNoteRepoImpl @Inject constructor(
private val noteTrashDao: TrashNoteDao,
) : TrashNoteRepo {

override suspend fun getTrashNotes(): List<TrashNote> {
return noteTrashDao.getTrashNote()
}

override suspend fun deleteTrashNoteById(noteId: Int) {
noteTrashDao.deleteTrashNoteById(noteId)
}

override suspend fun upsertTrashNote(trashNote: TrashNote) {
noteTrashDao.upsertTrashNote(trashNote)
}

override suspend fun getTrashNoteWithNote(): List<TrashNoteWithNotes> {
return noteTrashDao.getTrashNoteWithNote()
}

override suspend fun getTrashNotePeriodHasExceeded(localDateTime: LocalDateTime): List<Int> {
val getTrashNote = getTrashNotes()
return getTrashNote.filter {
val dateTime = it.dateTime
dateTime.until(localDateTime, ChronoUnit.DAYS) >= 28
}.map {
it.noteId
}
}
}
Loading