Skip to content

Commit

Permalink
feat: new scan mode dialog
Browse files Browse the repository at this point in the history
Co-authored-by: Kaizen <[email protected]>
Co-authored-by: Light2288 <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent 1225a4d commit 626178a
Show file tree
Hide file tree
Showing 15 changed files with 548 additions and 125 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ android {

buildTypes {
debug {
buildConfigField "String", "FAQ_URL", "\"https://www.dgc.gov.it/web/app.html\""
buildConfigField "String", "PRIVACY_POLICY_URL", "\"https://www.dgc.gov.it/web/pn.html\""
buildConfigField "String", "VERIFICATION_FAQ_URL", "\"https://www.dgc.gov.it/web/faq.html#verifica19\""
minifyEnabled false
debuggable true
}

release {
buildConfigField "String", "FAQ_URL", "\"https://www.dgc.gov.it/web/app.html\""
buildConfigField "String", "PRIVACY_POLICY_URL", "\"https://www.dgc.gov.it/web/pn.html\""
buildConfigField "String", "VERIFICATION_FAQ_URL", "\"https://www.dgc.gov.it/web/faq.html#verifica19\""
//signingConfig signingConfigs.debug
debuggable false
minifyEnabled false
Expand Down Expand Up @@ -146,6 +152,7 @@ android {
dependencies {
implementation project(':dgc-sdk')
implementation project(':decoder')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
coreLibraryDesugaring Deps.desugar_jdk_libs

implementation Deps.kotlin_stdlib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
package it.ministerodellasalute.verificaC19.ui

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.*
import android.content.pm.PackageManager
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.text.Html
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.method.LinkMovementMethod
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import android.text.util.Linkify
import android.util.Log
import android.view.View
Expand All @@ -45,6 +42,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import androidx.core.text.bold
import androidx.core.view.isVisible
import com.google.gson.Gson
Expand All @@ -62,15 +60,15 @@ import it.ministerodellasalute.verificaC19.ui.main.MainActivity
import it.ministerodellasalute.verificaC19sdk.data.local.prefs.PrefKeys
import it.ministerodellasalute.verificaC19sdk.model.FirstViewModel
import it.ministerodellasalute.verificaC19sdk.model.ScanMode
import it.ministerodellasalute.verificaC19sdk.model.validation.RuleSet
import it.ministerodellasalute.verificaC19sdk.util.ConversionUtility
import it.ministerodellasalute.verificaC19sdk.util.FORMATTED_DATE_LAST_SYNC
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.parseTo
import it.ministerodellasalute.verificaC19sdk.util.Utility
import java.util.*

@AndroidEntryPoint
class FirstActivity : AppCompatActivity(), View.OnClickListener,
SharedPreferences.OnSharedPreferenceChangeListener {
SharedPreferences.OnSharedPreferenceChangeListener, DialogInterface.OnDismissListener {

private lateinit var binding: ActivityFirstBinding
private lateinit var shared: SharedPreferences
Expand Down Expand Up @@ -250,7 +248,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
.bold { append(getString(R.string.label_choose_scan_mode)) }
binding.scanModeButton.text = s
} else {
var chosenScanMode =
val chosenScanMode =
when (currentScanMode) {
ScanMode.STANDARD -> getString(R.string.scan_mode_3G_header)
ScanMode.STRENGTHENED -> getString(R.string.scan_mode_2G_header)
Expand All @@ -260,21 +258,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
ScanMode.SCHOOL -> getString(R.string.scan_mode_school_header)
else -> getString(R.string.scan_mode_3G_header)
}
chosenScanMode += "\n"
val chosenModeDescription =
when (currentScanMode) {
ScanMode.STANDARD -> getString(R.string.label_scan_mode_3G)
ScanMode.STRENGTHENED -> getString(R.string.label_scan_mode_2G)
ScanMode.BOOSTER -> getString(R.string.label_scan_mode_booster)
ScanMode.WORK -> getString(R.string.label_scan_mode_work)
ScanMode.ENTRY_ITALY -> getString(R.string.label_scan_mode_entry_italy)
ScanMode.SCHOOL -> getString(R.string.label_scan_mode_school)
else -> getString(R.string.label_scan_mode_3G)
}
val s = SpannableStringBuilder()
.bold { append(chosenScanMode) }
.append(chosenModeDescription)
binding.scanModeButton.text = s
binding.scanModeButton.text = chosenScanMode
}
}

Expand All @@ -288,7 +272,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,

private fun createCheckConnectionAlertDialog() {
val builder = AlertDialog.Builder(this)
var dialog: AlertDialog? = null
val dialog: AlertDialog?
builder.setTitle(
getString(R.string.no_internet_title)
)
Expand Down Expand Up @@ -397,7 +381,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,

override fun onResume() {
super.onResume()
setScanModeButtonText(viewModel.getScanMode()!!)
setScanModeButtonText(viewModel.getScanMode())
checkAppMinimumVersion()
}

Expand All @@ -424,105 +408,56 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
}

override fun onClick(v: View?) {
if (v?.id == R.id.qrButton) {
viewModel.getDateLastSync().let {
if (!viewModel.getScanModeFlag() && v.id != R.id.scan_mode_button) {
createNoScanModeChosenAlert()
return
} else if (it == -1L) {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage))
return
}
}
viewModel.getDrlDateLastSync().let {
if (binding.resumeDownload.isVisible) {
createNoSyncAlertDialog(getString(R.string.label_drl_download_in_progress))
return
when (v?.id) {
R.id.qrButton -> {
viewModel.getDateLastSync().let {
if (it == -1L) {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage))
return
} else if (!viewModel.getScanModeFlag() && v.id != R.id.scan_mode_button) {
viewModel.getRuleSet()?.getErrorScanModePopup()?.run {
createNoScanModeChosenAlert()
} ?: run { createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage)) }
return
}
}
if ((viewModel.getIsDrlSyncActive() && System.currentTimeMillis() >= it + 24 * 60 * 60 * 1000) ||
(viewModel.getIsDrlSyncActive() && it == -1L)
) {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessageForDrl))
return
viewModel.getDrlDateLastSync().let {
if (binding.resumeDownload.isVisible) {
createNoSyncAlertDialog(getString(R.string.label_drl_download_in_progress))
return
}
if ((viewModel.getIsDrlSyncActive() && System.currentTimeMillis() >= it + 24 * 60 * 60 * 1000) ||
(viewModel.getIsDrlSyncActive() && it == -1L)
) {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessageForDrl))
return
}
}
checkCameraPermission()
}
}
when (v?.id) {
R.id.qrButton -> checkCameraPermission()
R.id.settings -> openSettings()
R.id.scan_mode_button -> showScanModeChoiceAlertDialog()
R.id.circle_info_container -> createScanModeInfoAlert()
}
}

private fun showScanModeChoiceAlertDialog() {
val mBuilder = AlertDialog.Builder(this)
val chosenScanMode = when (viewModel.getScanMode()) {
ScanMode.STANDARD -> 0
ScanMode.STRENGTHENED -> 1
ScanMode.BOOSTER -> 2
ScanMode.WORK -> 3
ScanMode.ENTRY_ITALY -> 4
ScanMode.SCHOOL -> 5
else -> 0
}
val scanModeChoices = arrayOf(
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_3G_header),
getString(R.string.label_scan_mode_3G)
),
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_2G_header),
getString(R.string.label_scan_mode_2G)
),
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_booster_header),
getString(R.string.label_scan_mode_booster)
),
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_work_header),
getString(R.string.label_scan_mode_work)
),
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_entry_italy_header),
getString(R.string.label_scan_mode_entry_italy)
),
getString(
R.string.label_alert_dialog_option,
getString(R.string.scan_mode_school_header),
getString(R.string.label_scan_mode_school)
),
)

mBuilder.setTitle(getString(R.string.label_scan_mode))
mBuilder.setSingleChoiceItems(scanModeChoices, chosenScanMode) { dialog, which ->
if (!viewModel.getScanModeFlag()) viewModel.setScanModeFlag(true)
when (which) {
0 -> viewModel.setScanMode(ScanMode.STANDARD)
1 -> viewModel.setScanMode(ScanMode.STRENGTHENED)
2 -> viewModel.setScanMode(ScanMode.BOOSTER)
3 -> viewModel.setScanMode(ScanMode.WORK)
4 -> viewModel.setScanMode(ScanMode.ENTRY_ITALY)
5 -> viewModel.setScanMode(ScanMode.SCHOOL)
R.id.scan_mode_button -> {
viewModel.getRuleSet()?.run {
ScanModeDialogFragment(viewModel.getRuleSet()!!).show(supportFragmentManager, "SCAN_MODE_DIALOG_FRAGMENT")
} ?: run {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage))
}
}
R.id.circle_info_container -> {
viewModel.getRuleSet()?.getBaseScanModeDescription()?.run {
createScanModeInfoAlert()
} ?: run { createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage)) }
}
dialog.dismiss()
}
val mDialog = mBuilder.create()
mDialog.setCancelable(false)
mDialog.show()
}

private fun createNoScanModeChosenAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.noKeyAlertTitle))
val string = SpannableString(getText(R.string.label_no_scan_mode_chosen)).also {
Linkify.addLinks(it, Linkify.ALL)
}
val string =
SpannableString(Html.fromHtml(viewModel.getRuleSet()?.getErrorScanModePopup(), HtmlCompat.FROM_HTML_MODE_LEGACY)).also {
Linkify.addLinks(it, Linkify.ALL)
}
builder.setMessage(string)
builder.setPositiveButton(getString(R.string.ok)) { _, _ ->
}
Expand All @@ -535,7 +470,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
private fun createScanModeInfoAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.label_scan_mode_types))
val string = SpannableString(getText(R.string.label_scan_mode_types_description)).also {
val string = SpannableString(Html.fromHtml(viewModel.getRuleSet()?.getInfoScanModePopup(), HtmlCompat.FROM_HTML_MODE_LEGACY)).also {
Linkify.addLinks(it, Linkify.ALL)
}
builder.setMessage(string)
Expand Down Expand Up @@ -664,4 +599,9 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
ConversionUtility.byteToMegaByte(viewModel.getTotalSizeInByte().toFloat())
)
}

override fun onDismiss(dialog: DialogInterface?) {
setScanModeButtonText(viewModel.getScanMode())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-verifier-app-android
* ---
* Copyright (C) 2022 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 nicolamcornelio on 2/17/22, 2:54 PM
*/

package it.ministerodellasalute.verificaC19.ui

import android.annotation.SuppressLint
import android.transition.TransitionManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import it.ministerodellasalute.verificaC19.databinding.ScanModeChoiceLayoutBinding
import it.ministerodellasalute.verificaC19.ui.ScanModeDialogFragment.ScanModeChoice

class ScanModeAdapter(
private var adapterList: List<ScanModeChoice>,
var mSelectedItem: Int,
private val scanModeDialogFragment: ScanModeDialogCallback
) : RecyclerView.Adapter<ScanModeAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(ScanModeChoiceLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false))
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(adapterList[position], position, mSelectedItem)
}

override fun getItemCount() = adapterList.size

inner class ViewHolder(private val binding: ScanModeChoiceLayoutBinding) : RecyclerView.ViewHolder(binding.root) {

@SuppressLint("NotifyDataSetChanged")
fun bind(
scanMode: ScanModeChoice,
position: Int,
selectedPosition: Int
) {
binding.title.text = scanMode.name
binding.description.text = scanMode.description
binding.radioButton.isChecked = selectedPosition == position
binding.cardView.visibility = if (selectedPosition == position) View.VISIBLE else View.GONE

binding.root.setOnClickListener {
scanModeDialogFragment.enableConfirmButton()
mSelectedItem = adapterPosition
notifyDataSetChanged()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-verifier-app-android
* ---
* Copyright (C) 2022 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 nicolamcornelio on 2/23/22, 9:14 AM
*/

package it.ministerodellasalute.verificaC19.ui

interface ScanModeDialogCallback {
fun enableConfirmButton()
}
Loading

0 comments on commit 626178a

Please sign in to comment.