Skip to content

Commit

Permalink
surveys: smoother numbers (fixes #4833) (#4842)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
deeppp15 and dogi authored Dec 5, 2024
1 parent 667e525 commit cf00e2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 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 2127
versionName "0.21.27"
versionCode 2128
versionName "0.21.28"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) } ?: ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down

0 comments on commit cf00e2f

Please sign in to comment.