This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/chore/update_gradle811' into cho…
…re/update_gradle811 # Conflicts: # app/build.gradle # app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/WidgetCalendarItem.kt # app/src/main/java/de/tum/in/tumcampusapp/component/ui/openinghour/OpeningHoursDetailFragment.java # app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/BoughtTicketViewHolder.kt # app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketAmountViewHolder.kt # app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/fragment/EventDetailsFragment.kt # app/src/main/java/de/tum/in/tumcampusapp/component/ui/tufilm/KinoDetailsFragment.kt # app/src/main/res/values-de/strings.xml # app/src/main/res/values/strings.xml # build.gradle
- Loading branch information
Showing
12 changed files
with
537 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/BoughtTicketViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.tum.`in`.tumcampusapp.component.ui.ticket | ||
|
||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import de.tum.`in`.tumcampusapp.R | ||
import de.tum.`in`.tumcampusapp.component.ui.ticket.model.TicketInfo | ||
import de.tum.`in`.tumcampusapp.utils.Utils | ||
|
||
class BoughtTicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
private val amountTextView: TextView by lazy { itemView.findViewById(R.id.ticket_amount) } | ||
private val ticketTypeNameTextView: TextView by lazy { itemView.findViewById(R.id.ticket_type_name) } | ||
private val ticketPriceTextView: TextView by lazy { itemView.findViewById(R.id.price_per_ticket) } | ||
|
||
fun bind(ticketInfo: TicketInfo) { | ||
amountTextView.text = itemView.context.getString(R.string.amount_x, ticketInfo.count) | ||
ticketTypeNameTextView.text = ticketInfo.ticketType?.description | ||
ticketPriceTextView.text = itemView.context.getString( | ||
R.string.price_per_ticket, | ||
Utils.formatPrice(ticketInfo.ticketType?.price ?: 0) | ||
) | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/TicketAmountViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package de.tum.`in`.tumcampusapp.component.ui.ticket | ||
|
||
import android.content.res.Resources | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.button.MaterialButton | ||
import de.tum.`in`.tumcampusapp.R | ||
import de.tum.`in`.tumcampusapp.component.ui.ticket.model.TicketType | ||
import de.tum.`in`.tumcampusapp.utils.Utils | ||
|
||
class TicketAmountViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
interface SelectTicketInterface { | ||
fun ticketAmountUpdated(ticketTypeId: Int, amount: Int) | ||
} | ||
|
||
private val minusButton: MaterialButton by lazy { itemView.findViewById(R.id.ticket_amount_minus) } | ||
private val plusButton: MaterialButton by lazy { itemView.findViewById(R.id.ticket_amount_plus) } | ||
private val currentAmount: TextView by lazy { itemView.findViewById(R.id.current_ticket_amount) } | ||
private val ticketTypeName: TextView by lazy { itemView.findViewById(R.id.ticket_type_name) } | ||
private val ticketPrice: TextView by lazy { itemView.findViewById(R.id.price_per_ticket) } | ||
|
||
private var ticketAmount = 1 | ||
private var ticketType = TicketType() | ||
private var ticketTypePos = 0 | ||
private var remainingTickets = 0 | ||
private var minAmount = 1 | ||
private var maxAmount = 1 | ||
|
||
fun bindToTicketType(ticketType: TicketType, position: Int) { | ||
this.ticketType = ticketType | ||
ticketTypePos = position | ||
|
||
minAmount = ticketType.paymentInfo.minTickets | ||
maxAmount = ticketType.paymentInfo.maxTickets | ||
|
||
if (position == 0) { | ||
ticketAmount = minAmount | ||
notifyActivity() | ||
} else { | ||
ticketAmount = 0 | ||
} | ||
|
||
// init text views | ||
ticketTypeName.text = ticketType.description | ||
ticketPrice.text = itemView.resources.getString(R.string.price_per_ticket, Utils.formatPrice(ticketType.price)) | ||
currentAmount.text = ticketAmount.toString() | ||
// init buttons | ||
plusButton.setOnClickListener { updateTicketAmount(true) } | ||
minusButton.setOnClickListener { updateTicketAmount(false) } | ||
|
||
// handle how many tickets are left | ||
remainingTickets = ticketType.contingent - ticketType.sold | ||
maxAmount = Math.min(maxAmount, remainingTickets) | ||
if (remainingTickets < minAmount) { | ||
ticketAmount = 0 | ||
currentAmount.text = ticketAmount.toString() | ||
plusButton.isEnabled = false | ||
minusButton.isEnabled = false | ||
ticketTypeName.setTextColor(Resources.getSystem().getColor(R.color.text_light_gray, null)) | ||
} | ||
updateButtonState() | ||
} | ||
|
||
/** | ||
* Updates the current ticket amount when the plus or minus button is clicked, | ||
* makes sure the min and max amount of tickets is adhered to (either 0 tickets or minAmount of tickets, nothing in between) | ||
* and the user doesn't select more tickets than are available | ||
*/ | ||
private fun updateTicketAmount(increase: Boolean) { | ||
if (increase) { | ||
if (ticketAmount == 0) { | ||
ticketAmount = minAmount | ||
} else { | ||
ticketAmount++ | ||
} | ||
} else { | ||
if (ticketAmount == minAmount) { | ||
ticketAmount = 0 | ||
} else { | ||
ticketAmount-- | ||
} | ||
} | ||
currentAmount.text = ticketAmount.toString() | ||
updateButtonState() | ||
|
||
notifyActivity() | ||
} | ||
|
||
private fun notifyActivity() { | ||
if (itemView.context is SelectTicketInterface) { | ||
(itemView.context as SelectTicketInterface).ticketAmountUpdated(ticketTypePos, ticketAmount) | ||
} else { | ||
Utils.log("The context is not a SelectTicketInterface") | ||
} | ||
} | ||
|
||
private fun updateButtonState() { | ||
plusButton.isEnabled = ticketAmount != maxAmount | ||
minusButton.isEnabled = ticketAmount != 0 | ||
} | ||
} |
Oops, something went wrong.