archive subjects
This commit is contained in:
		
							parent
							
								
									d4c017ef1b
								
							
						
					
					
						commit
						c3424b9996
					
				
					 5 changed files with 26 additions and 14 deletions
				
			
		|  | @ -7,10 +7,16 @@ data class Subject( | ||||||
|     @DocumentId val id: String = "", |     @DocumentId val id: String = "", | ||||||
|     val name: String = "", |     val name: String = "", | ||||||
|     val argb_color: Long = 0, |     val argb_color: Long = 0, | ||||||
|  |     var archived: Boolean = false, | ||||||
|     @get:Exclude @set:Exclude |     @get:Exclude @set:Exclude | ||||||
|     var taskCount: Int = 0, |     var taskCount: Int = 0, | ||||||
|     @get:Exclude @set:Exclude |     @get:Exclude @set:Exclude | ||||||
|     var taskCompletedCount: Int = 0, |     var taskCompletedCount: Int = 0, | ||||||
|     @get:Exclude @set:Exclude |  | ||||||
|     var time: Int = 0, |  | ||||||
| ) | ) | ||||||
|  | 
 | ||||||
|  | object SubjectDocument { | ||||||
|  |     const val id = "id" | ||||||
|  |     const val name = "name" | ||||||
|  |     const val archived = "archived" | ||||||
|  |     const val argb_color = "argb_color" | ||||||
|  | } | ||||||
|  | @ -1,12 +1,14 @@ | ||||||
| package be.ugent.sel.studeez.domain.implementation | package be.ugent.sel.studeez.domain.implementation | ||||||
| 
 | 
 | ||||||
| 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.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 | ||||||
| import com.google.firebase.firestore.AggregateSource | import com.google.firebase.firestore.AggregateSource | ||||||
| import com.google.firebase.firestore.CollectionReference | import com.google.firebase.firestore.CollectionReference | ||||||
| import com.google.firebase.firestore.FirebaseFirestore | import com.google.firebase.firestore.FirebaseFirestore | ||||||
|  | import com.google.firebase.firestore.Query | ||||||
| import com.google.firebase.firestore.ktx.snapshots | import com.google.firebase.firestore.ktx.snapshots | ||||||
| import com.google.firebase.firestore.ktx.toObject | import com.google.firebase.firestore.ktx.toObject | ||||||
| import kotlinx.coroutines.flow.Flow | import kotlinx.coroutines.flow.Flow | ||||||
|  | @ -21,6 +23,7 @@ class FireBaseSubjectDAO @Inject constructor( | ||||||
| ) : SubjectDAO { | ) : SubjectDAO { | ||||||
|     override fun getSubjects(): Flow<List<Subject>> { |     override fun getSubjects(): Flow<List<Subject>> { | ||||||
|         return currentUserSubjectsCollection() |         return currentUserSubjectsCollection() | ||||||
|  |             .subjectNotArchived() | ||||||
|             .snapshots() |             .snapshots() | ||||||
|             .map { it.toObjects(Subject::class.java) } |             .map { it.toObjects(Subject::class.java) } | ||||||
|             .map { subjects -> |             .map { subjects -> | ||||||
|  | @ -50,7 +53,7 @@ class FireBaseSubjectDAO @Inject constructor( | ||||||
| 
 | 
 | ||||||
|     override suspend fun getTaskCount(subject: Subject): Int { |     override suspend fun getTaskCount(subject: Subject): Int { | ||||||
|         return subjectTasksCollection(subject) |         return subjectTasksCollection(subject) | ||||||
|             .nonArchived() |             .taskNotArchived() | ||||||
|             .count() |             .count() | ||||||
|             .get(AggregateSource.SERVER) |             .get(AggregateSource.SERVER) | ||||||
|             .await() |             .await() | ||||||
|  | @ -59,8 +62,8 @@ class FireBaseSubjectDAO @Inject constructor( | ||||||
| 
 | 
 | ||||||
|     override suspend fun getCompletedTaskCount(subject: Subject): Int { |     override suspend fun getCompletedTaskCount(subject: Subject): Int { | ||||||
|         return subjectTasksCollection(subject) |         return subjectTasksCollection(subject) | ||||||
|             .nonArchived() |             .taskNotArchived() | ||||||
|             .completed() |             .taskNotCompleted() | ||||||
|             .count() |             .count() | ||||||
|             .get(AggregateSource.SERVER) |             .get(AggregateSource.SERVER) | ||||||
|             .await() |             .await() | ||||||
|  | @ -83,4 +86,10 @@ class FireBaseSubjectDAO @Inject constructor( | ||||||
|             .collection(FireBaseCollections.SUBJECT_COLLECTION) |             .collection(FireBaseCollections.SUBJECT_COLLECTION) | ||||||
|             .document(subject.id) |             .document(subject.id) | ||||||
|             .collection(FireBaseCollections.TASK_COLLECTION) |             .collection(FireBaseCollections.TASK_COLLECTION) | ||||||
|  | 
 | ||||||
|  |     fun CollectionReference.subjectNotArchived(): Query = | ||||||
|  |         this.whereEqualTo(SubjectDocument.archived, false) | ||||||
|  | 
 | ||||||
|  |     fun Query.subjectNotArchived(): Query = | ||||||
|  |         this.whereEqualTo(SubjectDocument.archived, false) | ||||||
| } | } | ||||||
|  | @ -21,7 +21,7 @@ class FireBaseTaskDAO @Inject constructor( | ||||||
| ) : TaskDAO { | ) : TaskDAO { | ||||||
|     override fun getTasks(subject: Subject): Flow<List<Task>> { |     override fun getTasks(subject: Subject): Flow<List<Task>> { | ||||||
|         return selectedSubjectTasksCollection(subject.id) |         return selectedSubjectTasksCollection(subject.id) | ||||||
|             .nonArchived() |             .taskNotArchived() | ||||||
|             .snapshots() |             .snapshots() | ||||||
|             .map { it.toObjects(Task::class.java) } |             .map { it.toObjects(Task::class.java) } | ||||||
|     } |     } | ||||||
|  | @ -55,14 +55,14 @@ class FireBaseTaskDAO @Inject constructor( | ||||||
| 
 | 
 | ||||||
| // Extend CollectionReference and Query with some filters | // Extend CollectionReference and Query with some filters | ||||||
| 
 | 
 | ||||||
| fun CollectionReference.nonArchived(): Query = | fun CollectionReference.taskNotArchived(): Query = | ||||||
|     this.whereEqualTo(TaskDocument.archived, false) |     this.whereEqualTo(TaskDocument.archived, false) | ||||||
| 
 | 
 | ||||||
| fun Query.nonArchived(): Query = | fun Query.taskNotArchived(): Query = | ||||||
|     this.whereEqualTo(TaskDocument.archived, false) |     this.whereEqualTo(TaskDocument.archived, false) | ||||||
| 
 | 
 | ||||||
| fun CollectionReference.completed(): Query = | fun CollectionReference.taskNotCompleted(): Query = | ||||||
|     this.whereEqualTo(TaskDocument.completed, true) |     this.whereEqualTo(TaskDocument.completed, true) | ||||||
| 
 | 
 | ||||||
| fun Query.completed(): Query = | fun Query.taskNotCompleted(): Query = | ||||||
|     this.whereEqualTo(TaskDocument.completed, true) |     this.whereEqualTo(TaskDocument.completed, true) | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ class SubjectEditFormViewModel @Inject constructor( | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     fun onDelete(openAndPopUp: (String, String) -> Unit) { |     fun onDelete(openAndPopUp: (String, String) -> Unit) { | ||||||
|         subjectDAO.deleteSubject(selectedSubject()) |         subjectDAO.updateSubject(selectedSubject().copy(archived = true)) | ||||||
|         openAndPopUp(StudeezDestinations.SUBJECT_SCREEN, StudeezDestinations.EDIT_SUBJECT_FORM) |         openAndPopUp(StudeezDestinations.SUBJECT_SCREEN, StudeezDestinations.EDIT_SUBJECT_FORM) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,7 +27,6 @@ data class TaskActions( | ||||||
|     val addTask: () -> Unit, |     val addTask: () -> Unit, | ||||||
|     val getSubject: () -> Subject, |     val getSubject: () -> Subject, | ||||||
|     val getTasks: () -> Flow<List<Task>>, |     val getTasks: () -> Flow<List<Task>>, | ||||||
|     val deleteTask: (Task) -> Unit, |  | ||||||
|     val onCheckTask: (Task, Boolean) -> Unit, |     val onCheckTask: (Task, Boolean) -> Unit, | ||||||
|     val editSubject: () -> Unit, |     val editSubject: () -> Unit, | ||||||
|     val startTask: (Task) -> Unit, |     val startTask: (Task) -> Unit, | ||||||
|  | @ -39,7 +38,6 @@ fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskAction | ||||||
|         addTask = { viewModel.addTask(open) }, |         addTask = { viewModel.addTask(open) }, | ||||||
|         getTasks = viewModel::getTasks, |         getTasks = viewModel::getTasks, | ||||||
|         getSubject = viewModel::getSelectedSubject, |         getSubject = viewModel::getSelectedSubject, | ||||||
|         deleteTask = viewModel::deleteTask, |  | ||||||
|         onCheckTask = { task, isChecked -> viewModel.toggleTaskCompleted(task, isChecked) }, |         onCheckTask = { task, isChecked -> viewModel.toggleTaskCompleted(task, isChecked) }, | ||||||
|         editSubject = { viewModel.editSubject(open) }, |         editSubject = { viewModel.editSubject(open) }, | ||||||
|         startTask = { task -> viewModel.startTask(task, open) }, |         startTask = { task -> viewModel.startTask(task, open) }, | ||||||
|  | @ -110,7 +108,6 @@ fun TaskScreenPreview() { | ||||||
|             {}, |             {}, | ||||||
|             { Subject(name = "Test Subject") }, |             { Subject(name = "Test Subject") }, | ||||||
|             { flowOf() }, |             { flowOf() }, | ||||||
|             {}, |  | ||||||
|             { _, _ -> run {} }, |             { _, _ -> run {} }, | ||||||
|             {}, |             {}, | ||||||
|             {}, |             {}, | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie