From e041063a14c1873989dff3fb1eea584c219a3dcd Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Mon, 22 Apr 2019 23:06:07 +0200 Subject: [PATCH] Temporarily fix show ticket crash (#1292) download ticketTypes explicitly when trying to view an a ticket --- .../tumcampusapp/component/ui/ticket/TicketTypeDao.java | 9 ++++----- .../component/ui/ticket/activity/ShowTicketActivity.java | 5 +++++ .../ui/ticket/repository/TicketsLocalRepository.kt | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketTypeDao.java b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketTypeDao.java index 6babe5e483..cab4bf097b 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketTypeDao.java +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketTypeDao.java @@ -1,12 +1,11 @@ package de.tum.in.tumcampusapp.component.ui.ticket; +import java.util.List; + import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; - -import java.util.List; - import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketType; @Dao @@ -18,8 +17,8 @@ public interface TicketTypeDao { @Query("SELECT * FROM ticket_types") List getAll(); - @Query("SELECT * FROM ticket_types WHERE id = :id") - TicketType getById(int id); + @Query("SELECT * FROM ticket_types tt, tickets t WHERE tt.id = t.ticket_type_id AND t.event_id = :eventId") + List getByEventId(int eventId); @Query("DELETE FROM ticket_types") void flush(); diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/ShowTicketActivity.java b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/ShowTicketActivity.java index 4cb2b1513d..dfc329d663 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/ShowTicketActivity.java +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/ShowTicketActivity.java @@ -35,6 +35,7 @@ import de.tum.in.tumcampusapp.component.ui.ticket.model.Event; import de.tum.in.tumcampusapp.component.ui.ticket.model.Ticket; import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketInfo; +import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketType; import de.tum.in.tumcampusapp.component.ui.ticket.repository.EventsLocalRepository; import de.tum.in.tumcampusapp.component.ui.ticket.repository.TicketsLocalRepository; import de.tum.in.tumcampusapp.component.ui.ticket.repository.TicketsRemoteRepository; @@ -155,6 +156,10 @@ private void handleTicketRefreshFailure() { } private void loadTicketData(int eventId) { + List ticketTypes = ticketsLocalRepo.getTicketTypesByEventId(eventId); + if (ticketTypes.isEmpty()) { + ticketsLocalRepo.addTicketTypes(ticketsRemoteRepo.fetchTicketTypesForEvent(eventId).blockingSingle()); + } ticketInfoList = ticketsLocalRepo.getTicketsByEventId(eventId); event = eventsLocalRepo.getEventById(eventId); } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/repository/TicketsLocalRepository.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/repository/TicketsLocalRepository.kt index 1b4ca51852..a509f43c1b 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/repository/TicketsLocalRepository.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/repository/TicketsLocalRepository.kt @@ -20,7 +20,7 @@ class TicketsLocalRepository @Inject constructor( fun getTicketsByEventId(eventId: Int): List = database.ticketDao().getByEventId(eventId) - fun getTicketTypeById(id: Int): TicketType = database.ticketTypeDao().getById(id) + fun getTicketTypesByEventId(eventId: Int): List = database.ticketTypeDao().getByEventId(eventId) fun addTicketTypes(ticketTypes: List) { database.ticketTypeDao().insert(ticketTypes)