Skip to content

Commit

Permalink
courses: smoother survey retake (fixes #4608) (#4619)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
deeppp15 and dogi authored Oct 14, 2024
1 parent 27b9878 commit 7e8d24d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2020
versionName "0.20.20"
versionCode 2021
versionName "0.20.21"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import io.realm.Case
import io.realm.Realm
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.R
Expand Down Expand Up @@ -127,40 +126,34 @@ class CourseStepFragment : BaseContainerFragment(), ImageCaptureCallback {
fragmentCourseStepBinding.btnTakeSurvey.visibility = View.GONE
if (stepExams.isNotEmpty()) {
val firstStepId = stepExams[0].id
val questions = cRealm.where(RealmExamQuestion::class.java).equalTo("examId", firstStepId).findAll()
val submissionsCount = step.courseId?.let {
cRealm.where(RealmSubmission::class.java).equalTo("userId",user?.id).contains("parentId", it)
.notEqualTo("status", "pending", Case.INSENSITIVE).count()
}
if (questions != null && questions.size > 0) {
val examId=questions[0]?.examId

val isSubmitted = step.courseId?.let { courseId ->
val parentId = "$examId@$courseId"
cRealm.where(RealmSubmission::class.java)
.equalTo("userId",user?.id)
.equalTo("parentId", parentId)
.equalTo("type", "exam")
.findFirst() != null
} ?: false
fragmentCourseStepBinding.btnTakeTest.text = if (isSubmitted) { getString(R.string.retake_test, stepExams.size) } else { getString(R.string.take_test, stepExams.size) }
fragmentCourseStepBinding.btnTakeTest.visibility = View.VISIBLE
}
val isTestPersent = existsSubmission(firstStepId, "exam")
fragmentCourseStepBinding.btnTakeTest.text = if (isTestPersent) { getString(R.string.retake_test, stepExams.size) } else { getString(R.string.take_test, stepExams.size) }
fragmentCourseStepBinding.btnTakeTest.visibility = View.VISIBLE
}
if (stepSurvey.isNotEmpty()) {
val firstStepId = stepSurvey[0].id
val questions = cRealm.where(RealmExamQuestion::class.java).equalTo("examId", firstStepId).findAll()
val submissionsCount = step.courseId?.let {
cRealm.where(RealmSubmission::class.java).contains("parentId", it)
.notEqualTo("status", "pending", Case.INSENSITIVE).count()
}
if (questions != null && questions.size > 0) {
if (submissionsCount != null) {
fragmentCourseStepBinding.btnTakeSurvey.text = if (submissionsCount > 0) { "redo survey" } else { "record survey" }
}
fragmentCourseStepBinding.btnTakeSurvey.visibility = View.VISIBLE
val isSurveyPresent = existsSubmission(firstStepId, "survey")
fragmentCourseStepBinding.btnTakeSurvey.text = if (isSurveyPresent) { "redo survey" } else { "record survey" }
fragmentCourseStepBinding.btnTakeSurvey.visibility = View.VISIBLE
}
}

private fun existsSubmission(firstStepId:String? , submissionType: String): Boolean{
val questions = cRealm.where(RealmExamQuestion::class.java).equalTo("examId", firstStepId).findAll()
var isPresent=false
if (questions != null && questions.size > 0) {
val examId=questions[0]?.examId
val isSubmitted = step.courseId?.let { courseId ->
val parentId = "$examId@$courseId"
cRealm.where(RealmSubmission::class.java)
.equalTo("userId",user?.id)
.equalTo("parentId", parentId)
.equalTo("type", submissionType)
.findFirst() != null
} ?: false
isPresent= isSubmitted
}
return isPresent
}

override fun setMenuVisibility(visible: Boolean) {
Expand Down

0 comments on commit 7e8d24d

Please sign in to comment.