Skip to content

Commit

Permalink
Update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsmanmeet committed Dec 12, 2023
1 parent 3a9064f commit d4244ae
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 52 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.thatsmanmeet.taskyapp"
minSdk 26
targetSdk 34
versionCode 25
versionName "2.4.1"
versionCode 26
versionName "2.4.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
Expand Down Expand Up @@ -71,7 +71,7 @@ dependencies {
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
def room_version = "2.6.0"
def room_version = "2.6.1"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.compose.runtime:runtime-livedata:1.5.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.thatsmanmeet.taskyapp.components

import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -18,21 +17,24 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModel
import com.thatsmanmeet.taskyapp.room.Todo
import com.thatsmanmeet.taskyapp.room.TodoViewModel
import com.thatsmanmeet.taskyapp.room.deletedtodo.DeletedTodo
import com.thatsmanmeet.taskyapp.room.deletedtodo.DeletedTodoViewModel
import com.thatsmanmeet.taskyapp.screens.currentDateTimeComparator
import com.thatsmanmeet.taskyapp.screens.scheduleNotification


@Composable
fun DeletedTodoItem(
deletedTodo: DeletedTodo,
todoViewModel: TodoViewModel,
deletedTodoViewModel: DeletedTodoViewModel,
context:Context = LocalContext.current,
modifier: Modifier = Modifier
) {
val isShowing = remember {
Expand All @@ -50,10 +52,12 @@ fun DeletedTodoItem(
.background(MaterialTheme.colorScheme.inverseOnSurface),
verticalAlignment = Alignment.CenterVertically
) {
Box(modifier = modifier.fillMaxWidth().padding(10.dp)){
Box(modifier = modifier
.fillMaxWidth()
.padding(10.dp)){
Text(
text = deletedTodo.title!!,
fontSize = 16.sp,
fontSize = 20.sp,
textDecoration = if(deletedTodo.isCompleted) TextDecoration.LineThrough else TextDecoration.None
)
}
Expand All @@ -66,7 +70,7 @@ fun DeletedTodoItem(
confirmButtonText = "Restore" ,
dismissButtonText = "Delete",
onConfirmClick = {
todoViewModel.insertTodo(Todo(
val newTodo = Todo(
ID = deletedTodo.ID,
title = deletedTodo.title,
todoDescription = deletedTodo.todoDescription,
Expand All @@ -75,7 +79,19 @@ fun DeletedTodoItem(
time = deletedTodo.time,
notificationID = deletedTodo.notificationID,
isRecurring = deletedTodo.isRecurring
))
)
todoViewModel.insertTodo(newTodo)
if(newTodo.time!!.isNotEmpty()){
currentDateTimeComparator(inputDate = newTodo.date!!, inputTime = newTodo.time!!) {
scheduleNotification(
context = context,
titleText = newTodo.title!!,
messageText = newTodo.todoDescription!!,
time = "${newTodo.date} ${newTodo.time}",
todo = newTodo
)
}
}
deletedTodoViewModel.deleteDeletedTodo(deletedTodo)
},
onDismissClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.room.Room
import com.thatsmanmeet.taskyapp.constants.Constants
import com.thatsmanmeet.taskyapp.room.Todo
import com.thatsmanmeet.taskyapp.room.TodoDatabase
import com.thatsmanmeet.taskyapp.room.deletedtodo.DeletedTodoDatabase
import com.thatsmanmeet.taskyapp.screens.scheduleNotification
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -28,6 +29,11 @@ class RepeatingTasksReceiver : BroadcastReceiver() {
TodoDatabase::class.java,
"todo_database"
).build()
val deletedTodoDatabase = Room.databaseBuilder(
context!!.applicationContext,
DeletedTodoDatabase::class.java,
"deleted_todo_database"
).build()
coroutineScope.launch {
withTimeout(10000) {
todoDatabase.todoDao().getAllTodosFlow().collect{todos->
Expand Down Expand Up @@ -60,6 +66,21 @@ class RepeatingTasksReceiver : BroadcastReceiver() {
}
}
}
coroutineScope.launch {
withTimeout(10000){
deletedTodoDatabase.deletedTodoDao().getAllTodosFlow().collect{deletedTodos->
val currentDate =
SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()).format(
Date()
)
for(todo in deletedTodos){
if(currentDate == todo.todoDeletionDate){
deletedTodoDatabase.deletedTodoDao().deleteTodo(todo)
}
}
}
}
}
val nextAlarmIntent = Intent(context.applicationContext,RepeatingTasksReceiver::class.java).also {
it.action = "repeating_tasks"
}
Expand Down
51 changes: 48 additions & 3 deletions app/src/main/java/com/thatsmanmeet/taskyapp/screens/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.thatsmanmeet.taskyapp.BuildConfig
import com.thatsmanmeet.taskyapp.R
import com.thatsmanmeet.taskyapp.components.OpenEditTodoDialog
import com.thatsmanmeet.taskyapp.components.SearchBarTop
Expand Down Expand Up @@ -119,9 +120,17 @@ fun MyApp(
) {
ModalNavigationDrawer(
drawerState = drawerState,
gesturesEnabled = true,
drawerContent = {
ModalDrawerSheet {
Text("Tasky", modifier = Modifier.padding(16.dp))
Row(
modifier = modifier.fillMaxWidth().padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("Tasky")
Text(text = "V${BuildConfig.VERSION_NAME}")
}
HorizontalDivider()
NavigationDrawerItem(
modifier = modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp),
Expand All @@ -135,6 +144,18 @@ fun MyApp(
navHostController.navigate(route = Screen.DeletedTodosScreen.route)
}
)
NavigationDrawerItem(
modifier = modifier.padding(start = 16.dp, end = 16.dp),
icon = { Icon(imageVector = Icons.Default.Info, contentDescription = null)},
label = { Text(text = "Guide") },
selected = false,
onClick = {
coroutineScope.launch {
drawerState.close()
}
navHostController.navigate(route = Screen.GuideScreen.route)
}
)
NavigationDrawerItem(
modifier = modifier.padding(bottom = 16.dp,start = 16.dp, end = 16.dp),
icon = { Icon(imageVector = Icons.Default.Settings, contentDescription = null)},
Expand Down Expand Up @@ -300,8 +321,6 @@ fun createNotificationChannel(context: Context){
channel.description = desc
channel.enableLights(true)
channel.enableVibration(true)
// val attributes = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build()
// channel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/raw/notifications"),attributes)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if(notificationManager.getNotificationChannel("Reminder Channel") != null){
notificationManager.deleteNotificationChannel("Reminder Channel")
Expand Down Expand Up @@ -422,6 +441,32 @@ fun CurrentDateTimeComparator(
}


fun currentDateTimeComparator(
inputDate:String,
inputTime:String,
onTruePerform: () -> Unit
) {
val calendarInstance = Calendar.getInstance()
val currentDate = calendarInstance.apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
}
val format = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
val parsedDate = format.parse(inputDate)
val calendar = calendarInstance.apply {
time = parsedDate!!
set(Calendar.HOUR_OF_DAY, inputTime.substringBefore(":").toInt())
set(Calendar.MINUTE, inputTime.substringAfter(":").toInt())
set(Calendar.SECOND, 0)
}
val currentTime = Calendar.getInstance().timeInMillis
if(calendar >= currentDate && calendar.timeInMillis >= currentTime){
onTruePerform()
}
}


@Preview
@Composable
fun DisplayAppScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun DeletedTodoScreen(
.height(100.dp)
.padding(16.dp)
){
Text(text = "Deleted Todos will be automatically deleted in 30 days.", fontSize = 15.sp)
Text(text = "Deleted Tasks will be automatically deleted in 30 days. Tap on a task to restore or permanently delete it.", fontSize = 15.sp)
}
LazyColumn{
items(deletedTodoList.value){deletedTodo->
Expand Down
Loading

0 comments on commit d4244ae

Please sign in to comment.