Skip to content

Commit

Permalink
- add content table on detailed result view; (eu-digital-green-certif…
Browse files Browse the repository at this point in the history
…icates#228)

- update resources;
  • Loading branch information
MykhailoNester authored Oct 1, 2021
1 parent ea25dd1 commit ec83d6d
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package dgca.verifier.app.android.model
import android.os.Parcelable
import kotlinx.parcelize.Parcelize


@Parcelize
data class CertificateModel(
val person: PersonModel,
Expand Down Expand Up @@ -65,7 +64,7 @@ data class PersonModel(
val familyName: String?,
val standardisedGivenName: String?,
val givenName: String?
): Parcelable
) : Parcelable

@Parcelize
data class VaccinationModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-verifier-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by mykhailo.nester on 30/09/2021, 20:04
*/

package dgca.verifier.app.android.verification.detailed

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import dgca.verifier.app.android.databinding.ItemCertificateContentBinding


class CertificateContentAdapter(private val inflater: LayoutInflater) :
RecyclerView.Adapter<CertificateContentAdapter.ViewHolder>() {

private var list = listOf<Pair<String, String>>()

inner class ViewHolder(val binding: ItemCertificateContentBinding) : RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(ItemCertificateContentBinding.inflate(inflater, parent, false))

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val data = list[position]
holder.binding.field.text = data.first
holder.binding.value.text = data.second
}

override fun getItemCount(): Int = list.size

@SuppressLint("NotifyDataSetChanged")
fun updateData(newMap: MutableMap<String, String>) {
list = newMap.toList()
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-verifier-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by mykhailo.nester on 30/09/2021, 20:04
*/

package dgca.verifier.app.android.verification.detailed

import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.card.MaterialCardView
import dgca.verifier.app.android.R
import dgca.verifier.app.android.databinding.ViewCertificateContentViewBinding
import dgca.verifier.app.android.model.CertificateModel

class CertificateContentView(context: Context, attrs: AttributeSet?) :
MaterialCardView(context, attrs) {

private val binding: ViewCertificateContentViewBinding =
ViewCertificateContentViewBinding.inflate(LayoutInflater.from(context), this)

private var isExpanded = false

init {
radius = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
context.resources.getDimension(R.dimen.detailed_verification_result_banner_radius),
context.resources.displayMetrics
)
strokeWidth = resources.getDimensionPixelSize(R.dimen.default_stroke_width)
setStrokeColor(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.black)))

binding.expandButton.setOnClickListener {
setExpanded(!isExpanded)
}

}

fun setCertificateModel(certificateModel: CertificateModel, certAdapter: CertificateContentAdapter) {
binding.contentRecyclerView.apply {
layoutManager = LinearLayoutManager(context)
adapter = certAdapter
}

val data = mutableMapOf(
context.getString(R.string.personal_data_title) to "",
context.getString(R.string.standardised_family_name_title) to certificateModel.person.standardisedFamilyName,
context.getString(R.string.family_name_title) to certificateModel.person.familyName.orEmpty(),
context.getString(R.string.standardised_given_name_title) to certificateModel.person.standardisedGivenName.orEmpty(),
context.getString(R.string.given_name_title) to certificateModel.person.givenName.orEmpty(),
context.getString(R.string.date_of_birth_title) to certificateModel.dateOfBirth,
)
certificateModel.vaccinations?.let {
if (it.isNotEmpty()) {
val item = it.first()
data[context.getString(R.string.vaccination_title)] = ""
data[context.getString(R.string.target_disease)] = item.disease.value
data[context.getString(R.string.vaccine_title)] = item.vaccine
data[context.getString(R.string.medical_product_title)] = item.medicinalProduct
data[context.getString(R.string.manufacturer_title)] = item.manufacturer
data[context.getString(R.string.dose_number_title)] = item.doseNumber.toString()
data[context.getString(R.string.total_doses_title)] = item.totalSeriesOfDoses.toString()
data[context.getString(R.string.date_of_vaccination_title)] = item.dateOfVaccination
data[context.getString(R.string.country_of_vaccination_title)] = item.countryOfVaccination
data[context.getString(R.string.certificate_issuer_title)] = item.certificateIssuer
data[context.getString(R.string.certificate_identifier_title)] = item.certificateIdentifier
}
}
certificateModel.tests?.let {
if (it.isNotEmpty()) {
val item = it.first()
data[context.getString(R.string.test_title)] = ""
data[context.getString(R.string.target_disease)] = item.disease.value
data[context.getString(R.string.type_of_test_title)] = item.typeOfTest.value
data[context.getString(R.string.test_name_title)] = item.testName.orEmpty()
data[context.getString(R.string.test_name_manufacturer_title)] = item.testNameAndManufacturer.orEmpty()
data[context.getString(R.string.date_time_of_collection_title)] = item.dateTimeOfCollection
data[context.getString(R.string.date_time_of_test_result_title)] = item.dateTimeOfTestResult.orEmpty()
data[context.getString(R.string.test_result_title)] = item.testResult
data[context.getString(R.string.testing_centre_title)] = item.testingCentre
data[context.getString(R.string.country_of_vaccination_title)] = item.countryOfVaccination
data[context.getString(R.string.certificate_identifier_title)] = item.certificateIdentifier
data[context.getString(R.string.result_type_title)] = item.resultType.value
}
}
certificateModel.recoveryStatements?.let {
if (it.isNotEmpty()) {
val item = it.first()
data[context.getString(R.string.recovery_title)] = ""
data[context.getString(R.string.target_disease)] = item.disease.value
data[context.getString(R.string.date_of_first_positive_test_title)] = item.dateOfFirstPositiveTest
data[context.getString(R.string.country_of_vaccination_title)] = item.countryOfVaccination
data[context.getString(R.string.certificate_issuer_title)] = item.certificateIssuer
data[context.getString(R.string.certificate_valid_from_title)] = item.certificateValidFrom
data[context.getString(R.string.certificate_valid_until_title)] = item.certificateValidUntil
data[context.getString(R.string.certificate_identifier_title)] = item.certificateIdentifier
}
}

certAdapter.updateData(data)
setExpanded(false)
}

private fun setExpanded(expanded: Boolean) {
isExpanded = expanded
binding.expandButton.setImageResource(if (expanded) R.drawable.ic_icon_minus else R.drawable.ic_icon_plus)
binding.contentRecyclerView.isVisible = isExpanded
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class DetailedVerificationResultDialogFragment :
private val args by navArgs<DetailedVerificationResultDialogFragmentArgs>()
private val viewModel by viewModels<DetailedBaseVerificationResultViewModel>()

private lateinit var adapter: CertificateContentAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
adapter = CertificateContentAdapter(layoutInflater)
}

override fun onCreateBinding(
inflater: LayoutInflater,
container: ViewGroup?
Expand All @@ -63,14 +70,6 @@ class DetailedVerificationResultDialogFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.detailedVerificationResultHeaderView.setInfoClickListener {
Toast.makeText(
requireContext(),
"TODO implement info click handler",
Toast.LENGTH_SHORT
).show()
// TODO implement handler
}
handleDetailedVerificationResult(
args.standardizedVerificationResult,
args.certificateModel,
Expand Down Expand Up @@ -138,15 +137,19 @@ class DetailedVerificationResultDialogFragment :
) {
if (certificateModel == null || hcert.isNullOrBlank()) {
binding.certificateInfo.visibility = View.GONE
binding.certificateContent.visibility = View.GONE
binding.certificateRawInfo.visibility = View.GONE
} else {
binding.certificateInfo.setCertificateModel(
certificateModel,
standardizedVerificationResult,
ruleValidationResultModelsContainer
)
binding.certificateContent.setCertificateModel(certificateModel, adapter)
binding.certificateRawInfo.setHcert(hcert)

binding.certificateInfo.visibility = View.VISIBLE
binding.certificateContent.visibility = View.VISIBLE
binding.certificateRawInfo.visibility = View.VISIBLE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,19 @@ import dgca.verifier.app.android.model.rules.RuleValidationResultModelsContainer
import dgca.verifier.app.android.verification.StandardizedVerificationResult
import dgca.verifier.app.android.verification.StandardizedVerificationResultCategory

class DetailedVerificationResultHeaderView(context: Context, attrs: AttributeSet?) :
ConstraintLayout(context, attrs) {
class DetailedVerificationResultHeaderView(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) {

private val binding: ViewDetailedVerificationResultHeaderBinding =
ViewDetailedVerificationResultHeaderBinding.inflate(LayoutInflater.from(context), this)

fun setInfoClickListener(infoClickListener: OnClickListener?) {
binding.information.setOnClickListener { infoClickListener?.onClick(it) }
}

fun setUp(
standardizedVerificationResult: StandardizedVerificationResult,
certificateModel: CertificateModel?,
ruleValidationResultModelsContainer: RuleValidationResultModelsContainer?
) {
binding.personFullName.text = certificateModel?.getFullName() ?: ""

val isValid =
standardizedVerificationResult.category == StandardizedVerificationResultCategory.VALID
binding.information.visibility = if (isValid) View.GONE else View.VISIBLE
val isValid = standardizedVerificationResult.category == StandardizedVerificationResultCategory.VALID

val (colorRes, textRes) = when (standardizedVerificationResult.category) {
StandardizedVerificationResultCategory.VALID -> Pair(R.color.green, R.string.cert_valid)
Expand Down
31 changes: 0 additions & 31 deletions app/src/main/res/drawable/ic_icon_information.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,22 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/certificateRawInfo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

<dgca.verifier.app.android.verification.detailed.CertificateContentView
android:id="@+id/certificateContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/certificateInfo"
tools:visibility="visible" />

<dgca.verifier.app.android.verification.detailed.DetailedCertificateRawView
android:id="@+id/certificateRawInfo"
android:layout_width="0dp"
Expand All @@ -83,7 +93,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/certificateInfo"
app:layout_constraintTop_toBottomOf="@id/certificateContent"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
Loading

0 comments on commit ec83d6d

Please sign in to comment.