Skip to content

Commit

Permalink
Merge branch 'master' into 4598-myHealth-update
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Oct 15, 2024
2 parents 72df4a1 + d83e15e commit 55da128
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class NotificationsFragment : Fragment() {

override fun onDestroy() {
super.onDestroy()
mRealm.close()
if (::mRealm.isInitialized) {
mRealm.close()
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginTop="@dimen/_10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/team" />
app:layout_constraintTop_toBottomOf="@+id/team"
app:layout_constraintVertical_bias="0.1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
Expand Down

0 comments on commit 55da128

Please sign in to comment.