Skip to content

Commit

Permalink
fix: modify super dgp behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-95 committed Dec 1, 2021
1 parent 8f7e4f0 commit bbaa37d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AlertDialogCaller {

mBuilder.setTitle(title)
mBuilder.setSingleChoiceItems(scanModeChoices, chosenScanMode) { dialog, which ->
if (!viewModel.getScanModeFlag()) viewModel.setScanModeFlag(true)
if (which == 0) {
viewModel.setScanMode("2G")
} else if (which == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import android.view.View
Expand All @@ -40,6 +41,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.text.bold
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.observe
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -52,6 +54,7 @@ import it.ministerodellasalute.verificaC19sdk.model.FirstViewModel
import it.ministerodellasalute.verificaC19sdk.model.VerificationViewModel
import it.ministerodellasalute.verificaC19sdk.util.FORMATTED_DATE_LAST_SYNC
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.parseTo
import java.util.*

@AndroidEntryPoint
class FirstActivity : AppCompatActivity(), View.OnClickListener {
Expand All @@ -62,6 +65,8 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener {

private lateinit var sharedPreference: SharedPreferences

private lateinit var verificationViewModel: VerificationViewModel

private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
if (isGranted) {
Expand Down Expand Up @@ -127,14 +132,33 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener {
}

sharedPreference = getSharedPreferences("dgca.verifier.app.pref", Context.MODE_PRIVATE)
val verificationViewModel = ViewModelProvider(this)[VerificationViewModel::class.java]
verificationViewModel = ViewModelProvider(this)[VerificationViewModel::class.java]

verificationViewModel.scanMode.observe(this, {
val chosenScanMode = if (it == "3G") getString(R.string.scan_mode_3G) else getString(R.string.scan_mode_2G)
binding.scanModeButton.text = chosenScanMode
setScanModeTexts(it)
})
}

private fun setScanModeTexts(currentScanMode: String) {
if (!verificationViewModel.getScanModeFlag()) {
val s = SpannableStringBuilder()
.bold { append(getString(R.string.label_choose_scan_mode)) }
binding.scanModeButton.text = s
} else {
var chosenScanMode =
if (currentScanMode == "3G") getString(R.string.scan_mode_3G_header) else getString(
R.string.scan_mode_2G_header
)
chosenScanMode += "\n"
val chosenScanModeText =
if (currentScanMode == "3G") getString(R.string.scan_mode_3G) else getString(R.string.scan_mode_2G)
val s = SpannableStringBuilder()
.bold { append(chosenScanMode) }
.append(chosenScanModeText)
binding.scanModeButton.text = s
}
}

private fun checkCameraPermission() {
if (ContextCompat.checkSelfPermission(
this,
Expand Down Expand Up @@ -167,8 +191,21 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener {

override fun onResume() {
super.onResume()
val chosenScanMode = if (sharedPreference.getString("scan_mode", "3G") == "3G") getString(R.string.scan_mode_3G) else getString(R.string.scan_mode_2G)
binding.scanModeButton.text = chosenScanMode
if (!sharedPreference.getBoolean("scan_mode_flag", false)) {
val s = SpannableStringBuilder()
.bold { append(getString(R.string.label_choose_scan_mode)) }
binding.scanModeButton.text = s
} else {
var chosenScanMode =
if (sharedPreference.getString("scan_mode", "3G") == "3G") getString(R.string.scan_mode_3G_header) else getString(R.string.scan_mode_2G_header)
chosenScanMode += "\n"
val chosenScanModeText =
if (sharedPreference.getString("scan_mode", "3G") == "3G") getString(R.string.scan_mode_3G) else getString(R.string.scan_mode_2G)
val s = SpannableStringBuilder()
.bold { append(chosenScanMode) }
.append(chosenScanModeText)
binding.scanModeButton.text = s
}
viewModel.getAppMinVersion().let {
if (Utility.versionCompare(it, BuildConfig.VERSION_NAME) > 0 || viewModel.isSDKVersionObsoleted()) {
createForceUpdateDialog()
Expand All @@ -191,6 +228,9 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener {
if (it == -1L) {
createNoKeyAlert()
return
} else if (!verificationViewModel.getScanModeFlag() && v?.id != R.id.scan_mode_button) {
createNoScanModeChosenAlert()
return
}
}
when (v?.id) {
Expand All @@ -199,12 +239,29 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener {
R.id.scan_mode_button -> AlertDialogCaller.showScanModeChoiceAlertDialog(
this,
getString(R.string.label_scan_mode),
arrayOf(getString(R.string.scan_mode_2G), getString(R.string.scan_mode_3G)),
arrayOf(getString(R.string.label_alert_dialog_option, getString(R.string.label_scan_mode), getString(R.string.scan_mode_2G_header).substringAfter(
' '
).toUpperCase(Locale.ROOT)),
getString(R.string.label_alert_dialog_option, getString(R.string.label_scan_mode), getString(R.string.scan_mode_3G_header).substringAfter(' ').toUpperCase(
Locale.ROOT
)
)
),
ViewModelProvider(this)[VerificationViewModel::class.java]
)
}
}

private fun createNoScanModeChosenAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.noKeyAlertTitle))
builder.setMessage(getString(R.string.label_no_scan_mode_chosen))
builder.setPositiveButton(getString(R.string.ok)) { _, _ ->
}
val dialog = builder.create()
dialog.show()
}

private fun createNoKeyAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.noKeyAlertTitle))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ class SettingsActivity : AppCompatActivity(), View.OnClickListener {
setContentView(binding.root)

setSwitchesValue()
setTextViewsValue()
setLiveDataObservers()
setButtonsListener()
}

private fun setButtonsListener() {
binding.backImage.setOnClickListener(this)
binding.backText.setOnClickListener(this)
binding.totemSwitch.setOnClickListener(this)
binding.scanCard.setOnClickListener(this)
binding.faqCard.setOnClickListener(this)
binding.privacyPolicyCard.setOnClickListener(this)
}
Expand All @@ -63,37 +60,11 @@ class SettingsActivity : AppCompatActivity(), View.OnClickListener {
binding.totemSwitch.isChecked = viewModel.getTotemMode()
}

private fun setTextViewsValue() {
val chosenScanMode =
if (viewModel.getScanMode() == "3G") getString(R.string.scan_mode_3G_short) else getString(
R.string.scan_mode_2G_short
)
binding.chosenScanText.text = chosenScanMode
}

private fun setLiveDataObservers() {
viewModel.scanMode.observe(this, {
val chosenScanMode =
if (it == "3G") getString(R.string.scan_mode_3G_short) else getString(R.string.scan_mode_2G_short)
binding.chosenScanText.text = chosenScanMode
})
}

override fun onClick(v: View?) {
if (v?.id == R.id.back_image || v?.id == R.id.back_text) {
finish()
} else if (v?.id == R.id.totem_switch) {
viewModel.setTotemMode(binding.totemSwitch.isChecked)
} else if (v?.id == R.id.scan_card) {
AlertDialogCaller.showScanModeChoiceAlertDialog(
this,
getString(R.string.label_scan_mode),
arrayOf(
getString(R.string.scan_mode_2G),
getString(R.string.scan_mode_3G)
),
viewModel
)
} else if (v?.id == R.id.faq_card) {
val browserIntent =
Intent(Intent.ACTION_VIEW, Uri.parse("https://www.dgc.gov.it/web/pn.html"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import it.ministerodellasalute.verificaC19sdk.util.FORMATTED_VALIDATION_DATE
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.parseFromTo
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.parseTo
import it.ministerodellasalute.verificaC19sdk.util.YEAR_MONTH_DAY
import java.util.*

@ExperimentalUnsignedTypes
@AndroidEntryPoint
Expand Down Expand Up @@ -126,8 +127,19 @@ class VerificationFragment : Fragment(), View.OnClickListener {
}

private fun setScanModeText() {
val chosenScanMode = if (viewModel.getScanMode() == "3G") getString(R.string.scan_mode_3G) else getString(R.string.scan_mode_2G)
binding.scanModeText.text = chosenScanMode
val lowerCaseString: String
val upperCaseString: String
val chosenScanMode = if (viewModel.getScanMode() == "3G") {
lowerCaseString = getString(R.string.scan_mode_3G_header).substringAfter(' ')
upperCaseString = lowerCaseString.toUpperCase(Locale.ROOT)
getString(R.string.scan_mode_3G_header).replace(lowerCaseString, upperCaseString)
} else {
lowerCaseString = getString(R.string.scan_mode_2G_header).substringAfter(' ')
upperCaseString = lowerCaseString.toUpperCase(Locale.ROOT)
getString(R.string.scan_mode_2G_header).replace(lowerCaseString, upperCaseString)
}
val scanModeLabel = getString(R.string.label_scan_mode)
binding.scanModeText.text = getString(R.string.label_verification_scan_mode, scanModeLabel, chosenScanMode)
}

private fun setupTimeStamp(cert: CertificateSimple) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_keyboard_arrow_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M8.59,16.59L13.17,12 8.59,7.41 10,6l6,6 -6,6 -1.41,-1.41z"/>
</vector>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_first.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@
android:layout_marginHorizontal="@dimen/margin_24dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@android:color/transparent"
android:drawableEnd="@drawable/ic_baseline_create"
android:drawableEnd="@drawable/ic_baseline_keyboard_arrow_right"
android:drawablePadding="@dimen/padding_10dp"
android:drawableTint="@color/blue_dark"
android:fontFamily="@font/titiliumfont"
android:insetBottom="0dp"
android:padding="@dimen/padding_16dp"
android:paddingStart="@dimen/padding_20dp"
android:paddingEnd="@dimen/padding_20dp"
android:text="@string/label_scan_mode"
android:text="@string/label_choose_scan_mode"
android:textAlignment="textStart"
android:textColor="@color/blue_dark"
android:textSize="15sp"
android:textStyle="bold"

app:layout_constraintBottom_toTopOf="@id/qrButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
63 changes: 1 addition & 62 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,67 +171,6 @@

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/scan_card"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_16dp"
android:layout_marginTop="@dimen/margin_16dp"
android:background="@color/white"
app:cardCornerRadius="4dp"
app:cardElevation="@dimen/size_8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/totem_card">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/scan_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/titiliumfont"
android:paddingHorizontal="@dimen/margin_24dp"
android:paddingVertical="@dimen/margin_16dp"
android:text="@string/label_scan_mode"
android:textAllCaps="true"
android:textColor="@color/blue_dark"
android:textStyle="bold" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:padding="@dimen/padding_12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_create"
app:tint="@color/blue_dark"
android:contentDescription="@string/scan_mode_choice" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/chosen_scan_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:fontFamily="@font/titiliumfont"
android:textAllCaps="true"
android:textColor="@color/blue_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/scan_button"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/scan_mode_3G_short" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/information_text"
android:layout_width="match_parent"
Expand All @@ -246,7 +185,7 @@
android:layout_marginTop="@dimen/padding_30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/scan_card" />
app:layout_constraintTop_toBottomOf="@id/totem_card" />

<androidx.cardview.widget.CardView
android:id="@+id/faq_card"
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@
<string name="faq_card_title">Domande frequenti</string>
<string name="privacy_card_title">Rispetto della privacy</string>
<string name="label_totem_mode">Modalità automatica</string>
<string name="label_scan_mode">Tipologia verifica</string>
<string name="scan_mode_choice">Tipologia verifica</string>
<string name="scan_mode_3G">Vaccinazione/Guarigione/Test</string>
<string name="label_scan_mode">Tipologia Verifica</string>
<string name="label_scan_mode_ver">Tipologia di Verifica</string>
<string name="scan_mode_3G_header">Verifica Base</string>
<string name="scan_mode_2G_header">Verifica Rafforzata</string>
<string name="scan_mode_3G">Vaccinazione/Guarigione/Tampone</string>
<string name="scan_mode_2G">Vaccinazione/Guarigione</string>
<string name="scan_mode_3G_short">V/G/T</string>
<string name="scan_mode_2G_short">V/G</string>
<string name="label_choose_scan_mode">Scegli tipologia di verifica</string>
<string name="label_no_scan_mode_chosen">Per procedere alla scansione è necessario selezionare una delle due tipologie di verifica della Certificazione verde Covid-19: BASE o RAFFORZATA. Se si sceglie la tipologia BASE la app considera valide le certificazioni verdi generate sia da vaccinazione, sia da guarigione, sia da tampone molecolare o antigenico rapido. Se si sceglie la modalità RAFFORZATA la app considera valide solo le certificazioni verdi generate da vaccinazione o da guarigione. La verifica BASE viene utilizzata per l’accesso ai luoghi di lavoro, quella RAFFORZATA - dal 6 dicembre 2021 - per accedere a spettacoli, eventi sportivi, ristorazione al chiuso, feste e discoteche, cerimonie pubbliche, ecc. Per approfondimenti consultare https://www.dgc.gov.it/web/faq.html#verifica19</string>
<string name="label_alert_dialog_option">%1$s %2$s</string>
<string name="label_verification_scan_mode">%1$s: %2$s</string>
</resources>

0 comments on commit bbaa37d

Please sign in to comment.