Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #314: Enroling already enroled course does not give meaningful error #344

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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