Skip to content

Commit

Permalink
Informace o nepropojeném účtu (#37)
Browse files Browse the repository at this point in the history
* attendee member info

* default photo

* detekt fix
  • Loading branch information
jan-stanek authored Nov 12, 2023
1 parent 91ef550 commit ebd4154
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "cz.skaut.srs.ticketsreader"
minSdk 26
targetSdk 34
versionCode 5
versionName "1.1.1"
versionCode 6
versionName "1.1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:name=".scanner.ScannerActivity"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"></activity>
tools:ignore="LockedOrientationActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ import kotlinx.serialization.Serializable

@Serializable
data class TicketCheckInfo(
/** Jméno účastníka. */
@SerialName("attendee_name") val attendeeName: String,

/** Věk účastníka. */
@SerialName("attendee_age") val attendeeAge: Int,

/** Odkaz na fotku účastníka. */
@SerialName("attendee_photo") val attendeePhoto: String? = null,

/** Má účastník propojený účet? */
@SerialName("attendee_member") val attendeeMember: Boolean,

/** Role účastníka. */
val roles: Array<String>,

/** Podakce účastníka. */
val subevents: Array<SubeventInfo>,

/** Má účastník podakci? */
@SerialName("has_subevent") val hasSubevent: Boolean,

/** Seznam časů kontroly vstupenky. */
@SerialName("subevent_checks") val subeventChecks: Array<Instant>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.graphics.Color
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.fragment.app.FragmentActivity
import coil.load
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand All @@ -22,7 +23,8 @@ import org.slf4j.LoggerFactory
import java.time.ZoneId
import java.time.format.DateTimeFormatter

private const val COLOR_ORANGE = 0xffffa500;
private const val COLOR_ORANGE = 0xffffa500
private const val ADULT_MIN_AGE = 18

class TicketQrProcessor(context: FragmentActivity) : QrProcessor(context) {
private val log = LoggerFactory.getLogger(this.javaClass)
Expand Down Expand Up @@ -70,27 +72,40 @@ class TicketQrProcessor(context: FragmentActivity) : QrProcessor(context) {
val tvSubevents: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_subevents_text)
val tvChecks: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_checks_text)

val messages: MutableList<String> = mutableListOf()

if (!ticketInfo.hasSubevent) {
tvStatus.text = context.getString(R.string.dialog_ticket_status_invalid)
tvStatus.setTextColor(Color.RED)
tvMessage.text = context.getString(R.string.dialog_ticket_message_missing_subevent)
} else if (ticketInfo.subeventChecks.isNotEmpty()) {
tvStatus.text = context.getString(R.string.dialog_ticket_status_used)
tvStatus.setTextColor(COLOR_ORANGE.toInt())
tvMessage.text = context.getString(R.string.dialog_ticket_message_used)
messages.add(context.getString(R.string.dialog_ticket_message_missing_subevent))
} else {
tvStatus.text = context.getString(R.string.dialog_ticket_status_valid)
tvStatus.setTextColor(Color.GREEN)
tvMessage.text = null
if (ticketInfo.subeventChecks.isNotEmpty()) {
tvStatus.text = context.getString(R.string.dialog_ticket_status_used)
tvStatus.setTextColor(COLOR_ORANGE.toInt())
messages.add(context.getString(R.string.dialog_ticket_message_used))
} else {
tvStatus.text = context.getString(R.string.dialog_ticket_status_valid)
tvStatus.setTextColor(Color.GREEN)
}

if (!ticketInfo.attendeeMember) {
messages.add(context.getString(R.string.dialog_ticket_message_not_member))
}
if (ticketInfo.attendeeAge < ADULT_MIN_AGE) {
messages.add(context.getString(R.string.dialog_ticket_message_not_adult))
}
}

tvMessage.visibility = if (tvMessage.text == null) TextView.GONE else TextView.VISIBLE
tvMessage.text = messages.joinToString("\n")
tvMessage.visibility = if (messages.isEmpty()) TextView.GONE else TextView.VISIBLE

tvName.text = ticketInfo.attendeeName
tvAge.text = ticketInfo.attendeeAge.toString()

if (ticketInfo.attendeePhoto != null) {
ivPhoto.load("${Preferences.srsUrl}${ticketInfo.attendeePhoto}")
} else {
ivPhoto.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.no_photo))
}

tvRoles.text = ticketInfo.roles.joinToString(", ")
Expand Down
Binary file added app/src/main/res/drawable/no_photo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/src/main/res/layout/dialog_ticket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:textAlignment="center"
android:textSize="16sp" />

Expand All @@ -33,6 +34,7 @@
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:gravity="center_horizontal">

<ImageView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<string name="dialog_ticket_status_invalid">Neplatná</string>
<string name="dialog_ticket_message_used">Vstupenka již byla dříve načtena.</string>
<string name="dialog_ticket_message_missing_subevent">Účastník nemá kontrolovanou podakci.</string>
<string name="dialog_ticket_message_not_member">Účastník nemá propojený účet.</string>
<string name="dialog_ticket_message_not_adult">Účastník je mladší 18 let.</string>

<string name="dialog_error_title">Chyba</string>
<string name="dialog_error_message_invalid_ticket_qr">Neplatný QR kód vstupenky.</string>
Expand Down

0 comments on commit ebd4154

Please sign in to comment.