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

Commit

Permalink
feat: management to add eudcc in home
Browse files Browse the repository at this point in the history
  • Loading branch information
andcomito committed Mar 8, 2022
1 parent fc81149 commit 7c1f7b3
Show file tree
Hide file tree
Showing 51 changed files with 1,596 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ data class ConfigurationSettings(
@field:Json(name = "dummy_analytics_waiting_time") val dummyAnalyticsWaitingTime: Int,
@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 = "risk_exposure") val risk_exposure: Map<String, String>,
@field:Json(name = "eudcc_validity") val days_expiration_dgc: Map<String, Int?>
)

@JsonClass(generateAdapter = true)
Expand Down Expand Up @@ -244,6 +245,19 @@ fun risk_exposure(): Map<String, String> {
)
}

fun daysExpirationDgc(): Map<String, Int?> {
return mapOf(
"cbis" to 540,
"molecular_test" to 3,
"rapid_test" to 2,
"vaccine_first_dose" to 43,
"vaccine_fully_completed" to 180,
"vaccine_booster" to 540,
"healing_certificate" to 180,
"exemption" to null
)
}

val defaultSettings = ConfigurationSettings(
minimumBuildVersion = 0,
faqUrls = languageMap { "https://get.immuni.gov.it/docs/faq-${it.code}.json" },
Expand Down Expand Up @@ -281,5 +295,6 @@ val defaultSettings = ConfigurationSettings(
dummyAnalyticsWaitingTime = 2_592_000,
countries = countriesMap(),
eudcc_expiration = eudccMap(),
risk_exposure = risk_exposure()
risk_exposure = risk_exposure(),
days_expiration_dgc = daysExpirationDgc()
)
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ val appModule = module {
androidContext(),
get(),
get(),
get(),
get()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,11 @@ class UserManager(
fun setShowModalDGC(show: Boolean) {
userRepository.setShowModalDGC(show)
}

val showDGCHome = userRepository.showDGCHome

fun setShowDGCHome(show: Boolean) {
userRepository.setShowDGCHome(show)
}
// END DGC
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import kotlinx.android.parcel.Parcelize
data class GreenCertificateUser(
@field:Json(name = "base64") val base64: String,
@field:Json(name = "greenCertificate") val data: GreenCertificate?,
@field:Json(name = "fglTipoDgc") val fglTipoDgc: String? = null
@field:Json(name = "fglTipoDgc") val fglTipoDgc: String? = null,
@field:Json(name = "addedHomeDgc") var addedHomeDgc: Boolean = false
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class UserRepository(
private val welcomeCompleteKey = KVStorage.Key<Boolean>("WelcomeComplete")
private val onboardingCompleteKey = KVStorage.Key<Boolean>("OnboardingComplete")
private val showModalDGCKey = KVStorage.Key<Boolean>("showModalDGC")
private val showDGCHomeKey = KVStorage.Key<Boolean>("showDGCHome")
}

val user = storage.stateFlow(userKey)
Expand Down Expand Up @@ -58,4 +59,10 @@ class UserRepository(
fun setShowModalDGC(show: Boolean) {
storage[showModalDGCKey] = show
}

val showDGCHome = storage.stateFlow(showDGCHomeKey)

fun setShowDGCHome(show: Boolean) {
storage[showDGCHomeKey] = show
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* Copyright (C) 2020 Presidenza del Consiglio dei Ministri.
* Please refer to the AUTHORS file for more information.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
import it.ministerodellasalute.immuni.R
import it.ministerodellasalute.immuni.extensions.utils.*
import it.ministerodellasalute.immuni.extensions.view.setSafeOnClickListener
import it.ministerodellasalute.immuni.logic.settings.ConfigurationSettingsManager
import it.ministerodellasalute.immuni.logic.user.models.GreenCertificateUser
import java.text.SimpleDateFormat
import java.util.*

class CertificateDGCAdapter(
val context: Context,
val settingsManager: ConfigurationSettingsManager,
private val clickListener: CertificateDGCClickListener
) :
RecyclerView.Adapter<CertificateDGCAdapter.GreenPassVH>() {

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)

var data: List<GreenCertificateUser> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}

private fun onItemClick(pos: Int) {
if (pos != RecyclerView.NO_POSITION) {
val uid = when (true) {
data[pos].data?.recoveryStatements != null -> {
data[pos].data?.recoveryStatements?.get(0)?.certificateIdentifier
}
data[pos].data?.tests != null -> {
data[pos].data?.tests?.get(0)?.certificateIdentifier
}
data[pos].data?.vaccinations != null -> {
data[pos].data?.vaccinations?.get(0)?.certificateIdentifier
}
data[pos].data?.exemptions != null -> {
data[pos].data?.exemptions?.get(0)?.certificateIdentifier
}
else -> null
}


clickListener.onClick(uid!!)
}
}

inner class GreenPassVH(v: View) : RecyclerView.ViewHolder(v) {
val dateEvent: TextView = v.findViewById(R.id.dateEvent)
val nameForename: TextView = v.findViewById(R.id.nameForename)
val eventType: TextView = v.findViewById(R.id.eventType)
val validityDGC: MaterialCardView = v.findViewById(R.id.validityDGC)
val addedInHome: ImageView = v.findViewById(R.id.addedInHome)

init {
v.setSafeOnClickListener { onItemClick(adapterPosition) }
}
}

override fun getItemCount(): Int = data.size

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): CertificateDGCAdapter.GreenPassVH {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.certificate_dgc_item, parent, false)
return GreenPassVH(v)
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: GreenPassVH, position: Int) {
val greenCertificate = data[position]
val daysExpiredDgcMap = settingsManager.settings.value.days_expiration_dgc
holder.nameForename.text =
"${greenCertificate.data?.person?.givenName} ${greenCertificate.data?.person?.familyName}"
holder.addedInHome.visibility = if (greenCertificate.addedHomeDgc) {
View.VISIBLE
} else {
View.GONE
}
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
)
}

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
)
} 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
)
}
}
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
)
} else {
dateExpired(
greenCertificate.data.vaccinations?.get(0)?.dateOfVaccination!!,
dateFormat,
daysExpiredDgcMap["vaccine_booster"]!!,
holder
)
}
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))
} else {
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 {
fun onClick(uid: String)
}
Loading

0 comments on commit 7c1f7b3

Please sign in to comment.