Skip to content

Commit

Permalink
Zobrazení věku a fotky (#12)
Browse files Browse the repository at this point in the history
* age and photo in dto

* photo load

* reformat

* fix nullable photo

* version info
  • Loading branch information
jan-stanek authored Jul 12, 2023
1 parent aeda320 commit 6598d4a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 26 deletions.
6 changes: 4 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 33
versionCode 3
versionName "1.0"
versionCode 4
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -64,6 +64,8 @@ dependencies {
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"

implementation "io.coil-kt:coil:2.4.0"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/cz/skaut/srs/ticketsreader/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer

const val CONNECTED = "connected"
const val API_URL = "apiUrl"
const val SRS_URL = "srsUrl"
const val API_TOKEN = "apiToken"
const val SEMINAR_NAME = "seminarName"
const val SUBEVENTS = "subevents"
Expand All @@ -21,7 +21,7 @@ class Preferences private constructor() {
private lateinit var prefs: SharedPreferences

var connected: Boolean = false
var apiUrl: String? = null
var srsUrl: String? = null
var apiToken: String? = null
var seminarName: String? = null
var subevents: Array<SubeventInfo> = emptyArray()
Expand All @@ -33,16 +33,16 @@ class Preferences private constructor() {
load()
}

fun setConnectionInfo(apiUrl: String, apiToken: String) {
fun setConnectionInfo(srsUrl: String, apiToken: String) {
connected = true
this.apiUrl = apiUrl
this.srsUrl = srsUrl
this.apiToken = apiToken
save()
}

fun removeConnectionInfo() {
connected = false
apiUrl = null
srsUrl = null
apiToken = null
removeSeminarInfo()
}
Expand Down Expand Up @@ -73,7 +73,7 @@ class Preferences private constructor() {

private fun load() {
connected = prefs.getBoolean(CONNECTED, false)
apiUrl = prefs.getString(API_URL, null)
srsUrl = prefs.getString(SRS_URL, null)
apiToken = prefs.getString(API_TOKEN, null)
seminarName = prefs.getString(SEMINAR_NAME, null)

Expand All @@ -90,7 +90,7 @@ class Preferences private constructor() {
private fun save() {
val edit = prefs.edit()
edit.putBoolean(CONNECTED, connected)
edit.putString(API_URL, apiUrl)
edit.putString(SRS_URL, srsUrl)
edit.putString(API_TOKEN, apiToken)
edit.putString(SEMINAR_NAME, seminarName)
edit.putString(SUBEVENTS, Json.encodeToString(serializer(), subevents))
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/cz/skaut/srs/ticketsreader/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class ApiClient {
}

suspend fun getSeminarInfo(): SeminarInfo {
return getValidResponse("${Preferences.apiUrl}tickets/seminar")
return getValidResponse("${Preferences.srsUrl}api/tickets/seminar")
}

suspend fun checkTicket(userId: Int): TicketCheckInfo {
return getValidResponse(
"${Preferences.apiUrl}tickets/check-ticket/?userId=$userId" +
"${Preferences.srsUrl}api/tickets/check-ticket/?userId=$userId" +
"&subeventId=${Preferences.selectedSubeventId}"
)
}

private fun checkConnectionPreferences() {
if (Preferences.apiUrl == null || Preferences.apiToken == null) {
if (Preferences.srsUrl == null || Preferences.apiToken == null) {
throw ApiConfigException()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import kotlinx.serialization.Serializable
@Serializable
data class TicketCheckInfo(
@SerialName("attendee_name") val attendeeName: String,
@SerialName("attendee_age") val attendeeAge: Int,
@SerialName("attendee_photo") val attendeePhoto: String? = null,
val roles: Array<String>,
val subevents: Array<SubeventInfo>,
@SerialName("has_subevent") val hasSubevent: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class ConnectionQrProcessor(context: Context) : QrProcessor(context) {
override fun process(value: String) {
try {
val connectionInfo = Json.decodeFromString(ConnectionInfo.serializer(), value)
val apiUrl = connectionInfo.apiUrl
val srsUrl = connectionInfo.srsUrl
val apiToken = connectionInfo.apiToken
Preferences.setConnectionInfo(apiUrl, apiToken)
Preferences.setConnectionInfo(srsUrl, apiToken)

val apiClient = ApiClient()
val seminarInfo: SeminarInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package cz.skaut.srs.ticketsreader.processor

import android.graphics.Color
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import coil.load
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import cz.skaut.srs.ticketsreader.Preferences
import cz.skaut.srs.ticketsreader.R
import cz.skaut.srs.ticketsreader.api.ApiClient
import cz.skaut.srs.ticketsreader.api.ApiConfigException
Expand Down Expand Up @@ -59,6 +62,8 @@ class TicketQrProcessor(context: FragmentActivity) : QrProcessor(context) {
val tvStatus: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_status)
val tvMessage: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_message)
val tvName: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_name_text)
val tvAge: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_age_text)
val ivPhoto: ImageView = dialogView.findViewById(R.id.dialog_ticket_iv_photo)
val tvRoles: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_roles_text)
val tvSubevents: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_subevents_text)
val tvChecks: TextView = dialogView.findViewById(R.id.dialog_ticket_tv_checks_text)
Expand All @@ -80,6 +85,12 @@ class TicketQrProcessor(context: FragmentActivity) : QrProcessor(context) {
tvMessage.visibility = if (tvMessage.text == null) TextView.GONE else TextView.VISIBLE

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

if (ticketInfo.attendeePhoto != null) {
ivPhoto.load("${Preferences.srsUrl}${ticketInfo.attendeePhoto}")
}

tvRoles.text = ticketInfo.roles.joinToString(", ")
tvSubevents.text = ticketInfo.subevents
.map { it.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class ConnectionInfo(
val apiUrl: String,
val srsUrl: String,
val apiToken: String,
)
53 changes: 43 additions & 10 deletions app/src/main/res/layout/dialog_ticket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,50 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/dialog_ticket_tv_name_label"
android:layout_width="wrap_content"
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="@string/dialog_ticket_tv_name_label" />

<TextView
android:id="@+id/dialog_ticket_tv_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_marginTop="8dp"
android:orientation="vertical">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/dialog_ticket_tv_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="@string/dialog_ticket_tv_name_label" />

<TextView
android:id="@+id/dialog_ticket_tv_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/dialog_ticket_tv_age_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="@string/dialog_ticket_tv_age_label" />

<TextView
android:id="@+id/dialog_ticket_tv_age_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>

<ImageView
android:id="@+id/dialog_ticket_iv_photo"
android:importantForAccessibility="no" />
</TableRow>

<TableRow
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="activity_main_btn_scan_tickets">Kontrola vstupenek</string>

<string name="dialog_ticket_tv_name_label">Jméno: </string>
<string name="dialog_ticket_tv_age_label">Věk: </string>
<string name="dialog_ticket_tv_roles_label">Role: </string>
<string name="dialog_ticket_tv_subevents_label">Podakce: </string>
<string name="dialog_ticket_tv_checks_label">Kontrolováno: </string>
Expand All @@ -29,7 +30,7 @@
<string name="dialog_error_message_api_config_error">Propojení se SRS není nastaveno.</string>
<string name="dialog_error_message_api_connection_error">Připojení k SRS se nezdařilo, zkontrolujte připojení k internetu.</string>
<string name="dialog_error_message_api_unknown_error">Při připojení k SRS došlo k neznámé chybě.</string>
<string name="dialog_error_message_api_serialization_error">Neplatná odpověď SRS.</string>
<string name="dialog_error_message_api_serialization_error">Neplatná odpověď SRS, zkontrolujte, že používáte aktuální verzi aplikace a SRS.</string>

<string name="dialog_permission_title">Vyžadováno oprávnění</string>
<string name="dialog_permission_message_camera_required">Tato aplikace vyžaduje přístup k fotoaparátu pro skenování QR kódů.</string>
Expand Down

0 comments on commit 6598d4a

Please sign in to comment.