diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt index 80d1e3d79d..4dc548acfe 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt @@ -161,8 +161,8 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N createDrawer() if (!(user?.id?.startsWith("guest") == true && profileDbHandler.offlineVisits >= 3) && resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { result?.openDrawer() - } //Opens drawer by default - result?.stickyFooter?.setPadding(0, 0, 0, 0) // moves logout button to the very bottom of the drawer. Without it, the "logout" button suspends a little. + } + result?.stickyFooter?.setPadding(0, 0, 0, 0) result?.actionBarDrawerToggle?.isDrawerIndicatorEnabled = true dl = result?.drawerLayout topbarSetting() @@ -309,7 +309,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") } @@ -467,7 +467,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N val pendingSurveys = getPendingSurveys(user?.id) val surveyTitles = getSurveyTitlesFromSubmissions(pendingSurveys) surveyTitles.forEach { title -> - createNotificationIfNotExists("survey", "you have a pending survey: $title", title) + createNotificationIfNotExists("survey", "$title", title) } val tasks = mRealm.where(RealmTeamTask::class.java) @@ -476,18 +476,11 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N .equalTo("assignee", user?.id) .findAll() tasks.forEach { task -> - createNotificationIfNotExists("task", "${task.title} is due in ${formatDate(task.deadline)}", task.id) + createNotificationIfNotExists("task","${task.title} ${formatDate(task.deadline)}", task.id) } val storageRatio = totalAvailableMemoryRatio - when { - storageRatio <= 10 -> { - createNotificationIfNotExists("storage", "${getString(R.string.storage_critically_low)} $storageRatio% ${getString(R.string.available_please_free_up_space)}", "storage") - } - storageRatio <= 40 -> { - createNotificationIfNotExists("storage", "${getString(R.string.storage_running_low)} $storageRatio% ${getString(R.string.available)}", "storage") - } - } + createNotificationIfNotExists("storage", "$storageRatio" , "storage") } private fun updateResourceNotification() { @@ -499,10 +492,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N .findFirst() if (existingNotification != null) { - existingNotification.message = "you have $resourceCount resources not downloaded" + existingNotification.message = "$resourceCount" existingNotification.relatedId = "$resourceCount" } else { - createNotificationIfNotExists("resource", "you have $resourceCount resources not downloaded", "$resourceCount") + createNotificationIfNotExists("resource", "$resourceCount", "$resourceCount") } } else { mRealm.where(RealmNotification::class.java) @@ -557,8 +550,9 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N private fun getSurveyTitlesFromSubmissions(submissions: List): List { val titles = mutableListOf() 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) } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite index ff850517f4..472c1b074e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite @@ -161,8 +161,8 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N createDrawer() if (!(user?.id?.startsWith("guest") == true && profileDbHandler.offlineVisits >= 3) && resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { result?.openDrawer() - } //Opens drawer by default - result?.stickyFooter?.setPadding(0, 0, 0, 0) // moves logout button to the very bottom of the drawer. Without it, the "logout" button suspends a little. + } + result?.stickyFooter?.setPadding(0, 0, 0, 0) result?.actionBarDrawerToggle?.isDrawerIndicatorEnabled = true dl = result?.drawerLayout topbarSetting() @@ -309,7 +309,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") } @@ -467,7 +467,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N val pendingSurveys = getPendingSurveys(user?.id) val surveyTitles = getSurveyTitlesFromSubmissions(pendingSurveys) surveyTitles.forEach { title -> - createNotificationIfNotExists("survey", "you have a pending survey: $title", title) + createNotificationIfNotExists("survey", "$title", title) } val tasks = mRealm.where(RealmTeamTask::class.java) @@ -476,18 +476,11 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N .equalTo("assignee", user?.id) .findAll() tasks.forEach { task -> - createNotificationIfNotExists("task", "${task.title} is due in ${formatDate(task.deadline)}", task.id) + createNotificationIfNotExists("task","${task.title} ${formatDate(task.deadline)}", task.id) } val storageRatio = totalAvailableMemoryRatio - when { - storageRatio <= 10 -> { - createNotificationIfNotExists("storage", "${getString(R.string.storage_critically_low)} $storageRatio% ${getString(R.string.available_please_free_up_space)}", "storage") - } - storageRatio <= 40 -> { - createNotificationIfNotExists("storage", "${getString(R.string.storage_running_low)} $storageRatio% ${getString(R.string.available)}", "storage") - } - } + createNotificationIfNotExists("storage", "$storageRatio" , "storage") } private fun updateResourceNotification() { @@ -499,10 +492,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N .findFirst() if (existingNotification != null) { - existingNotification.message = "you have $resourceCount resources not downloaded" + existingNotification.message = "$resourceCount" existingNotification.relatedId = "$resourceCount" } else { - createNotificationIfNotExists("resource", "you have $resourceCount resources not downloaded", "$resourceCount") + createNotificationIfNotExists("resource", "$resourceCount", "$resourceCount") } } else { mRealm.where(RealmNotification::class.java) @@ -557,8 +550,9 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N private fun getSurveyTitlesFromSubmissions(submissions: List): List { val titles = mutableListOf() 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) } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/notification/AdapterNotification.kt b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/notification/AdapterNotification.kt index 6c0388304a..9421f38dfb 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/notification/AdapterNotification.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/notification/AdapterNotification.kt @@ -1,13 +1,20 @@ package org.ole.planet.myplanet.ui.dashboard.notification +import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import org.ole.planet.myplanet.R import org.ole.planet.myplanet.databinding.RowNotificationsBinding import org.ole.planet.myplanet.model.RealmNotification -class AdapterNotification(var notificationList: List, private val onMarkAsReadClick: (Int) -> Unit, private val onNotificationClick: (RealmNotification) -> Unit) : RecyclerView.Adapter() { +class AdapterNotification( + var notificationList: List, + private val onMarkAsReadClick: (Int) -> Unit, + private val onNotificationClick: (RealmNotification) -> Unit +) : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderNotifications { val rowNotificationsBinding = RowNotificationsBinding.inflate(LayoutInflater.from(parent.context), parent, false) return ViewHolderNotifications(rowNotificationsBinding) @@ -25,9 +32,14 @@ class AdapterNotification(var notificationList: List, private notifyDataSetChanged() } - inner class ViewHolderNotifications(private val rowNotificationsBinding: RowNotificationsBinding) : RecyclerView.ViewHolder(rowNotificationsBinding.root) { + inner class ViewHolderNotifications(private val rowNotificationsBinding: RowNotificationsBinding) : + RecyclerView.ViewHolder(rowNotificationsBinding.root) { + fun bind(notification: RealmNotification, position: Int) { - rowNotificationsBinding.title.text = notification.message + val context = rowNotificationsBinding.root.context + val currentNotification = formatNotificationMessage(notification, context) + rowNotificationsBinding.title.text = currentNotification + if (notification.isRead) { rowNotificationsBinding.btnMarkAsRead.visibility = View.GONE rowNotificationsBinding.root.alpha = 0.5f @@ -43,5 +55,38 @@ class AdapterNotification(var notificationList: List, private onNotificationClick(notification) } } + + private fun formatNotificationMessage(notification: RealmNotification, context: Context): String { + return when (notification.type.lowercase()) { + "survey" -> context.getString(R.string.pending_survey_notification) + " ${notification.message}" + "task" -> { + val parts = notification.message.split(" ") + if (parts.size >= 2) { + val taskTitle = parts[0] + val dateValue = parts.subList(1, parts.size).joinToString(" ") + context.getString(R.string.task_notification, taskTitle, dateValue) + } else { + "INVALID" + } + } + "resource" -> { + val resourceCount = notification.message.toIntOrNull() + resourceCount?.let { + context.getString(R.string.resource_notification, it) + } ?: "INVALID" + } + "storage" -> { + val storageValue = notification.message.toIntOrNull() + storageValue?.let { + when { + it <= 10 -> context.getString(R.string.storage_running_low) +" ${it}%" + it <= 40 -> context.getString(R.string.storage_running_low)+ " ${it}%" + else -> "INVALID" + } + } ?: "INVALID" + } + else -> "INVALID" + } + } } } diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 405073d31a..0dbeba7657 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -733,6 +733,9 @@ \n\nعودة إلى علامة التبويب الرئيسية للوصول إلى "مكتبتي".\n \nملاحظة: قد تحتاج لاستكمال تنزيل الموارد المضافة حديثًا. %s\nالفحص الذاتي + لديك استطلاع قيد الانتظار: + %1$s مستحق في %2$s + لديك %1$d موارد لم يتم تنزيلها درجة الحرارة: %1$s\n النبض: %2$s\n diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 23c877cb17..9e1c7988e4 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -733,6 +733,9 @@ \n\nRegresa a la pestaña de Inicio para acceder a miBiblioteca.\n \nNota: Es posible que aún necesites descargar los recursos recién agregados. %s\nAutoexamen + tienes una encuesta pendiente: + %1$s vence el %2$s + Tienes %1$d recursos no descargados Temperatura: %1$s\n Pulso: %2$s\n diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 045d857083..fb307dbc58 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -733,6 +733,9 @@ Retournez à l\'onglet Accueil pour accéder à votre bibliothèque. Note: Vous devrez peut-être toujours télécharger les nouvelles ressources ajoutées. %s\nAuto-examen + vous avez une enquête en attente : + %1$s est dû le %2$s + Vous avez %1$d ressources non téléchargées Température : %1$s\n Pouls : %2$s\n diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index d9920520c4..a0c1f9963d 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -733,6 +733,9 @@ \n\nमेरो पुस्तकालयमा पहुँचका लागि होम ट्याबमा फर्कनुहोस्।\n \nनोट: तपाईंले अहिले थपिएका स्रोतहरू डाउनलोड गर्न अझै सक्छ। %s\nस्व-परिक्षण + तपाईंको एउटा पेंडिङ सर्वेक्षण छ: + %1$s %2$s मा समाप्त हुन्छ + तपाईंसँग %1$d स्रोतहरू डाउनलोड गरिएको छैन तापमान: %1$s\n नाडी: %2$s\n diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 2f87ff661c..e9e33ea170 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -733,6 +733,9 @@ \n\nKu noqo tabka Home si aad uga heli karto maktabaddaaga.\n \nNote: Amaan waxaad u baahan tahay inaad ku diyaariyey khadkaan cusub ee la soo kiciyey. %s\nIs-imtixaanid + waxaad leedahay su\'aal weydiin sugaya: + %1$s waa inuu dhamaadaa %2$s + Waxaad haysataa %1$d agab aan la soo dejisan Heerkulka: %1$s\n Garaaca wadnaha: %2$s\n diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c23eed13c0..437a746fdb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -732,6 +732,9 @@ \n\nReturn to the Home tab to access myLibrary.\n \nNote: You may still need to download the newly added resources. %s\nSelf Examination + you have a pending survey: + %1$s is due in %2$s + You have %1$d resources not downloaded Temperature: %1$s\n Pulse: %2$s\n