From 9e20ac5236be0f6e07060aec4e498b75f0fe110d Mon Sep 17 00:00:00 2001 From: Abhijeet Viswa Date: Sat, 20 Mar 2021 11:33:01 +0530 Subject: [PATCH] Fix: NPE when opening notification for course not available locally Partially closes #304 --- .../cms/activities/CourseDetailActivity.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/crux/bphc/cms/activities/CourseDetailActivity.kt b/app/src/main/java/crux/bphc/cms/activities/CourseDetailActivity.kt index b0b67825..df3215e2 100644 --- a/app/src/main/java/crux/bphc/cms/activities/CourseDetailActivity.kt +++ b/app/src/main/java/crux/bphc/cms/activities/CourseDetailActivity.kt @@ -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) @@ -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)) { @@ -96,7 +96,7 @@ class CourseDetailActivity : AppCompatActivity() { val fragmentTransaction = supportFragmentManager.beginTransaction() val courseSectionFragment = CourseContentFragment.newInstance( UserAccount.token, - course!!.id, + course.id, contextUrl, ) fragmentTransaction.replace( @@ -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() @@ -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")