Skip to content

feat: Add ticket details #2031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2019
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 @@ -3,6 +3,7 @@ package org.fossasia.openevent.general.ticket
import android.graphics.Paint
import android.text.Editable
import android.text.TextWatcher
import android.text.Html
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
Expand All @@ -17,7 +18,18 @@ import kotlinx.android.synthetic.main.item_ticket.view.donationInput
import kotlinx.android.synthetic.main.item_ticket.view.orderQtySection
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.data.Resource
import kotlinx.android.synthetic.main.item_ticket.view.priceInfo
import kotlinx.android.synthetic.main.item_ticket.view.moreInfoSection
import kotlinx.android.synthetic.main.item_ticket.view.seeMoreInfoText
import kotlinx.android.synthetic.main.item_ticket.view.ticketDateText
import kotlinx.android.synthetic.main.item_ticket.view.saleInfo
import kotlinx.android.synthetic.main.item_ticket.view.description
import org.fossasia.openevent.general.discount.DiscountCode
import org.fossasia.openevent.general.event.EventUtils
import org.fossasia.openevent.general.event.EventUtils.getFormattedDate
import org.threeten.bp.DateTimeUtils
import java.util.Date
import kotlin.collections.ArrayList

const val AMOUNT = "amount"
const val TICKET_TYPE_FREE = "free"
Expand All @@ -31,10 +43,19 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
ticket: Ticket,
selectedListener: TicketSelectedListener?,
eventCurrency: String?,
eventTimeZone: String?,
ticketQuantity: Int,
discountCode: DiscountCode? = null
) {
itemView.ticketName.text = ticket.name
setupTicketSaleDate(ticket, eventTimeZone)

setMoreInfoText()
itemView.seeMoreInfoText.setOnClickListener {
itemView.moreInfoSection.isVisible = !itemView.moreInfoSection.isVisible
setMoreInfoText()
}

var minQty = ticket.minOrder
var maxQty = ticket.maxOrder
if (discountCode?.minQuantity != null)
Expand Down Expand Up @@ -74,6 +95,16 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
}
}

val priceInfo = "<b>${resource.getString(R.string.price)}:</b> ${itemView.price.text}"
itemView.priceInfo.text = Html.fromHtml(priceInfo)

if (ticket.description.isNullOrEmpty()) {
itemView.description.isVisible = false
} else {
itemView.description.isVisible = true
itemView.description.text = ticket.description
}

if (discountCode?.value != null && ticket.price != null && ticket.price != 0.toFloat()) {
itemView.discountPrice.visibility = View.VISIBLE
itemView.price.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
Expand Down Expand Up @@ -133,4 +164,37 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
}
}
}

private fun setMoreInfoText() {
itemView.seeMoreInfoText.text = resource.getString(
if (itemView.moreInfoSection.isVisible) R.string.see_less else R.string.see_more)
}

private fun setupTicketSaleDate(ticket: Ticket, timeZone: String?) {
val startAt = ticket.salesStartsAt
val endAt = ticket.salesEndsAt
if (startAt != null && endAt != null && timeZone != null) {
val startsAt = EventUtils.getEventDateTime(startAt, timeZone)
val endsAt = EventUtils.getEventDateTime(endAt, timeZone)
val startDate = DateTimeUtils.toDate(startsAt.toInstant())
val endDate = DateTimeUtils.toDate(endsAt.toInstant())
val currentDate = Date()

if (currentDate < startDate) {
itemView.ticketDateText.isVisible = true
itemView.ticketDateText.text = resource.getString(R.string.not_open)
itemView.orderQtySection.isVisible = false
} else if (startDate < currentDate && currentDate < endDate) {
itemView.ticketDateText.isVisible = false
itemView.orderQtySection.isVisible = true
} else {
itemView.ticketDateText.text = resource.getString(R.string.ended)
itemView.ticketDateText.isVisible = true
itemView.orderQtySection.isVisible = false
}

val salesEnd = "<b>${resource.getString(R.string.sales_end)}</b> ${getFormattedDate(endsAt)}"
itemView.saleInfo.text = Html.fromHtml(salesEnd)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class TicketsFragment : Fragment() {
val startsAt = EventUtils.getEventDateTime(event.startsAt, event.timezone)
val endsAt = EventUtils.getEventDateTime(event.endsAt, event.timezone)
rootView.time.text = EventUtils.getFormattedDateTimeRangeDetailed(startsAt, endsAt)
ticketsRecyclerAdapter.setTimeZone(event.timezone)
}

private fun handleNoTicketsSelected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {

private val tickets = ArrayList<Ticket>()
private var eventCurrency: String? = null
private var eventTimeZone: String? = null
private var discountCode: DiscountCode? = null
private var selectedListener: TicketSelectedListener? = null
private lateinit var ticketAndQuantity: List<Triple<Int, Int, Float>>
Expand All @@ -28,6 +29,11 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {
eventCurrency = currencyCode
}

fun setTimeZone(timeZone: String?) {
eventTimeZone = timeZone
notifyDataSetChanged()
}

fun applyDiscount(discountCode: DiscountCode) {
this.discountCode = discountCode
}
Expand All @@ -49,7 +55,7 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {
currentDiscountCode = discountCode
}
val qty = if ((this::ticketAndQuantity.isInitialized)) ticketAndQuantity[position].second else 0
holder.bind(ticket, selectedListener, eventCurrency, qty, currentDiscountCode)
holder.bind(ticket, selectedListener, eventCurrency, eventTimeZone, qty, currentDiscountCode)
}

override fun getItemCount(): Int {
Expand Down
73 changes: 65 additions & 8 deletions app/src/main/res/layout/item_ticket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,40 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/layout_margin_medium"
android:layout_marginRight="@dimen/layout_margin_medium"
android:padding="@dimen/layout_margin_medium"
android:elevation="@dimen/card_elevation"
android:background="@drawable/border"
android:background="@drawable/border">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/layout_margin_medium"
android:weightSum="8">

<TextView
android:id="@+id/ticketName"
android:weightSum="8"
android:layout_marginBottom="@dimen/layout_margin_medium">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
tools:text="Google I/O" />
android:orientation="vertical">
<TextView
android:id="@+id/ticketName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Google I/O" />
<TextView
android:id="@+id/seeMoreInfoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@color/colorAccent"
android:text="@string/see_more"
tools:text="@string/see_more"/>
</LinearLayout>


<LinearLayout
android:layout_width="0dp"
Expand Down Expand Up @@ -64,6 +83,17 @@
android:textSize="@dimen/text_size_small" />

</LinearLayout>
<TextView
android:id="@+id/ticketDateText"
android:layout_weight="2"
android:layout_width="@dimen/layout_margin_none"
android:layout_height="match_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="@dimen/text_size_large"
android:visibility="gone"
tools:visibility="visible"
tools:text="@string/ended"/>

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/donationInput"
Expand All @@ -74,5 +104,32 @@
android:inputType="number"
android:visibility="gone"
tools:visibility="visible"/>

</LinearLayout>
<LinearLayout
android:id="@+id/moreInfoSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/layout_margin_medium"
android:padding="@dimen/padding_medium"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible"
android:background="@drawable/filled_border">
<TextView
android:id="@+id/priceInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Price: $55.00"/>
<TextView
android:id="@+id/saleInfo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="Sales End: Jul 12, 2019" />
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="VIP Includes one hour early admission and free sample slices of pizza during VIP hour"
android:layout_marginBottom="@dimen/layout_margin_medium"/>
</LinearLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,5 +462,8 @@
<string name="error_cropping_image_message">Oops. There is an error on cropping image</string>
<string name="error_editting_image_message">Oops, there is an error. Current image can\'t be edited</string>
<string name="donation">Donation</string>
<string name="ended">Ended</string>
<string name="not_open">Not Open</string>
<string name="sales_end">Sales End:</string>

</resources>