Skip to content

Commit

Permalink
Fix: NPE when opening notification for course not available locally
Browse files Browse the repository at this point in the history
Partially closes crux-bphc#304
  • Loading branch information
abhijeetviswa committed Mar 20, 2021
1 parent 232ead1 commit 9e20ac5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions app/src/main/java/crux/bphc/cms/activities/CourseDetailActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import io.realm.Realm
class CourseDetailActivity : AppCompatActivity() {
private lateinit var realm: Realm

private var course: Course? = null
private lateinit var course: Course

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -52,17 +52,17 @@ class CourseDetailActivity : AppCompatActivity() {
courseId = enrolCourse!!.id
}

course = realm
.where(Course::class.java)
.equalTo("id", courseId)
.findFirst()
this.course = realm
.where(Course::class.java)
.equalTo("id", courseId)
.findFirst() ?: Course(courseId)

// check if enrolled
if (course == null) {
setCourseEnrol(enrolCourse!!)
title = enrolCourse!!.shortName
if (courseId == -1 && enrolCourse != null) {
setCourseEnrol(enrolCourse)
title = enrolCourse.shortName
} else {
title = course!!.shortName
title = course.shortName

val url = Uri.parse(contextUrl) ?: Uri.EMPTY
if (Urls.isCourseSectionUrl(url) || Urls.isCourseModuleUrl(url)) {
Expand Down Expand Up @@ -96,7 +96,7 @@ class CourseDetailActivity : AppCompatActivity() {
val fragmentTransaction = supportFragmentManager.beginTransaction()
val courseSectionFragment = CourseContentFragment.newInstance(
UserAccount.token,
course!!.id,
course.id,
contextUrl,
)
fragmentTransaction.replace(
Expand All @@ -111,7 +111,7 @@ class CourseDetailActivity : AppCompatActivity() {
setCourseContentFragment("")
supportFragmentManager.executePendingTransactions()
val fragmentTransaction = supportFragmentManager.beginTransaction()
val forumFragment: Fragment = ForumFragment.newInstance(course!!.id, forumId, course!!.shortName)
val forumFragment: Fragment = ForumFragment.newInstance(course.id, forumId, course.shortName)
fragmentTransaction.addToBackStack(null)
.replace(R.id.course_section_enrol_container, forumFragment, "Announcements")
fragmentTransaction.commit()
Expand All @@ -125,10 +125,10 @@ class CourseDetailActivity : AppCompatActivity() {
supportFragmentManager.executePendingTransactions()
val fragmentTransaction = supportFragmentManager.beginTransaction()
val discussionFragment: Fragment = DiscussionFragment.newInstance(
course!!.id,
course.id,
forumId,
discussionId,
course!!.shortName
course.shortName
)
fragmentTransaction.addToBackStack(null)
.replace(R.id.course_section_enrol_container, discussionFragment, "Discussion")
Expand Down

0 comments on commit 9e20ac5

Please sign in to comment.