Skip to content

Commit

Permalink
Fix Enroling an already enroled course does not give a meaningful err…
Browse files Browse the repository at this point in the history
…or (#314)
  • Loading branch information
Code-R57 committed Jan 6, 2022
1 parent 4a21b96 commit 0296567
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/src/main/java/crux/bphc/cms/fragments/CourseEnrolFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crux.bphc.cms.fragments

import android.app.ProgressDialog
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
Expand All @@ -12,16 +13,21 @@ import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import crux.bphc.cms.R
import crux.bphc.cms.app.Urls
import crux.bphc.cms.fragments.CourseContentFragment.Companion.newInstance
import crux.bphc.cms.helper.CourseDataHandler
import crux.bphc.cms.helper.CourseRequestHandler
import crux.bphc.cms.models.UserAccount
import crux.bphc.cms.models.course.Course
import crux.bphc.cms.models.enrol.SearchedCourseDetail
import crux.bphc.cms.models.enrol.SelfEnrol
import crux.bphc.cms.network.MoodleServices
import io.realm.Realm
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -55,6 +61,25 @@ class CourseEnrolFragment : Fragment() {
val teachers = course.contacts
val noTeacherInfo = view.findViewById<TextView>(R.id.course_enrol_teacher_no_info)
val mEnrolButton = view.findViewById<Button>(R.id.course_enrol_enrol_button)
val courses: MutableList<Course> = ArrayList()

lifecycleScope.launch {
launch(Dispatchers.IO) {
val courseRequestHandler = CourseRequestHandler()
try {
val courseList = courseRequestHandler.fetchCourseListSync()
courses.clear()
courses.addAll(courseList)
val realm = Realm.getDefaultInstance() // tie a realm instance to this thread
val courseDataHandler = CourseDataHandler(realm)
courseDataHandler.replaceCourses(courseList)
realm.close()

} catch (e: Exception) {
Log.e("CourseEnrolFragment", "", e)
}
}
}

mCourseDisplayName.text = course.displayName
mCourseCategory.text = course.categoryName
Expand Down Expand Up @@ -130,7 +155,7 @@ class CourseEnrolFragment : Fragment() {
.replace(R.id.course_section_enrol_container, courseSectionFragment)
.commit()
} else {
Toast.makeText(activity, "Unknown error occurred", Toast.LENGTH_SHORT).show()
Toast.makeText(activity, R.string.course_enrol_course_already_enrolled_msg, Toast.LENGTH_SHORT).show()
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="course_enrol_self_enrol_button">Enrol me</string>
<string name="course_enrol_teachers_no_info">No information available about teachers</string>
<string name="course_enrol_confirmation_msg">Are you sure you want to enrol yourself in this course?</string>
<string name="course_enrol_course_already_enrolled_msg">You are already enrolled in this course</string>

<!-- App Info -->
<string name="app_info"><![CDATA[This companion app for Moodle (CMS) is open source. It provides live notifications
Expand Down

0 comments on commit 0296567

Please sign in to comment.