#109 archiving subject archives all tasks of subject
This commit is contained in:
parent
a7752e5706
commit
93aae20f85
4 changed files with 26 additions and 3 deletions
|
@ -13,6 +13,8 @@ interface SubjectDAO {
|
||||||
|
|
||||||
fun updateSubject(newSubject: Subject)
|
fun updateSubject(newSubject: Subject)
|
||||||
|
|
||||||
|
suspend fun archiveSubject(subject: Subject)
|
||||||
|
|
||||||
fun getTaskCount(subject: Subject): Flow<Int>
|
fun getTaskCount(subject: Subject): Flow<Int>
|
||||||
fun getCompletedTaskCount(subject: Subject): Flow<Int>
|
fun getCompletedTaskCount(subject: Subject): Flow<Int>
|
||||||
fun getStudyTime(subject: Subject): Flow<Int>
|
fun getStudyTime(subject: Subject): Flow<Int>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package be.ugent.sel.studeez.domain.implementation
|
package be.ugent.sel.studeez.domain.implementation
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import be.ugent.sel.studeez.data.local.models.task.Subject
|
import be.ugent.sel.studeez.data.local.models.task.Subject
|
||||||
import be.ugent.sel.studeez.data.local.models.task.SubjectDocument
|
import be.ugent.sel.studeez.data.local.models.task.SubjectDocument
|
||||||
import be.ugent.sel.studeez.data.local.models.task.Task
|
import be.ugent.sel.studeez.data.local.models.task.Task
|
||||||
|
import be.ugent.sel.studeez.data.local.models.task.TaskDocument
|
||||||
import be.ugent.sel.studeez.domain.AccountDAO
|
import be.ugent.sel.studeez.domain.AccountDAO
|
||||||
import be.ugent.sel.studeez.domain.SubjectDAO
|
import be.ugent.sel.studeez.domain.SubjectDAO
|
||||||
import be.ugent.sel.studeez.domain.TaskDAO
|
import be.ugent.sel.studeez.domain.TaskDAO
|
||||||
|
@ -45,6 +47,18 @@ class FireBaseSubjectDAO @Inject constructor(
|
||||||
currentUserSubjectsCollection().document(newSubject.id).set(newSubject)
|
currentUserSubjectsCollection().document(newSubject.id).set(newSubject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun archiveSubject(subject: Subject) {
|
||||||
|
currentUserSubjectsCollection().document(subject.id).update(SubjectDocument.archived, true)
|
||||||
|
currentUserSubjectsCollection().document(subject.id)
|
||||||
|
.collection(FireBaseCollections.TASK_COLLECTION)
|
||||||
|
.taskNotArchived()
|
||||||
|
.get().await()
|
||||||
|
.documents
|
||||||
|
.forEach {
|
||||||
|
it.reference.update(TaskDocument.archived, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getTaskCount(subject: Subject): Flow<Int> {
|
override fun getTaskCount(subject: Subject): Flow<Int> {
|
||||||
return taskDAO.getTasks(subject)
|
return taskDAO.getTasks(subject)
|
||||||
.map(List<Task>::count)
|
.map(List<Task>::count)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import androidx.compose.material.OutlinedTextField
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
@ -16,6 +17,7 @@ import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
||||||
import be.ugent.sel.studeez.common.ext.basicButton
|
import be.ugent.sel.studeez.common.ext.basicButton
|
||||||
import be.ugent.sel.studeez.common.ext.fieldModifier
|
import be.ugent.sel.studeez.common.ext.fieldModifier
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
import be.ugent.sel.studeez.R.string as AppText
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -42,6 +44,7 @@ fun SubjectEditRoute(
|
||||||
viewModel: SubjectEditFormViewModel,
|
viewModel: SubjectEditFormViewModel,
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState
|
val uiState by viewModel.uiState
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
SubjectForm(
|
SubjectForm(
|
||||||
title = AppText.edit_subject,
|
title = AppText.edit_subject,
|
||||||
goBack = goBack,
|
goBack = goBack,
|
||||||
|
@ -51,7 +54,9 @@ fun SubjectEditRoute(
|
||||||
onColorChange = {},
|
onColorChange = {},
|
||||||
) {
|
) {
|
||||||
DeleteButton(text = AppText.delete_subject) {
|
DeleteButton(text = AppText.delete_subject) {
|
||||||
viewModel.onDelete(openAndPopUp)
|
coroutineScope.launch {
|
||||||
|
viewModel.onDelete(openAndPopUp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import be.ugent.sel.studeez.data.SelectedSubject
|
||||||
import be.ugent.sel.studeez.data.local.models.task.Subject
|
import be.ugent.sel.studeez.data.local.models.task.Subject
|
||||||
import be.ugent.sel.studeez.domain.LogService
|
import be.ugent.sel.studeez.domain.LogService
|
||||||
import be.ugent.sel.studeez.domain.SubjectDAO
|
import be.ugent.sel.studeez.domain.SubjectDAO
|
||||||
|
import be.ugent.sel.studeez.domain.TaskDAO
|
||||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
||||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
@ -59,6 +60,7 @@ class SubjectCreateFormViewModel @Inject constructor(
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SubjectEditFormViewModel @Inject constructor(
|
class SubjectEditFormViewModel @Inject constructor(
|
||||||
subjectDAO: SubjectDAO,
|
subjectDAO: SubjectDAO,
|
||||||
|
private val taskDAO: TaskDAO,
|
||||||
selectedSubject: SelectedSubject,
|
selectedSubject: SelectedSubject,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
) : SubjectFormViewModel(subjectDAO, selectedSubject, logService) {
|
) : SubjectFormViewModel(subjectDAO, selectedSubject, logService) {
|
||||||
|
@ -69,8 +71,8 @@ class SubjectEditFormViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun onDelete(openAndPopUp: (String, String) -> Unit) {
|
suspend fun onDelete(openAndPopUp: (String, String) -> Unit) {
|
||||||
subjectDAO.updateSubject(selectedSubject().copy(archived = true))
|
subjectDAO.archiveSubject(selectedSubject())
|
||||||
openAndPopUp(StudeezDestinations.SUBJECT_SCREEN, StudeezDestinations.EDIT_SUBJECT_FORM)
|
openAndPopUp(StudeezDestinations.SUBJECT_SCREEN, StudeezDestinations.EDIT_SUBJECT_FORM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue