-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Teacher][MBL-8756] Route to module items from module list (#32)
- Loading branch information
1 parent
2fc434b
commit 179adf2
Showing
26 changed files
with
863 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...r/src/main/java/com/instructure/teacher/features/modules/list/ModuleListEventBusSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2019 - present Instructure, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
package com.instructure.teacher.features.modules.list | ||
|
||
import com.instructure.canvasapi2.models.ModuleItem | ||
import com.instructure.teacher.events.* | ||
import com.instructure.teacher.mobius.common.EventBusSource | ||
import org.greenrobot.eventbus.Subscribe | ||
|
||
@Suppress("unused") | ||
class ModuleListEventBusSource : EventBusSource<ModuleListEvent>() { | ||
|
||
private val subId = ModuleListEventBusSource::class.java.name | ||
|
||
@Subscribe(sticky = true) | ||
fun onAssignmentEdited(event: AssignmentUpdatedEvent) { | ||
event.once(subId) { assignmentId -> updateModuleItem("Assignment") { it.contentId == assignmentId } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onAssignmentDeleted(event: AssignmentDeletedEvent) { | ||
event.once(subId) { assignmentId -> deleteModuleItem("Assignment") { it.contentId == assignmentId } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onDiscussionUpdate(event: DiscussionUpdatedEvent) { | ||
event.once(subId) { discussion -> updateModuleItem("Discussion") { it.contentId == discussion.id } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onDiscussionDeleted(event: DiscussionTopicHeaderDeletedEvent) { | ||
event.once(subId) { discussionId -> deleteModuleItem("Discussion") { it.contentId == discussionId } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onFileUpdated(event: FileFolderUpdatedEvent) { | ||
event.once(subId) { file -> updateModuleItem("File") { it.contentId == file.id } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onFileDeleted(event: FileFolderDeletedEvent) { | ||
event.once(subId) { file -> deleteModuleItem("File") { it.contentId == file.id } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onPageUpdated(event : PageUpdatedEvent) { | ||
event.once(subId) { page -> | ||
/* The module API does not expose the page ID in module items, so we must use the page URL to identify | ||
which page was updated. Unfortunately that URL is based on the page name, so if the page name was | ||
updated then we have no way to uniquely identify and update that page. */ | ||
updateModuleItem("Page") { it.pageUrl == page.url } | ||
} | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onPageDeleted(event : PageDeletedEvent) { | ||
event.once(subId) { page -> deleteModuleItem("Page") { it.pageUrl == page.url } } | ||
} | ||
|
||
@Subscribe(sticky = true) | ||
fun onQuizUpdated(event: QuizUpdatedEvent) { | ||
event.once(subId) { quizId -> updateModuleItem("Quiz") { it.contentId == quizId } } | ||
} | ||
|
||
private fun updateModuleItem(type: String, predicate: (item: ModuleItem) -> Boolean) { | ||
sendEvent(ModuleListEvent.ItemRefreshRequested(type, predicate)) | ||
} | ||
|
||
private fun deleteModuleItem(type: String, predicate: (item: ModuleItem) -> Boolean) { | ||
sendEvent(ModuleListEvent.RemoveModuleItems(type, predicate)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.