Skip to content

Commit

Permalink
Fixed notification of pending surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
deeppp15 committed Dec 18, 2024
1 parent 9a640a0 commit 517f899
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ open class RealmNotification : RealmObject() {
var createdAt: Date = Date()
var type: String = ""
var relatedId: String? = null
var lang: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import kotlinx.coroutines.launch
import org.json.JSONArray
import org.ole.planet.myplanet.BuildConfig
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.MainApplication.Companion.context
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.base.BaseContainerFragment
import org.ole.planet.myplanet.base.BaseResourceFragment
Expand Down Expand Up @@ -311,7 +312,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N

val hasUnfinishedSurvey = mRealm.where(RealmStepExam::class.java)
.equalTo("courseId", courseId)
.equalTo("type", "surveys")
.equalTo("type", "survey")
.findAll()
.any { survey -> !TakeCourseFragment.existsSubmission(mRealm, survey.id, "survey") }

Expand Down Expand Up @@ -468,6 +469,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N

val pendingSurveys = getPendingSurveys(user?.id)
val surveyTitles = getSurveyTitlesFromSubmissions(pendingSurveys)
Log.d("noti","Found survey tiles : $surveyTitles")
surveyTitles.forEach { title ->
createNotificationIfNotExists("survey", "${getString(R.string.pending_survey_notification)} $title", title)
}
Expand All @@ -477,8 +479,9 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
.equalTo("completed", false)
.equalTo("assignee", user?.id)
.findAll()

tasks.forEach { task ->
createNotificationIfNotExists("task", "${task.title} is due in ${formatDate(task.deadline)}", task.id)
createNotificationIfNotExists("task", context.getString(R.string.task_notification, task.title, formatDate(task.deadline)), task.id)
}

val storageRatio = totalAvailableMemoryRatio
Expand All @@ -487,7 +490,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
createNotificationIfNotExists("storage", "${getString(R.string.storage_critically_low)} $storageRatio% ${getString(R.string.available_please_free_up_space)}", "storage")
}
storageRatio <= 40 -> {
Log.d("lang", "lang is "+getString(R.string.storage_running_low))
Log.d("noti", "lang is "+getString(R.string.storage_running_low))
createNotificationIfNotExists("storage", "${getString(R.string.storage_running_low)} $storageRatio% ${getString(R.string.available)}", "storage")
}
}
Expand Down Expand Up @@ -532,17 +535,14 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
}

private fun createNotificationIfNotExists(type: String, message: String, relatedId: String?) {
val currentLanguage = LocaleHelper.getLanguage(this)

val existingNotification = mRealm.where(RealmNotification::class.java)
.equalTo("userId", user?.id)
.equalTo("type", type)
.equalTo("relatedId", relatedId)
.equalTo("lang", currentLanguage)
.findFirst()
if (existingNotification != null) {
Log.d(
"lang",
"noti",
"existing notification has ${existingNotification?.message} v/s ${message}"
)
}
Expand All @@ -555,7 +555,6 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
this.message = message
this.relatedId = relatedId
this.createdAt = Date()
this.lang= currentLanguage
}
}
}
Expand All @@ -571,8 +570,9 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
private fun getSurveyTitlesFromSubmissions(submissions: List<RealmSubmission>): List<String> {
val titles = mutableListOf<String>()
submissions.forEach { submission ->
val examId = submission.parentId?.split("@")?.firstOrNull() ?: ""
val exam = mRealm.where(RealmStepExam::class.java)
.equalTo("id", submission.parentId)
.equalTo("id", examId)
.findFirst()
exam?.name?.let { titles.add(it) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ole.planet.myplanet.ui.dashboard.notification

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -27,7 +28,14 @@ class AdapterNotification(var notificationList: List<RealmNotification>, private

inner class ViewHolderNotifications(private val rowNotificationsBinding: RowNotificationsBinding) : RecyclerView.ViewHolder(rowNotificationsBinding.root) {
fun bind(notification: RealmNotification, position: Int) {
Log.d("noti","current notification ${notification.type}")
rowNotificationsBinding.title.text = notification.message
/*
* changes here gett the storage stuff and paste it herer
* types of notification types- resource, storage, survey, sync
*
*
* */
if (notification.isRead) {
rowNotificationsBinding.btnMarkAsRead.visibility = View.GONE
rowNotificationsBinding.root.alpha = 0.5f
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">\nملاحظة: قد تحتاج لاستكمال تنزيل الموارد المضافة حديثًا.</string>
<string name="self_examination">%s\nالفحص الذاتي</string>
<string name="pending_survey_notification">لديك استطلاع قيد الانتظار:</string>
<string name="task_notification">%1$s مستحق في %2$s</string>
<string name="vitals_format">
درجة الحرارة: %1$s\n
النبض: %2$s\n
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">\nNota: Es posible que aún necesites descargar los recursos recién agregados.</string>
<string name="self_examination">%s\nAutoexamen</string>
<string name="pending_survey_notification">tienes una encuesta pendiente:</string>
<string name="task_notification">%1$s vence el %2$s</string>
<string name="vitals_format">
Temperatura: %1$s\n
Pulso: %2$s\n
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">Note: Vous devrez peut-être toujours télécharger les nouvelles ressources ajoutées.</string>
<string name="self_examination">%s\nAuto-examen</string>
<string name="pending_survey_notification">vous avez une enquête en attente :</string>
<string name="task_notification">%1$s est dû le %2$s</string>
<string name="vitals_format">
Température : %1$s\n
Pouls : %2$s\n
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">\nनोट: तपाईंले अहिले थपिएका स्रोतहरू डाउनलोड गर्न अझै सक्छ।</string>
<string name="self_examination">%s\nस्व-परिक्षण</string>
<string name="pending_survey_notification">तपाईंको एउटा पेंडिङ सर्वेक्षण छ:</string>
<string name="task_notification">%1$s %2$s मा समाप्त हुन्छ</string>
<string name="vitals_format">
तापमान: %1$s\n
नाडी: %2$s\n
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">\nNote: Amaan waxaad u baahan tahay inaad ku diyaariyey khadkaan cusub ee la soo kiciyey.</string>
<string name="self_examination">%s\nIs-imtixaanid</string>
<string name="pending_survey_notification">waxaad leedahay su\'aal weydiin sugaya:</string>
<string name="task_notification">%1$s waa inuu dhamaadaa %2$s</string>
<string name="vitals_format">
Heerkulka: %1$s\n
Garaaca wadnaha: %2$s\n
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 @@ -733,6 +733,7 @@
<string name="note_you_may_still_need_to_download_the_newly_added_resources">\nNote: You may still need to download the newly added resources.</string>
<string name="self_examination">%s\nSelf Examination</string>
<string name="pending_survey_notification">you have a pending survey:</string>
<string name="task_notification">%1$s is due in %2$s</string>
<string name="vitals_format">
Temperature: %1$s\n
Pulse: %2$s\n
Expand Down

0 comments on commit 517f899

Please sign in to comment.