Skip to content

Commit

Permalink
Merge branch 'feature/edit_executions_for_task' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
braiso-22 committed Apr 29, 2024
2 parents b823aa5 + a0c4858 commit b7fa543
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution

import android.widget.Space
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -83,7 +82,17 @@ fun AddEditExecutionScreenContent(
modifier = modifier,
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.add_execution)) },
title = {
Text(
stringResource(
if (state.isEditExecution) {
R.string.edit_execution
} else {
R.string.add_execution
}
)
)
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import androidx.lifecycle.viewModelScope
import com.braiso_22.cozycave.R
import com.braiso_22.cozycave.feature_execution.domain.use_case.AddExecutionUseCase
import com.braiso_22.cozycave.feature_execution.domain.use_case.GetExecutionByIdUseCase
import com.braiso_22.cozycave.feature_execution.domain.use_case.GetExecutionsByRelatedIdUseCase
import com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution.state.AddEditExecutionUiState
import com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution.state.asExecution
import com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution.state.toUiState
import com.braiso_22.cozycave.feature_task.presentation.add_edit_task.state.toUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand Down Expand Up @@ -94,4 +92,3 @@ class AddEditExecutionViewModel @Inject constructor(
data class SavedCloseScreen(val message: Int) : UiEvent()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.time.LocalTime
import java.time.format.DateTimeFormatter

data class AddEditExecutionUiState(
val id: Int = 0,
val startDate: String = "",
val startTime: String = "",
val endDate: String = "",
Expand All @@ -17,6 +18,7 @@ data class AddEditExecutionUiState(
)

fun Execution.toUiState() = AddEditExecutionUiState(
id = id,
startDate = startDateTime.toFormatedDate(),
startTime = startDateTime.toFormatedTime(),
endDate = endDateTime.toFormatedDate(),
Expand All @@ -39,6 +41,7 @@ fun LocalDateTime.toFormatedTime(): String {

fun AddEditExecutionUiState.asExecution(): Execution {
return Execution(
id = id,
startDateTime = LocalDateTime.of(
LocalDate.parse(startDate, DateTimeFormatter.ofPattern("dd/MM/yyyy")),
LocalTime.parse(startTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.braiso_22.cozycave.feature_task.domain.Task
import com.braiso_22.cozycave.feature_task.domain.use_case.AddTaskUseCase
import com.braiso_22.cozycave.feature_task.domain.use_case.GetTaskByIdUseCase
import com.braiso_22.cozycave.feature_task.presentation.add_edit_task.AddEditTaskEvent.*
import com.braiso_22.cozycave.feature_task.presentation.add_edit_task.state.AddEditTaskUiState
import com.braiso_22.cozycave.feature_task.presentation.add_edit_task.state.toTask
import com.braiso_22.cozycave.feature_task.presentation.add_edit_task.state.toUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.braiso_22.cozycave.feature_task.presentation.show_task_detail

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -27,6 +28,7 @@ import com.braiso_22.cozycave.feature_task.presentation.show_task_detail.state.T
fun TaskDetailScreen(
windowSizeClass: WindowSizeClass,
onBack: () -> Unit,
onClickTaskExecution: (taskId: Int, executionId: Int) -> Unit,
modifier: Modifier = Modifier,
viewModel: TaskDetailViewModel = hiltViewModel(),
) {
Expand All @@ -35,6 +37,7 @@ fun TaskDetailScreen(
state = state,
windowSizeClass = windowSizeClass,
onBack = onBack,
onClickTaskExecution = onClickTaskExecution,
modifier = modifier,
)
}
Expand All @@ -44,6 +47,7 @@ fun TaskDetailScreen(
fun TaskDetailScreenContent(
state: TaskDetailUiState,
windowSizeClass: WindowSizeClass,
onClickTaskExecution: (Int, Int) -> Unit,
onBack: () -> Unit,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -113,6 +117,9 @@ fun TaskDetailScreenContent(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.clickable {
onClickTaskExecution(state.taskId, execution.id)
}
)
if (index != state.unFinishedExecutions.lastIndex)
HorizontalDivider(
Expand All @@ -139,6 +146,9 @@ fun TaskDetailScreenContent(
modifier = Modifier
.fillMaxSize()
.padding(8.dp)
.clickable {
onClickTaskExecution(state.taskId, execution.id)
}
)
if (index != state.completedExecutions.lastIndex)
HorizontalDivider(
Expand All @@ -156,13 +166,16 @@ fun TaskDetailScreenContent(
private fun TaskDetailScreenContentPreview(dpSize: DpSize) {
val state = remember {
mutableStateOf(
TaskDetailUiState(),
TaskDetailUiState(taskId = 0),
)
}
TaskDetailScreenContent(
state = state.value,
windowSizeClass = WindowSizeClass.calculateFromSize(dpSize),
onBack = {},
onClickTaskExecution = { taskId, executionId ->

},
modifier = Modifier.fillMaxSize()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TaskDetailViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
) : ViewModel() {

private val _state = mutableStateOf(TaskDetailUiState())
private val _state = mutableStateOf(TaskDetailUiState(taskId = 0))
val state: State<TaskDetailUiState> = _state

private val _taskId = mutableIntStateOf(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fun CompletedExecutionComponent(
private fun ExecutionComponentPreview() {
CompletedExecutionComponent(
state = ExecutionUiState(
id = 0,
startDate = "00/00/0000",
endDate = "00/07/0000",
startHour = "00:00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fun UnCompletedExecutionComponent(
private fun UnCompletedExecutionComponentPreview() {
UnCompletedExecutionComponent(
state = ExecutionUiState(
id = 0,
startDate = "22/03/2002",
endDate = "22/03/2002",
startHour = "01:00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution.
import com.braiso_22.cozycave.feature_execution.presentation.add_edit_execution.state.toFormatedTime

data class ExecutionUiState(
val id: Int,
val startDate: String,
val endDate: String,
val startHour: String,
val endHour: String,
)

fun Execution.toUiState() = ExecutionUiState(
id = this.id,
startDate = this.startDateTime.toFormatedDate(),
startHour = this.startDateTime.toFormatedTime(),
endDate = this.endDateTime.toFormatedDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import com.braiso_22.cozycave.feature_execution.domain.Execution
import com.braiso_22.cozycave.feature_task.domain.TaskWithExecutions

data class TaskDetailUiState(
val taskId: Int,
val name: String = "Task",
val completedExecutions: List<ExecutionUiState> = emptyList(),
val unFinishedExecutions: List<ExecutionUiState> = emptyList(),
)

fun TaskWithExecutions.toUiState(): TaskDetailUiState = TaskDetailUiState(
taskId = this.task.id,
name = this.task.name,
completedExecutions = this.executions.filter {
it.finished
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.braiso_22.cozycave.router

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
Expand Down Expand Up @@ -153,6 +152,9 @@ fun AppNavigation(
onBack = {
navController.popBackStack()
},
onClickTaskExecution = { taskId, executionId ->
navController.navigate(AppScreens.AddEditExecution.route + taskId + "/true/" + executionId)
},
modifier = modifier.fillMaxSize()
)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<string name="add_execution">Add execution</string>
<string name="execution_saved_correctly">Execution saved correctly</string>
<string name="task_detail">Task detail</string>
<string name="edit_execution">Edit execution</string>
</resources>

0 comments on commit b7fa543

Please sign in to comment.