"#22 styling of task overview"
This commit is contained in:
		
							parent
							
								
									1a2e192227
								
							
						
					
					
						commit
						e1c05bb0d4
					
				
					 9 changed files with 140 additions and 37 deletions
				
			
		| 
						 | 
				
			
			@ -31,7 +31,9 @@ fun SubjectRoute(
 | 
			
		|||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        addSubject = { viewModel.addSubject() },
 | 
			
		||||
    ) { viewModel.getSubjects() }
 | 
			
		||||
        getSubjects = viewModel::getSubjects,
 | 
			
		||||
        onViewSubject = { viewModel.onViewSubject(Subject(), open) },
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +42,7 @@ fun SubjectScreen(
 | 
			
		|||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
    addSubject: () -> Unit,
 | 
			
		||||
    getSubjects: () -> Flow<List<Subject>>,
 | 
			
		||||
    onViewSubject: () -> Unit,
 | 
			
		||||
) {
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.tasks),
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +69,10 @@ fun SubjectScreen(
 | 
			
		|||
//                    }
 | 
			
		||||
//                }
 | 
			
		||||
                items(subjects.value) {
 | 
			
		||||
                    SubjectEntry(subject = it)
 | 
			
		||||
                    SubjectEntry(
 | 
			
		||||
                        subject = it,
 | 
			
		||||
                        onViewSubject = onViewSubject,
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            NewTaskSubjectButton(onClick = addSubject, R.string.new_subject)
 | 
			
		||||
| 
						 | 
				
			
			@ -80,6 +86,8 @@ fun SubjectScreenPreview() {
 | 
			
		|||
    SubjectScreen(
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}),
 | 
			
		||||
        {},
 | 
			
		||||
    ) { flowOf() }
 | 
			
		||||
        addSubject = {},
 | 
			
		||||
        getSubjects = { flowOf() },
 | 
			
		||||
        onViewSubject = {},
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ package be.ugent.sel.studeez.screens.tasks
 | 
			
		|||
import be.ugent.sel.studeez.data.local.models.task.Subject
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.domain.SubjectDAO
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
| 
						 | 
				
			
			@ -27,4 +28,8 @@ class SubjectViewModel @Inject constructor(
 | 
			
		|||
    fun getSubjects(): Flow<List<Subject>> {
 | 
			
		||||
        return subjectDAO.getSubjects()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onViewSubject(subject: Subject, open: (String) -> Unit) {
 | 
			
		||||
        open(StudeezDestinations.TASKS_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,34 +1,115 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.tasks
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.layout.padding
 | 
			
		||||
import androidx.compose.foundation.lazy.LazyColumn
 | 
			
		||||
import androidx.compose.foundation.lazy.items
 | 
			
		||||
import androidx.compose.material.ButtonDefaults
 | 
			
		||||
import androidx.compose.material.Icon
 | 
			
		||||
import androidx.compose.material.IconButton
 | 
			
		||||
import androidx.compose.material.Text
 | 
			
		||||
import androidx.compose.material.icons.Icons
 | 
			
		||||
import androidx.compose.material.icons.filled.Edit
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.runtime.collectAsState
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.graphics.Color
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.BasicButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.NewTaskSubjectButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.ext.basicButton
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Subject
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Task
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
import kotlinx.coroutines.flow.flowOf
 | 
			
		||||
 | 
			
		||||
data class TaskActions(
 | 
			
		||||
    val addTask: () -> Unit,
 | 
			
		||||
    val getSubject: () -> Subject,
 | 
			
		||||
    val getTasks: () -> Flow<List<Task>>,
 | 
			
		||||
    val deleteSubject: () -> Unit,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
fun getTaskActions(viewModel: TaskViewModel): TaskActions {
 | 
			
		||||
    return TaskActions(
 | 
			
		||||
        addTask = viewModel::addTask,
 | 
			
		||||
        getTasks = viewModel::getTasks,
 | 
			
		||||
        getSubject = { Subject(name = "Test Subject") },
 | 
			
		||||
        deleteSubject = {},
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TaskRoute(
 | 
			
		||||
    goBack: () -> Unit,
 | 
			
		||||
    viewModel: TaskViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    TaskScreen(
 | 
			
		||||
        addTask = viewModel::addTask,
 | 
			
		||||
        getTasks = viewModel::getTasks,
 | 
			
		||||
        goBack = goBack,
 | 
			
		||||
        taskActions = getTaskActions(viewModel = viewModel),
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TaskScreen(
 | 
			
		||||
    addTask: () -> Unit,
 | 
			
		||||
    getTasks: () -> Flow<List<Task>>,
 | 
			
		||||
    goBack: () -> Unit,
 | 
			
		||||
    taskActions: TaskActions,
 | 
			
		||||
) {
 | 
			
		||||
    SecondaryScreenTemplate(
 | 
			
		||||
        title = taskActions.getSubject().name,
 | 
			
		||||
        popUp = goBack,
 | 
			
		||||
        barAction = { EditAction {} } // TODO implement
 | 
			
		||||
    ) {
 | 
			
		||||
        val tasks = taskActions.getTasks().collectAsState(initial = emptyList())
 | 
			
		||||
        Column(
 | 
			
		||||
            modifier = Modifier.padding(top = 5.dp)
 | 
			
		||||
        ) {
 | 
			
		||||
            LazyColumn {
 | 
			
		||||
                items(tasks.value) {
 | 
			
		||||
                    Text(text = it.name)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            NewTaskSubjectButton(onClick = taskActions.addTask, R.string.new_task)
 | 
			
		||||
            BasicButton(
 | 
			
		||||
                text = R.string.delete_subject,
 | 
			
		||||
                modifier = Modifier.basicButton(),
 | 
			
		||||
                colors = ButtonDefaults.buttonColors(
 | 
			
		||||
                    backgroundColor = Color.Red,
 | 
			
		||||
                    contentColor = Color.White,
 | 
			
		||||
                ),
 | 
			
		||||
                onClick = taskActions.deleteSubject,
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun EditAction(
 | 
			
		||||
    onClick: () -> Unit
 | 
			
		||||
) {
 | 
			
		||||
    IconButton(onClick = onClick) {
 | 
			
		||||
        Icon(
 | 
			
		||||
            imageVector = Icons.Default.Edit,
 | 
			
		||||
            contentDescription = resources().getString(R.string.edit_task)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun TaskScreenPreview() {
 | 
			
		||||
    TaskScreen(
 | 
			
		||||
        addTask = {},
 | 
			
		||||
        getTasks = { flowOf() }
 | 
			
		||||
        goBack = {},
 | 
			
		||||
        taskActions = TaskActions(
 | 
			
		||||
            {},
 | 
			
		||||
            { Subject(name = "Test Subject") },
 | 
			
		||||
            { flowOf() },
 | 
			
		||||
            {},
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.tasks
 | 
			
		||||
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Subject
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Task
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.domain.TaskDAO
 | 
			
		||||
| 
						 | 
				
			
			@ -19,15 +20,6 @@ class TaskViewModel @Inject constructor(
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    fun getTasks() : Flow<List<Task>> {
 | 
			
		||||
        return flowOf(listOf(
 | 
			
		||||
            Task(
 | 
			
		||||
                name = "Test Task",
 | 
			
		||||
                completed = false,
 | 
			
		||||
            ),
 | 
			
		||||
            Task(
 | 
			
		||||
                name = "Test Task 2",
 | 
			
		||||
                completed = true,
 | 
			
		||||
            )
 | 
			
		||||
        ))
 | 
			
		||||
        return taskDAO.getTasks(Subject())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue