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 @@ -22,8 +22,8 @@ interface OrderApi {
@POST("orders/{orderIdentifier}/charge")
fun chargeOrder(@Path("orderIdentifier") orderIdentifier: String, @Body charge: Charge): Single<Charge>

@GET("/v1/users/{userId}/orders?filter=[{\"name\":\"status\",\"op\":\"in\",\"val\":\"[\"completed\"," +
"\"placed\",\"pending\"]\"}]&include=event,attendees&fields[attendees]=id")
@GET("/v1/users/{userId}/orders?filter=[{\"name\":\"status\",\"op\":\"in\",\"val\":[\"completed\"," +
"\"placed\",\"pending\"]}]&include=event,attendees&fields[attendees]=id")
fun ordersUnderUser(@Path("userId") userId: Long): Single<List<Order>>

@GET("/v1/orders/{orderIdentifier}/attendees")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
eventCurrency: String?,
eventTimeZone: String?,
ticketQuantity: Int,
donationAmount: Float,
discountCode: DiscountCode? = null
) {
itemView.ticketName.text = ticket.name
Expand Down Expand Up @@ -79,6 +80,7 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
itemView.price.text = resource.getString(R.string.enter_donation)
itemView.orderQtySection.isVisible = false
itemView.donationInput.isVisible = true
if (donationAmount > 0F) itemView.donationInput.setText(donationAmount.toString())
setupDonationTicketPicker(selectedListener, ticket)
}
TICKET_TYPE_FREE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import org.fossasia.openevent.general.utils.Utils.setToolbar
import org.jetbrains.anko.design.longSnackbar

const val TICKETS_FRAGMENT = "ticketsFragment"
private const val APPLY_DISCOUNT_CODE = 1
const val APPLY_DISCOUNT_CODE = 1
private const val SHOW_DISCOUNT_CODE_LAYOUT = 2
private const val DISCOUNT_CODE_APPLIED = 3

Expand Down Expand Up @@ -307,7 +307,10 @@ class TicketsFragment : Fragment() {
val retainedTicketIdAndQty: List<Triple<Int, Int, Float>>? = ticketsViewModel.ticketIdAndQty.value
if (retainedTicketIdAndQty != null) {
for (idAndQty in retainedTicketIdAndQty) {
handleTicketSelect(idAndQty.first, idAndQty.second)
if (idAndQty.third != 0F)
handleTicketDonationEntered(idAndQty.first, idAndQty.third)
else
handleTicketSelect(idAndQty.first, idAndQty.second)
}
ticketsRecyclerAdapter.setTicketAndQty(retainedTicketIdAndQty)
ticketsRecyclerAdapter.notifyDataSetChanged()
Expand All @@ -319,24 +322,32 @@ class TicketsFragment : Fragment() {
rootView.ticketTableHeader.isVisible = !show
rootView.ticketsRecycler.isVisible = !show
rootView.register.isVisible = !show
if (show) {
rootView.discountCodeLayout.isVisible = false
rootView.discountCodeAppliedLayout.isVisible = false
rootView.applyDiscountCode.isVisible = false
} else {
handleDiscountCodeVisibility(ticketsViewModel.discountCodeCurrentLayout)
}
}

private fun handleDiscountCodeVisibility(code: Int = APPLY_DISCOUNT_CODE) {
ticketsViewModel.discountCodeCurrentLayout = code
when (code) {
APPLY_DISCOUNT_CODE -> {
rootView.applyDiscountCode.visibility = View.VISIBLE
rootView.discountCodeAppliedLayout.visibility = View.GONE
rootView.discountCodeLayout.visibility = View.GONE
rootView.applyDiscountCode.isVisible = true
rootView.discountCodeAppliedLayout.isVisible = false
rootView.discountCodeLayout.isVisible = false
}
SHOW_DISCOUNT_CODE_LAYOUT -> {
rootView.applyDiscountCode.visibility = View.GONE
rootView.discountCodeAppliedLayout.visibility = View.GONE
rootView.discountCodeLayout.visibility = View.VISIBLE
rootView.applyDiscountCode.isVisible = false
rootView.discountCodeAppliedLayout.isVisible = false
rootView.discountCodeLayout.isVisible = true
}
DISCOUNT_CODE_APPLIED -> {
rootView.applyDiscountCode.visibility = View.GONE
rootView.discountCodeAppliedLayout.visibility = View.VISIBLE
rootView.discountCodeLayout.visibility = View.GONE
rootView.applyDiscountCode.isVisible = false
rootView.discountCodeAppliedLayout.isVisible = true
rootView.discountCodeLayout.isVisible = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {
if (it.id.toInt() == ticket.id)
currentDiscountCode = discountCode
}
val qty = if ((this::ticketAndQuantity.isInitialized)) ticketAndQuantity[position].second else 0
holder.bind(ticket, selectedListener, eventCurrency, eventTimeZone, qty, currentDiscountCode)
var qty = 0
var donation = 0F
if (this::ticketAndQuantity.isInitialized) {
val ticketIndex = ticketAndQuantity.map { it.first }.indexOf(ticket.id)
if (ticketIndex != -1) {
qty = ticketAndQuantity[ticketIndex].second
donation = ticketAndQuantity[ticketIndex].third
}
}

holder.bind(ticket, selectedListener, eventCurrency, eventTimeZone, qty, donation, currentDiscountCode)
}

override fun getItemCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TicketsViewModel(
private val mutableTicketTableVisibility = MutableLiveData<Boolean>()
val ticketTableVisibility: LiveData<Boolean> = mutableTicketTableVisibility
val ticketIdAndQty = MutableLiveData<List<Triple<Int, Int, Float>>>()
var discountCodeCurrentLayout = APPLY_DISCOUNT_CODE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to retain current discount code layout on screen rotation or coming back from AttendeeFragment


fun isLoggedIn() = authHolder.isLoggedIn()

Expand Down