Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
refactor: Move course date types to strings.xml
Browse files Browse the repository at this point in the history
Course date types were previously in a code file which didn't allow us
to get these strings translated. This commits fixes the issue by moving
the strings to strings.xml file and changing the code accordingly.
  • Loading branch information
miankhalid committed Sep 10, 2021
1 parent 840ae14 commit b8ff48e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
18 changes: 16 additions & 2 deletions OpenEdXMobile/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,22 @@ lo que significa que no puedes participar en tareas calificadas. Parece que no c
<!--Message Course Dates Banner Reset Date-->
<string name="course_dates_banner_reset_date">Parece que no has cumplido con algunos plazos importantes según nuestro calendario sugerido.
Para mantenerte en el camino adecuado, puedes actualizar este calendario y mover las tareas vencidas hacia el futuro. No te preocupes, no perderás nada de lo que hayas avanzado cuando cambies las fechas de entrega.</string>
<!--Label Course Card Graded Message-->
<string name="value_prop_course_card_message">Desbloquealo para acceder a más funciones</string>

<!-- region: Course Date types -->
<!-- Label used when the date is Today -->
<string name="date_type_today">Hoy</string>
<!-- Label used when an assignment is for verified user only -->
<string name="date_type_verified_only">Solamente Verificado</string>
<!-- Label used when an assignment is completed -->
<string name="date_type_completed">Completado</string>
<!-- Label used when an assignment is past due -->
<string name="date_type_past_due">Vencido</string>
<!-- Label used when an assignment is due next -->
<string name="date_type_due_next">Debido a continuacion</string>
<!-- Label used when an assignment is not yet released -->
<string name="date_type_not_yet_released">Todavía no se ha publicado</string>
<!-- endregion -->

<!--Title Sync to calendar-->
<string name="sync_to_calendar">Sincronización con el calendario</string>
<!--Title Sync to calendar-->
Expand Down
15 changes: 15 additions & 0 deletions OpenEdXMobile/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@
<string name="course_dates_banner_reset_date">It looks like you missed some important deadlines based on our suggested schedule.
To keep yourself on track, you can update this schedule and shift the past due assignments into the future. Don’t worry—you won’t lose any of the progress you’ve made when you shift your due dates.</string>

<!-- region: Course Date types -->
<!-- Label used when the date is Today -->
<string name="date_type_today">Today</string>
<!-- Label used when an assignment is for verified user only -->
<string name="date_type_verified_only">Verified Only</string>
<!-- Label used when an assignment is completed -->
<string name="date_type_completed">Completed</string>
<!-- Label used when an assignment is past due -->
<string name="date_type_past_due">Past Due</string>
<!-- Label used when an assignment is due next -->
<string name="date_type_due_next">Due Next</string>
<!-- Label used when an assignment is not yet released -->
<string name="date_type_not_yet_released">Not Yet Released</string>
<!-- endregion -->

<!-- Title Sync to calendar -->
<string name="sync_to_calendar">Sync to calendar</string>
<!-- Title Sync to calendar -->
Expand Down
21 changes: 13 additions & 8 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateType.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package org.edx.mobile.util

import org.edx.mobile.R

/**
* This enum defines the Date type of Course Dates
*/
enum class CourseDateType {
TODAY, BLANK, VERIFIED_ONLY, COMPLETED, PAST_DUE, DUE_NEXT, NOT_YET_RELEASED,
COURSE_EXPIRED_DATE;

fun getTitle(): String {
/**
* @return The string resource's ID if it's a valid enum inside [CourseDateType], otherwise -1.
*/
fun getStringResIdForDateType(): Int {
return when (this) {
TODAY -> "Today"
VERIFIED_ONLY -> "Verified Only"
COMPLETED -> "Completed"
PAST_DUE -> "Past Due"
DUE_NEXT -> "Due Next"
NOT_YET_RELEASED -> "Not Yet Released"
else -> ""
TODAY -> R.string.date_type_today
VERIFIED_ONLY -> R.string.date_type_verified_only
COMPLETED -> R.string.date_type_completed
PAST_DUE -> R.string.date_type_past_due
DUE_NEXT -> R.string.date_type_due_next
NOT_YET_RELEASED -> R.string.date_type_not_yet_released
else -> -1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class DataBindingHelperUtils {
return
}
}
addDateBadge(textView, courseDateType.getTitle(), badgeBackground, textAppearance, badgeIcon, badgeStrokeColor)
addDateBadge(textView, courseDateType.getStringResIdForDateType(), badgeBackground, textAppearance, badgeIcon, badgeStrokeColor)
}

/**
Expand All @@ -202,8 +202,12 @@ class DataBindingHelperUtils {
/**
* Method to add the date badge at the end in given title with styles attributes
*/
private fun addDateBadge(textView: TextView, title: String, badgeBackground: Int, textAppearance: Int,
private fun addDateBadge(textView: TextView, titleRes: Int, badgeBackground: Int, textAppearance: Int,
badgeIcon: Drawable?, badgeStrokeColor: Int) {
val title = when (titleRes) {
-1 -> ""
else -> textView.resources.getString(titleRes)
}
// add badge title so can identify the actual badge position
val titleWithBadge = SpannableStringBuilder((textView.text as Spannable))
// add space before badge title
Expand Down

0 comments on commit b8ff48e

Please sign in to comment.