Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 7,
"identityHash": "bf12d8e7557281fa0414606f818fac5e",
"identityHash": "a641e7fa047321119d684609308e713a",
"entities": [
{
"tableName": "Event",
Expand Down Expand Up @@ -576,7 +576,7 @@
},
{
"tableName": "Ticket",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `description` TEXT, `type` TEXT, `name` TEXT NOT NULL, `maxOrder` INTEGER NOT NULL, `isFeeAbsorbed` INTEGER, `isDescriptionVisible` INTEGER, `price` REAL, `position` TEXT, `quantity` TEXT, `isHidden` INTEGER, `salesStartsAt` TEXT, `salesEndsAt` TEXT, `minOrder` INTEGER NOT NULL, `event` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`event`) REFERENCES `Event`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `description` TEXT, `type` TEXT, `name` TEXT NOT NULL, `maxOrder` INTEGER NOT NULL, `isFeeAbsorbed` INTEGER, `isDescriptionVisible` INTEGER, `price` REAL NOT NULL, `position` TEXT, `quantity` TEXT, `isHidden` INTEGER, `salesStartsAt` TEXT, `salesEndsAt` TEXT, `minOrder` INTEGER NOT NULL, `event` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`event`) REFERENCES `Event`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -624,7 +624,7 @@
"fieldPath": "price",
"columnName": "price",
"affinity": "REAL",
"notNull": false
"notNull": true
},
{
"fieldPath": "position",
Expand Down Expand Up @@ -1899,7 +1899,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bf12d8e7557281fa0414606f818fac5e')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a641e7fa047321119d684609308e713a')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ val viewModelModule = module {
viewModel { EventsViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { ProfileViewModel(get(), get()) }
viewModel { SignUpViewModel(get(), get(), get()) }
viewModel { EventDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { EventDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { SessionViewModel(get(), get(), get()) }
viewModel { SearchViewModel(get(), get()) }
viewModel { SearchResultsViewModel(get(), get(), get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import kotlinx.android.synthetic.main.content_event.view.socialLinkContainer
import kotlinx.android.synthetic.main.content_event.view.similarEventsRecycler
import kotlinx.android.synthetic.main.content_event.view.similarEventsContainer
import kotlinx.android.synthetic.main.content_event.view.alreadyRegisteredLayout
import kotlinx.android.synthetic.main.content_event.view.ticketPriceLinearLayout
import kotlinx.android.synthetic.main.content_event.view.priceRangeTextView
import kotlinx.android.synthetic.main.fragment_event.view.buttonTickets
import kotlinx.android.synthetic.main.fragment_event.view.eventErrorCard
import kotlinx.android.synthetic.main.fragment_event.view.container
Expand Down Expand Up @@ -203,6 +205,8 @@ class EventDetailsFragment : Fragment() {
eventViewModel.fetchEventSponsors(it.id)
if (eventViewModel.socialLinks.value == null)
eventViewModel.fetchSocialLink(it.id)
if (eventViewModel.priceRange.value == null)
eventViewModel.syncTickets(it)

// Update favorite icon and external event url menu option
activity?.invalidateOptionsMenu()
Expand All @@ -212,6 +216,13 @@ class EventDetailsFragment : Fragment() {
setHasOptionsMenu(true)
})

eventViewModel.priceRange
.nonNull()
.observe(viewLifecycleOwner, Observer {
rootView.ticketPriceLinearLayout.isVisible = true
rootView.priceRangeTextView.text = it
})

val eventIdentifier = arguments?.getString(EVENT_IDENTIFIER)
val event = eventViewModel.event.value
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ import org.fossasia.openevent.general.speakers.Speaker
import org.fossasia.openevent.general.speakers.SpeakerService
import org.fossasia.openevent.general.sponsor.Sponsor
import org.fossasia.openevent.general.sponsor.SponsorService
import org.fossasia.openevent.general.ticket.TicketPriceRange
import org.fossasia.openevent.general.ticket.TicketService
import org.fossasia.openevent.general.utils.extensions.withDefaultSchedulers
import timber.log.Timber
import java.lang.StringBuilder

class EventDetailsViewModel(
private val eventService: EventService,
private val ticketService: TicketService,
private val authHolder: AuthHolder,
private val speakerService: SpeakerService,
private val sponsorService: SponsorService,
Expand Down Expand Up @@ -74,6 +78,8 @@ class EventDetailsViewModel(
val similarEventsProgress: LiveData<Boolean> = mutableSimilarEventsProgress
private val mutableOrders = MutableLiveData<List<Order>>()
val orders: LiveData<List<Order>> = mutableOrders
private val mutablePriceRange = MutableLiveData<String>()
val priceRange: LiveData<String> = mutablePriceRange

fun isLoggedIn() = authHolder.isLoggedIn()

Expand Down Expand Up @@ -255,6 +261,55 @@ class EventDetailsViewModel(
})
}

fun syncTickets(event: Event) {
compositeDisposable += ticketService.syncTickets(event.id)
.withDefaultSchedulers()
.subscribe({
if (!it.isNullOrEmpty())
loadPriceRange(event)
}, {
Timber.e(it, "Error fetching tickets")
})
}

private fun loadPriceRange(event: Event) {
compositeDisposable += ticketService.getTicketPriceRange(event.id)
.withDefaultSchedulers()
.subscribe({
setRange(it, event.paymentCurrency.toString())
}, {
Timber.e(it, "Error fetching ticket price range")
})
}

private fun setRange(priceRange: TicketPriceRange, paymentCurrency: String) {
val maxPrice = priceRange.maxValue
val minPrice = priceRange.minValue
val range = StringBuilder()
if (maxPrice == minPrice) {
if (maxPrice == 0f)
range.append("Free")
else {
range.append(paymentCurrency)
range.append(" ")
range.append(minPrice)
}
} else {
if (minPrice == 0f)
range.append("Free")
else {
range.append(paymentCurrency)
range.append(" ")
range.append(minPrice)
}
range.append(" - ")
range.append(paymentCurrency)
range.append(" ")
range.append(maxPrice)
}
mutablePriceRange.value = range.toString()
}

fun loadMap(event: Event): String {
// location handling
val BASE_URL = "https://api.mapbox.com/v4/mapbox.emerald/pin-l-marker+673ab7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class Ticket(
val maxOrder: Int = 0,
val isFeeAbsorbed: Boolean? = false,
val isDescriptionVisible: Boolean? = false,
val price: Float?,
val price: Float,
val position: String?,
val quantity: String?,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ interface TicketDao {

@Query("SELECT * from Ticket WHERE id in (:ids)")
fun getTicketsWithIds(ids: List<Int>): Single<List<Ticket>>

@Query("SELECT MAX(price) as maxValue, MIN(price) as minValue from Ticket WHERE event = :eventId")
fun getTicketPriceRange(eventId: Long): Single<TicketPriceRange>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.fossasia.openevent.general.ticket

data class TicketPriceRange(
val maxValue: Float,
val minValue: Float
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class TicketService(
}
}

fun syncTickets(id: Long): Flowable<List<Ticket>> {
return ticketApi.getTickets(id).map {
ticketDao.insertTickets(it)
it
}
}

fun getTicketPriceRange(id: Long): Single<TicketPriceRange> {
return ticketDao.getTicketPriceRange(id)
}

fun getTicketDetails(id: Long): Single<Ticket> {
return ticketDao.getTicketDetails(id)
}
Expand Down
30 changes: 29 additions & 1 deletion app/src/main/res/layout/content_event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,34 @@
tools:text="Location" />
</LinearLayout>

<LinearLayout
android:id="@+id/ticketPriceLinearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_large"
android:layout_marginEnd="@dimen/layout_margin_medium"
android:visibility="gone"
android:background="?selectableItemBackground"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/refundPolicyLinearLayout"
app:layout_constraintTop_toBottomOf="@+id/refundPolicyLinearLayout">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/layout_margin_medium"
app:srcCompat="@drawable/ic_outline_ticket"
app:tint="@color/eventDetailsFragmentIcon"/>

<TextView
android:id="@+id/priceRangeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/layout_margin_medium"
android:textColor="@color/dark_grey"/>
</LinearLayout>

<LinearLayout
android:id="@+id/refundPolicyLinearLayout"
android:layout_width="0dp"
Expand Down Expand Up @@ -237,7 +265,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/refundPolicyLinearLayout"
app:layout_constraintTop_toBottomOf="@+id/ticketPriceLinearLayout"
tools:visibility="visible">

<View
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<color name="orderStatusBlue">#2889D2</color>
<color name="orderStatusGreen">#21BA45</color>
<color name="orderStatusOrange">#F2711C</color>
<color name="eventDetailsFragmentIcon">#b2b2b2</color>
</resources>