show studytime
This commit is contained in:
		
							parent
							
								
									ec31e116b4
								
							
						
					
					
						commit
						e9cc4f4a0c
					
				
					 3 changed files with 25 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -9,6 +9,8 @@ import androidx.compose.material.Text
 | 
			
		|||
import androidx.compose.material.icons.Icons
 | 
			
		||||
import androidx.compose.material.icons.filled.List
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.runtime.collectAsState
 | 
			
		||||
import androidx.compose.runtime.getValue
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.draw.clip
 | 
			
		||||
| 
						 | 
				
			
			@ -21,13 +23,17 @@ import androidx.compose.ui.unit.dp
 | 
			
		|||
import be.ugent.sel.studeez.common.composable.StealthButton
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Subject
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
import kotlinx.coroutines.flow.flowOf
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SubjectEntry(
 | 
			
		||||
    subject: Subject,
 | 
			
		||||
    onViewSubject: () -> Unit,
 | 
			
		||||
    getStudyTime: () -> Flow<Int>,
 | 
			
		||||
) {
 | 
			
		||||
    val studytime by getStudyTime().collectAsState(initial = 0)
 | 
			
		||||
    Card(
 | 
			
		||||
        modifier = Modifier
 | 
			
		||||
            .fillMaxWidth()
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +70,7 @@ fun SubjectEntry(
 | 
			
		|||
                        verticalAlignment = Alignment.CenterVertically,
 | 
			
		||||
                    ) {
 | 
			
		||||
                        Text(
 | 
			
		||||
                            text = HoursMinutesSeconds(subject.time).toString(),
 | 
			
		||||
                            text = HoursMinutesSeconds(studytime).toString(),
 | 
			
		||||
                        )
 | 
			
		||||
                        Row(
 | 
			
		||||
                            verticalAlignment = Alignment.CenterVertically,
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +80,7 @@ fun SubjectEntry(
 | 
			
		|||
                                imageVector = Icons.Default.List,
 | 
			
		||||
                                contentDescription = stringResource(id = AppText.tasks)
 | 
			
		||||
                            )
 | 
			
		||||
                            Text(text = "${subject.taskCompletedCount}/${subject.taskCount}") // TODO
 | 
			
		||||
                            Text(text = "${subject.taskCompletedCount}/${subject.taskCount}")
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -98,11 +104,12 @@ fun SubjectEntryPreview() {
 | 
			
		|||
        subject = Subject(
 | 
			
		||||
            name = "Test Subject",
 | 
			
		||||
            argb_color = 0xFFFFD200,
 | 
			
		||||
            time = 60,
 | 
			
		||||
            taskCount = 5,
 | 
			
		||||
            taskCompletedCount = 2,
 | 
			
		||||
        ),
 | 
			
		||||
    ) {}
 | 
			
		||||
        onViewSubject = {},
 | 
			
		||||
        getStudyTime = { flowOf() }
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +119,8 @@ fun OverflowSubjectEntryPreview() {
 | 
			
		|||
        subject = Subject(
 | 
			
		||||
            name = "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
 | 
			
		||||
            argb_color = 0xFFFFD200,
 | 
			
		||||
            time = 60,
 | 
			
		||||
        ),
 | 
			
		||||
    ) {}
 | 
			
		||||
        onViewSubject = {},
 | 
			
		||||
        getStudyTime = { flowOf() }
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -19,6 +19,8 @@ import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
 | 
			
		|||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.tasks.SubjectEntry
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.task.Subject
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
import kotlinx.coroutines.flow.flowOf
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +36,7 @@ fun SubjectRoute(
 | 
			
		|||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        onAddSubject = { viewModel.onAddSubject(open) },
 | 
			
		||||
        onViewSubject = { viewModel.onViewSubject(it, open) },
 | 
			
		||||
        getStudyTime = viewModel::getStudyTime,
 | 
			
		||||
        uiState,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +47,7 @@ fun SubjectScreen(
 | 
			
		|||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
    onAddSubject: () -> Unit,
 | 
			
		||||
    onViewSubject: (Subject) -> Unit,
 | 
			
		||||
    getStudyTime: (Subject) -> Flow<Int>,
 | 
			
		||||
    uiState: SubjectUiState,
 | 
			
		||||
) {
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
| 
						 | 
				
			
			@ -72,6 +76,7 @@ fun SubjectScreen(
 | 
			
		|||
                            SubjectEntry(
 | 
			
		||||
                                subject = it,
 | 
			
		||||
                                onViewSubject = { onViewSubject(it) },
 | 
			
		||||
                                getStudyTime = { getStudyTime(it) },
 | 
			
		||||
                            )
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +94,7 @@ fun SubjectScreenPreview() {
 | 
			
		|||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}, {}, {}, {}),
 | 
			
		||||
        onAddSubject = {},
 | 
			
		||||
        onViewSubject = {},
 | 
			
		||||
        getStudyTime = { flowOf() },
 | 
			
		||||
        uiState = SubjectUiState.Succes(
 | 
			
		||||
            listOf(
 | 
			
		||||
                Subject(
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +115,7 @@ fun SubjectScreenLoadingPreview() {
 | 
			
		|||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}, {}, {}, {}),
 | 
			
		||||
        onAddSubject = {},
 | 
			
		||||
        onViewSubject = {},
 | 
			
		||||
        getStudyTime = { flowOf() },
 | 
			
		||||
        uiState = SubjectUiState.Loading
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +30,10 @@ class SubjectViewModel @Inject constructor(
 | 
			
		|||
        open(StudeezDestinations.ADD_SUBJECT_FORM)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun getStudyTime(subject: Subject): Flow<Int> {
 | 
			
		||||
        return subjectDAO.getStudyTime(subject)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onViewSubject(subject: Subject, open: (String) -> Unit) {
 | 
			
		||||
        selectedSubject.set(subject)
 | 
			
		||||
        open(StudeezDestinations.TASKS_SCREEN)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue