From cf00e2f442054ecbf2b0ffc6d4f9b152ead7e7c0 Mon Sep 17 00:00:00 2001 From: Deep Vora <70479785+deeppp15@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:00:13 -0500 Subject: [PATCH] surveys: smoother numbers (fixes #4833) (#4842) Co-authored-by: dogi --- app/build.gradle | 4 +-- .../planet/myplanet/model/RealmSubmission.kt | 27 ++++++++++++++----- .../myplanet/ui/survey/AdapterSurvey.kt | 4 +-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 04da2d8270..c8fdf45da2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 26 targetSdkVersion 34 - versionCode 2127 - versionName "0.21.27" + versionCode 2128 + versionName "0.21.28" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt index ba34e3b34b..f36ec0262c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt @@ -204,12 +204,25 @@ open class RealmSubmission : RealmObject() { } } + fun generateParentId(courseId: String?, examId: String?): String? { + return if (!examId.isNullOrEmpty()) { + if (!courseId.isNullOrEmpty()) { + "$examId@$courseId" + } else { + examId + } + } else { + null + } + } + @JvmStatic - fun getNoOfSubmissionByUser(id: String?, userId: String?, mRealm: Realm): String { + fun getNoOfSubmissionByUser(id: String?, courseId:String?, userId: String?, mRealm: Realm): String { if (id == null || userId == null) return "No Submissions Found" - + val submissionParentId= generateParentId(courseId, id) + if(submissionParentId.isNullOrEmpty()) return "No Submissions Found" val submissionCount = mRealm.where(RealmSubmission::class.java) - .equalTo("parentId", id) + .equalTo("parentId", submissionParentId) .equalTo("userId", userId) .equalTo("status", "complete") .count().toInt() @@ -230,15 +243,15 @@ open class RealmSubmission : RealmObject() { } @JvmStatic - fun getRecentSubmissionDate(id: String?, userId: String?, mRealm: Realm): String { + fun getRecentSubmissionDate(id: String?, courseId:String?, userId: String?, mRealm: Realm): String { if (id == null || userId == null) return "" - + val submissionParentId= generateParentId(courseId, id) + if(submissionParentId.isNullOrEmpty()) return "" val recentSubmission = mRealm.where(RealmSubmission::class.java) - .equalTo("parentId", id) + .equalTo("parentId", submissionParentId) .equalTo("userId", userId) .sort("startTime", Sort.DESCENDING) .findFirst() - return recentSubmission?.startTime?.let { TimeUtils.getFormatedDateWithTime(it) } ?: "" } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt b/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt index e4551d0ae7..b618711e36 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt @@ -85,8 +85,8 @@ class AdapterSurvey(private val context: Context, private val mRealm: Realm, pri startSurvey.visibility = View.GONE } - tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, user?.id, mRealm) - tvDateCompleted.text = getRecentSubmissionDate(exam.id, user?.id, mRealm) + tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, exam.courseId, user?.id, mRealm) + tvDateCompleted.text = getRecentSubmissionDate(exam.id, exam.courseId, user?.id, mRealm) tvDate.text = formatDate(RealmStepExam.getSurveyCreationTime(exam.id!!, mRealm)!!, "MMM dd, yyyy") } }