Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat: add translation + management expired certificates in list
Browse files Browse the repository at this point in the history
  • Loading branch information
andcomito committed Mar 10, 2022
1 parent 7c1f7b3 commit 7dbde10
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class ConfigurationSettings(
@field:Json(name = "countries") val countries: Map<String, Map<String, String>>,
@field:Json(name = "eudcc_expiration") val eudcc_expiration: Map<String, Map<String, String>>,
@field:Json(name = "risk_exposure") val risk_exposure: Map<String, String>,
@field:Json(name = "eudcc_validity") val days_expiration_dgc: Map<String, Int?>
@field:Json(name = "eu_dcc_deadlines") val eu_dcc_deadlines: Map<String, Int?>
)

@JsonClass(generateAdapter = true)
Expand Down Expand Up @@ -248,13 +248,13 @@ fun risk_exposure(): Map<String, String> {
fun daysExpirationDgc(): Map<String, Int?> {
return mapOf(
"cbis" to 540,
"molecular_test" to 3,
"rapid_test" to 2,
"molecular_test" to 72,
"rapid_test" to 48,
"vaccine_first_dose" to 43,
"vaccine_fully_completed" to 180,
"vaccine_booster" to 540,
"healing_certificate" to 180,
"exemption" to null
"exemption" to 540
)
}

Expand Down Expand Up @@ -296,5 +296,5 @@ val defaultSettings = ConfigurationSettings(
countries = countriesMap(),
eudcc_expiration = eudccMap(),
risk_exposure = risk_exposure(),
days_expiration_dgc = daysExpirationDgc()
eu_dcc_deadlines = daysExpirationDgc()
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package it.ministerodellasalute.immuni.ui.certificate

import android.annotation.SuppressLint
import android.content.Context
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -42,7 +41,8 @@ class CertificateDGCAdapter(

private val molecolarTest = "LP6464-4"
private val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US)
private val dateTimeFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
private val dateTimeFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US)
private val dateFormatString = SimpleDateFormat("dd-MM-yyyy", Locale.US)

var data: List<GreenCertificateUser> = emptyList()
set(value) {
Expand All @@ -67,8 +67,6 @@ class CertificateDGCAdapter(
}
else -> null
}


clickListener.onClick(uid!!)
}
}
Expand Down Expand Up @@ -99,111 +97,143 @@ class CertificateDGCAdapter(
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: GreenPassVH, position: Int) {
val greenCertificate = data[position]
val daysExpiredDgcMap = settingsManager.settings.value.days_expiration_dgc
val daysExpiredDgcMap = settingsManager.settings.value.eu_dcc_deadlines
holder.nameForename.text =
"${greenCertificate.data?.person?.givenName} ${greenCertificate.data?.person?.familyName}"
"${greenCertificate.data?.person?.familyName} ${greenCertificate.data?.person?.givenName}"
holder.addedInHome.visibility = if (greenCertificate.addedHomeDgc) {
View.VISIBLE
} else {
View.GONE
}
val todayDateMill = Date().byAdding().time
when (true) {
greenCertificate.data?.recoveryStatements != null -> {
holder.dateEvent.text = when(greenCertificate.fglTipoDgc) {
"cbis" -> dateExpired(
greenCertificate.data?.recoveryStatements?.get(0)?.certificateValidFrom!!,
dateFormat,
daysExpiredDgcMap["cbis"]!!,
holder
)
else -> dateExpired(
greenCertificate.data?.recoveryStatements?.get(0)?.certificateValidFrom!!,
dateFormat,
daysExpiredDgcMap["healing_certificate"]!!,
holder
)
val validityDays = if (greenCertificate.fglTipoDgc == "cbis") {
daysExpiredDgcMap["cbis"]
} else {
daysExpiredDgcMap["healing_certificate"]
}

val maxDateValidity = if (validityDays != null) {
dateFormat.parse(greenCertificate.data?.recoveryStatements?.get(0)?.certificateValidFrom!!)!!
.byAdding(days = validityDays)
} else {
null
}
holder.dateEvent.text =
if (maxDateValidity !== null && maxDateValidity.time > todayDateMill) {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.colorPrimary, null)
context.getString(
R.string.green_certificate_list_dgc_valid,
dateFormatString.format(maxDateValidity)
)
} else {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.danger, null)
context.getString(R.string.green_certificate_list_dgc_expired)
}
holder.eventType.text = context.getString(R.string.green_certificate_card_recovery)
}
greenCertificate.data?.tests != null -> {
if (greenCertificate.data?.tests?.get(0)!!.typeOfTest == molecolarTest) {
holder.eventType.text =
context.getString(R.string.green_certificate_card_molecular_test)
holder.dateEvent.text = dateExpired(
greenCertificate.data.tests?.get(0)?.dateTimeOfTestResult!!,
dateTimeFormat,
daysExpiredDgcMap["molecular_test"]!!,
holder
)
val validityHours =
if (greenCertificate.data?.tests?.get(0)!!.typeOfTest == molecolarTest) {
holder.eventType.text =
context.getString(R.string.green_certificate_card_molecular_test)
daysExpiredDgcMap["molecular_test"]
} else {
holder.eventType.text =
context.getString(R.string.green_certificate_card_rapid_test)
daysExpiredDgcMap["rapid_test"]
}
val maxDateValidity = if (validityHours != null) {
dateTimeFormat.parse(greenCertificate.data.tests?.get(0)?.dateTimeOfCollection!!)!!
.byAdding(hours = validityHours)
} else {
holder.eventType.text =
context.getString(R.string.green_certificate_card_rapid_test)
holder.dateEvent.text = dateExpired(
greenCertificate.data.tests?.get(0)?.dateTimeOfTestResult!!,
dateTimeFormat,
daysExpiredDgcMap["rapid_test"]!!,
holder
)
null
}
holder.dateEvent.text =
if (maxDateValidity !== null && maxDateValidity.time > todayDateMill) {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.colorPrimary, null)
if (greenCertificate.data.tests?.get(0)!!.typeOfTest == molecolarTest) {
settingsManager.settings.value.eudcc_expiration[Locale.getDefault().language]!!["molecular_test"]
} else {
settingsManager.settings.value.eudcc_expiration[Locale.getDefault().language]!!["rapid_test"]
}
} else {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.danger, null)
context.getString(R.string.green_certificate_list_dgc_expired)
}
}
greenCertificate.data?.vaccinations != null -> {
holder.dateEvent.text = if (greenCertificate.data?.vaccinations?.get(0)!!.doseNumber < greenCertificate.data.vaccinations?.get(0)!!.totalSeriesOfDoses) {
dateExpired(
greenCertificate.data.vaccinations?.get(0)?.dateOfVaccination!!,
dateFormat,
daysExpiredDgcMap["vaccine_first_dose"]!!,
holder
)
} else if (greenCertificate.data.vaccinations?.get(0)!!.doseNumber == greenCertificate.data.vaccinations?.get(0)!!.totalSeriesOfDoses && greenCertificate.data.vaccinations?.get(0)!!.totalSeriesOfDoses < 3) {
dateExpired(
greenCertificate.data.vaccinations?.get(0)?.dateOfVaccination!!,
dateFormat,
daysExpiredDgcMap["vaccine_fully_completed"]!!,
holder
)
val validityDays =
if (greenCertificate.data?.vaccinations?.get(0)!!.doseNumber < greenCertificate.data.vaccinations?.get(
0
)!!.totalSeriesOfDoses
) {
daysExpiredDgcMap["vaccine_first_dose"]
} else if (greenCertificate.data.vaccinations?.get(0)!!.doseNumber == greenCertificate.data.vaccinations?.get(
0
)!!.totalSeriesOfDoses && greenCertificate.data.vaccinations?.get(0)!!.totalSeriesOfDoses < 3
) {
daysExpiredDgcMap["vaccine_fully_completed"]
} else {
daysExpiredDgcMap["vaccine_booster"]
}
val maxDateValidity = if (validityDays != null) {
dateFormat.parse(greenCertificate.data.vaccinations?.get(0)?.dateOfVaccination!!)!!
.byAdding(days = validityDays)
} else {
dateExpired(
greenCertificate.data.vaccinations?.get(0)?.dateOfVaccination!!,
dateFormat,
daysExpiredDgcMap["vaccine_booster"]!!,
holder
)
null
}
holder.dateEvent.text =
if (maxDateValidity !== null && maxDateValidity.time > todayDateMill) {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.colorPrimary, null)
context.getString(
R.string.green_certificate_list_dgc_valid,
dateFormatString.format(maxDateValidity)
)
} else {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.danger, null)
context.getString(R.string.green_certificate_list_dgc_expired)
}
holder.eventType.text = context.getString(
R.string.green_certificate_card_vaccination,
greenCertificate.data.vaccinations?.get(0)?.doseNumber,
greenCertificate.data.vaccinations?.get(0)?.totalSeriesOfDoses
)
}
greenCertificate.data?.exemptions != null -> {
holder.dateEvent.text = if (greenCertificate.data?.exemptions!![0].certificateValidUntil != null) {
val todayDateMill = Date().byAdding().time
val maxDateValidity = dateFormat.parse(greenCertificate.data.exemptions!![0].certificateValidUntil!!)!!
if (maxDateValidity.time > todayDateMill) {
context.getString(R.string.green_certificate_list_dgc_valid, DateFormat.getDateFormat(context).format(greenCertificate.data.exemptions!![0].certificateValidUntil))
val maxDateValidity =
if (!greenCertificate.data?.exemptions!![0].certificateValidUntil.isNullOrBlank()) {
dateFormat.parse(greenCertificate.data.exemptions?.get(0)?.certificateValidUntil!!)!!
} else if (daysExpiredDgcMap["exemption"] != null) {
dateFormat.parse(greenCertificate.data.exemptions?.get(0)?.certificateValidFrom!!)!!
.byAdding(days = daysExpiredDgcMap["exemption"]!!)
} else {
null
}

holder.dateEvent.text =
if (maxDateValidity != null && maxDateValidity.time > todayDateMill) {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.colorPrimary, null)
context.getString(
R.string.green_certificate_list_dgc_valid,
dateFormatString.format(maxDateValidity)
)
} else {
holder.validityDGC.backgroundTintList =
context.resources.getColorStateList(R.color.danger, null)
context.getString(R.string.green_certificate_list_dgc_expired)
}
} else {
context.getString(R.string.green_certificate_list_dgc_expired)
}
holder.eventType.text = context.getString(R.string.green_certificate_card_exemption)
}
}
}

private fun dateExpired(dateFrom: String,simpleDateFormat: SimpleDateFormat, daysValidity: Int, holder: GreenPassVH): String {
val todayDateMill = Date().byAdding().time
val maxDateValidity = simpleDateFormat.parse(dateFrom)!!.byAdding(days = daysValidity)
return if (maxDateValidity.time > todayDateMill) {
holder.validityDGC.backgroundTintList = context.resources.getColorStateList(R.color.colorPrimary, null)
context.getString(R.string.green_certificate_list_dgc_valid, DateFormat.getDateFormat(context).format(maxDateValidity))
} else {
holder.validityDGC.backgroundTintList = context.resources.getColorStateList(R.color.danger, null)
context.getString(R.string.green_certificate_list_dgc_expired)
}
}
}

interface CertificateDGCClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import it.ministerodellasalute.immuni.extensions.view.setSafeOnClickListener
import it.ministerodellasalute.immuni.logic.settings.ConfigurationSettingsManager
import it.ministerodellasalute.immuni.logic.user.UserManager
import it.ministerodellasalute.immuni.logic.user.models.GreenCertificateUser
import kotlin.math.abs
import kotlinx.android.synthetic.main.certificate_dgc.*
import org.koin.android.ext.android.get
import kotlin.math.abs

class CertificateDGCFragment : Fragment(R.layout.certificate_dgc), CertificateDGCClickListener {

Expand Down Expand Up @@ -104,5 +104,4 @@ class CertificateDGCFragment : Fragment(R.layout.certificate_dgc), CertificateDG
// important keep here, after navigating
findNavController().popBackStack()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.View
import it.ministerodellasalute.immuni.R
import it.ministerodellasalute.immuni.ui.dialog.PopupDialogFragment

class CertificateDGCKnowMore: PopupDialogFragment() {
class CertificateDGCKnowMore : PopupDialogFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ConfirmationDialogFragment : DialogFragment() {
targetRequestCode
)
}

}
.setNegativeButton(args.getString(ARG_NEGATIVE_BUTTON)) { _, _ ->
listener.onDialogNegative(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import it.ministerodellasalute.immuni.logic.user.models.User
import it.ministerodellasalute.immuni.ui.dialog.ConfirmationDialogListener
import it.ministerodellasalute.immuni.ui.dialog.openConfirmationDialog
import it.ministerodellasalute.immuni.util.ImageUtils
import kotlin.math.abs
import kotlinx.android.synthetic.main.green_certificate.*
import kotlinx.android.synthetic.main.green_certificate_tab.*
import org.koin.android.ext.android.get
import org.koin.androidx.viewmodel.ext.android.getViewModel
import kotlin.math.abs

class GreenCertificateFragment : Fragment(R.layout.green_certificate), ConfirmationDialogListener {

Expand Down Expand Up @@ -146,7 +146,6 @@ class GreenCertificateFragment : Fragment(R.layout.green_certificate), Confirmat
}
}


TabLayoutMediator(tabLayoutDot, viewpager) { tab, position ->
// Some implementation
}.attach()
Expand Down Expand Up @@ -305,7 +304,7 @@ class GreenCertificateFragment : Fragment(R.layout.green_certificate), Confirmat
if (uid.isNullOrBlank()) {
return 0
}
var i = 0;
var i = 0
var indexSelected = 0
loop@ for (greenPass in userManager.user.value?.greenPass!!.asReversed()) {
when (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,5 @@ class HomeFragment : Fragment(),
}

private fun openCertificate() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class HomeListAdapter(
is CertificateVH -> {
val listGreenCertificateHome = getCertificateHome()
if (listGreenCertificateHome.isNotEmpty()) {
holder.person.text = "${listGreenCertificateHome[0].data?.person?.givenName} ${listGreenCertificateHome[0].data?.person?.familyName}"
holder.person.text = "${listGreenCertificateHome[0].data?.person?.familyName} ${listGreenCertificateHome[0].data?.person?.givenName}"
holder.qrCodeHome.setImageBitmap(ImageUtils.convert(listGreenCertificateHome[0].base64))
}
}
Expand All @@ -242,7 +242,7 @@ class HomeListAdapter(
override fun getItemCount(): Int = items.size

private fun getCertificateHome(): List<GreenCertificateUser> {
return userManager.user.value?.greenPass!!.filter { greenCertificateUser -> greenCertificateUser.addedHomeDgc}
return userManager.user.value?.greenPass!!.filter { greenCertificateUser -> greenCertificateUser.addedHomeDgc }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package it.ministerodellasalute.immuni.ui.main

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
Expand All @@ -26,7 +25,6 @@ import it.ministerodellasalute.immuni.extensions.lifecycle.AppLifecycleObserver
import it.ministerodellasalute.immuni.extensions.notifications.PushNotificationManager
import it.ministerodellasalute.immuni.logic.exposure.ExposureManager
import it.ministerodellasalute.immuni.logic.user.UserManager
import it.ministerodellasalute.immuni.logic.user.models.GreenCertificateUser
import it.ministerodellasalute.immuni.ui.home.*
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ class ExposureNotificationFragment :
}

private fun canProceed(): Boolean {
return true //viewModel.isBroadcastingActive.value ?: false
return viewModel.isBroadcastingActive.value ?: false
}
}
Loading

0 comments on commit 7dbde10

Please sign in to comment.