Skip to content

Commit

Permalink
chore: impl share dates between calender screen and add task screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal2376 committed Apr 2, 2024
1 parent 23b57a7 commit b2c24b3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -76,6 +75,7 @@ import com.vishal2376.snaptick.presentation.common.h1TextStyle
import com.vishal2376.snaptick.presentation.common.h2TextStyle
import com.vishal2376.snaptick.presentation.common.h3TextStyle
import com.vishal2376.snaptick.presentation.common.taskTextStyle
import com.vishal2376.snaptick.presentation.main.MainEvent
import com.vishal2376.snaptick.presentation.main.MainState
import com.vishal2376.snaptick.ui.theme.Blue
import com.vishal2376.snaptick.ui.theme.DarkGreen
Expand All @@ -96,14 +96,19 @@ import java.util.UUID
fun AddTaskScreen(
appState: MainState,
onEvent: (AddEditScreenEvent) -> Unit,
onMainEvent: (MainEvent) -> Unit,
onBack: () -> Unit
) {

val currentTime = LocalTime.now()
val currentDate = appState.calenderDate ?: LocalDate.now()
onMainEvent(MainEvent.UpdateCalenderDate(null))


var taskTitle by remember { mutableStateOf("") }
var taskStartTime by remember { mutableStateOf(currentTime) }
var taskEndTime by remember { mutableStateOf(currentTime.plusHours(1)) }
var taskDate by remember { mutableStateOf(LocalDate.now()) }
var taskDate by remember { mutableStateOf(currentDate) }
var isTaskReminderOn by remember { mutableStateOf(true) }
var isTaskRepeated by remember { mutableStateOf(false) }
var repeatedWeekDays by remember { mutableStateOf("") }
Expand Down Expand Up @@ -475,6 +480,6 @@ fun AddTaskScreen(
@Composable
fun AddTaskScreenPreview() {
SnaptickTheme {
AddTaskScreen(MainState(), onEvent = {}, {})
AddTaskScreen(MainState(), onEvent = {}, {}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.vishal2376.snaptick.presentation.common.h1TextStyle
import com.vishal2376.snaptick.presentation.home_screen.HomeScreenEvent
import com.vishal2376.snaptick.presentation.home_screen.components.EmptyTaskComponent
import com.vishal2376.snaptick.presentation.home_screen.components.TaskComponent
import com.vishal2376.snaptick.presentation.main.MainEvent
import com.vishal2376.snaptick.presentation.navigation.Routes
import com.vishal2376.snaptick.ui.theme.Blue
import com.vishal2376.snaptick.ui.theme.SnaptickTheme
Expand All @@ -67,6 +68,7 @@ import java.util.Locale
fun CalenderScreen(
tasks: List<Task>,
onEvent: (HomeScreenEvent) -> Unit,
onMainEvent: (MainEvent) -> Unit,
onNavigate: (route: String) -> Unit,
onBack: () -> Unit
) {
Expand Down Expand Up @@ -147,6 +149,7 @@ fun CalenderScreen(
if (selectedDay >= LocalDate.now()) {
FloatingActionButton(
onClick = {
onMainEvent(MainEvent.UpdateCalenderDate(selectedDay))
onNavigate(Routes.AddTaskScreen.name)
},
containerColor = Blue,
Expand Down Expand Up @@ -264,6 +267,6 @@ fun CalenderScreen(
fun CalenderScreenPreview() {
SnaptickTheme {
val tasks = DummyTasks.dummyTasks
CalenderScreen(tasks, {}, {}, {})
CalenderScreen(tasks, {}, {}, {}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.vishal2376.snaptick.presentation.common.AppTheme
import com.vishal2376.snaptick.presentation.common.NavDrawerItem
import com.vishal2376.snaptick.presentation.common.SortTask
import java.time.LocalDate
import java.time.LocalTime

sealed class MainEvent {
Expand All @@ -12,5 +13,6 @@ sealed class MainEvent {
data class UpdateSleepTime(val sleepTime: LocalTime, val context: Context) : MainEvent()
data class UpdateLanguage(val language: String, val context: Context) : MainEvent()
data class UpdateSortByTask(val sortTask: SortTask, val context: Context) : MainEvent()
data class UpdateCalenderDate(val date: LocalDate?) : MainEvent()
data class OnClickNavDrawerItem(val context: Context, val item: NavDrawerItem) : MainEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vishal2376.snaptick.presentation.main

import com.vishal2376.snaptick.presentation.common.AppTheme
import com.vishal2376.snaptick.presentation.common.SortTask
import java.time.LocalDate
import java.time.LocalTime
import java.util.Locale

Expand All @@ -15,4 +16,5 @@ data class MainState(
val sleepTime: LocalTime = LocalTime.of(23, 59),
val language: String = Locale.ENGLISH.language,
val isWheelTimePicker: Boolean = true,
val calenderDate: LocalDate? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fun AppNavigation(taskViewModel: TaskViewModel) {
CalenderScreen(
tasks = allTasks,
onEvent = taskViewModel::onEvent,
onMainEvent = taskViewModel::onEvent,
onBack = {
if (navController.isValidBackStack) {
navController.popBackStack()
Expand All @@ -109,6 +110,7 @@ fun AppNavigation(taskViewModel: TaskViewModel) {
AddTaskScreen(
appState = taskViewModel.appState,
onEvent = taskViewModel::onEvent,
onMainEvent = taskViewModel::onEvent,
onBack = {
if (navController.isValidBackStack) {
navController.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import javax.inject.Inject
class TaskViewModel @Inject constructor(private val repository: TaskRepository) : ViewModel() {

var appState by mutableStateOf(MainState())
var deletedTask: Task? = null
private var deletedTask: Task? = null
var task: Task by mutableStateOf(
Task(
id = 0,
Expand Down Expand Up @@ -102,6 +102,10 @@ class TaskViewModel @Inject constructor(private val repository: TaskRepository)
}
}

is MainEvent.UpdateCalenderDate -> {
appState = appState.copy(calenderDate = event.date)
}

is MainEvent.OnClickNavDrawerItem -> {
when (event.item) {
NavDrawerItem.REPORT_BUGS -> {
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/vishal2376/snaptick/util/Validation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ fun checkValidTask(
return Pair(false, "Title can't be empty")
}

if (currentDuration >= freeTime) {
return Pair(false, "Invalid Duration! You have only $formattedFreeTime remaining.")
}

if (task.getDuration() < Constants.MIN_ALLOWED_DURATION * 60) {
return Pair(false, "Task should be at least ${Constants.MIN_ALLOWED_DURATION} minutes.")
}
Expand All @@ -33,6 +29,14 @@ fun checkValidTask(
return Pair(false, "Past dates are not allowed")
}

if (task.date > LocalDate.now()) {
return Pair(true, "Future Task")
}

if (currentDuration >= freeTime) {
return Pair(false, "Invalid Duration! You have only $formattedFreeTime remaining.")
}

// if (task.reminder) {
// if (startTimeSec < currentTime && !task.isRepeated) {
// return Pair(false, "Cannot set a reminder for past time")
Expand Down

0 comments on commit b2c24b3

Please sign in to comment.