Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboard: smoother translated notifications (fixes #4853) #4890

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.MenuItemCompat
Expand All @@ -42,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 @@ -309,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 @@ -466,17 +469,19 @@ 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", "you have a pending survey: $title", title)
createNotificationIfNotExists("survey", "${getString(R.string.pending_survey_notification)} $title", title)
}

val tasks = mRealm.where(RealmTeamTask::class.java)
.notEqualTo("status", "archived")
.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 @@ -485,6 +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("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 @@ -534,6 +540,13 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
.equalTo("type", type)
.equalTo("relatedId", relatedId)
.findFirst()
if (existingNotification != null) {
Log.d(
"noti",
"existing notification has ${existingNotification?.message} v/s ${message}"
)
}


if (existingNotification == null) {
mRealm.createObject(RealmNotification::class.java, "${UUID.randomUUID()}").apply {
Expand All @@ -557,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
Expand Up @@ -10,13 +10,15 @@ import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.MenuItemCompat
Expand Down Expand Up @@ -235,7 +237,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
Handler(Looper.getMainLooper()).postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
} else {
// val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
// if (fragment is BaseContainerFragment) {
// if (fragment is BaseContainerFragment) {
// fragment.handleBackPressed()
// }
finish()
Expand Down Expand Up @@ -485,6 +487,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))
createNotificationIfNotExists("storage", "${getString(R.string.storage_running_low)} $storageRatio% ${getString(R.string.available)}", "storage")
}
}
Expand Down Expand Up @@ -529,11 +532,21 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
}

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

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",
"existing notification has ${existingNotification?.message} v/s ${message}"
)
}


if (existingNotification == null) {
mRealm.createObject(RealmNotification::class.java, "${UUID.randomUUID()}").apply {
Expand All @@ -542,6 +555,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
this.message = message
this.relatedId = relatedId
this.createdAt = Date()
this.lang= currentLanguage
}
}
}
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
2 changes: 2 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">\n\nعودة إلى علامة التبويب الرئيسية للوصول إلى "مكتبتي".\n</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">\n\nRegresa a la pestaña de Inicio para acceder a miBiblioteca.\n</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">Retournez à l\'onglet Accueil pour accéder à votre bibliothèque.</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">\n\nमेरो पुस्तकालयमा पहुँचका लागि होम ट्याबमा फर्कनुहोस्।\n</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">\n\nKu noqo tabka Home si aad uga heli karto maktabaddaaga.\n</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@
<string name="return_to_the_home_tab_to_access_mylibrary">\n\nReturn to the Home tab to access myLibrary.\n</string>
<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
Loading