Skip to content

Commit

Permalink
fix: Add checkbox for enabling billing information (fossasia#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhanh11001 authored and liveHarshit committed Aug 11, 2019
1 parent 62faaf0 commit 2161798
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.firstName
import kotlinx.android.synthetic.main.fragment_attendee.view.helloUser
import kotlinx.android.synthetic.main.fragment_attendee.view.lastName
import kotlinx.android.synthetic.main.fragment_attendee.view.billingPostalCode
import kotlinx.android.synthetic.main.fragment_attendee.view.billingInfoCheckboxSection
import kotlinx.android.synthetic.main.fragment_attendee.view.billingEnabledCheckbox
import kotlinx.android.synthetic.main.fragment_attendee.view.attendeeScrollView
import kotlinx.android.synthetic.main.fragment_attendee.view.accept
import kotlinx.android.synthetic.main.fragment_attendee.view.amount
Expand Down Expand Up @@ -132,7 +134,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
private val safeArgs: AttendeeFragmentArgs by navArgs()
private lateinit var timer: CountDownTimer
private lateinit var card: Card
private var showBillingInfoLayout = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -141,8 +142,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
attendeeViewModel.singleTicket = safeArgs.ticketIdAndQty?.value?.map { it.second }?.sum() == 1
}

showBillingInfoLayout = safeArgs.hasPaidTickets || safeArgs.amount > 0

attendeeRecyclerAdapter.setEventId(safeArgs.eventId)
if (attendeeViewModel.paymentCurrency.isNotBlank())
ticketsRecyclerAdapter.setCurrency(attendeeViewModel.paymentCurrency)
Expand Down Expand Up @@ -503,12 +502,17 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
}

private fun setupBillingInfo() {
rootView.billingInfoContainer.isVisible = showBillingInfoLayout
attendeeViewModel.billingEnabled = showBillingInfoLayout
rootView.billingInfoCheckboxSection.isVisible = safeArgs.amount > 0
rootView.billingCompanyLayout.setRequired()
rootView.billingAddressLayout.setRequired()
rootView.billingCityLayout.setRequired()
rootView.billingPostalCodeLayout.setRequired()
rootView.billingInfoContainer.isVisible = rootView.billingEnabledCheckbox.isChecked
attendeeViewModel.billingEnabled = rootView.billingEnabledCheckbox.isChecked
rootView.billingEnabledCheckbox.setOnCheckedChangeListener { _, isChecked ->
attendeeViewModel.billingEnabled = isChecked
rootView.billingInfoContainer.isVisible = isChecked
}
}

private fun setupCountryOptions() {
Expand Down Expand Up @@ -691,7 +695,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
rootView.email.checkEmpty()

var checkBillingInfo = true
if (showBillingInfoLayout) {
if (rootView.billingEnabledCheckbox.isChecked) {
checkBillingInfo = rootView.billingCompany.checkEmpty() && rootView.billingAddress.checkEmpty() &&
rootView.billingCity.checkEmpty() && rootView.billingPostalCode.checkEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ class TicketsFragment : Fragment() {
ticketIdAndQty = wrappedTicketAndQty,
currency = safeArgs.currency,
amount = totalAmount,
taxAmount = ticketsViewModel.totalTaxAmount,
hasPaidTickets = ticketsViewModel.hasPaidTickets
taxAmount = ticketsViewModel.totalTaxAmount
))
ticketsViewModel.hasPaidTickets = false
}

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

fun isLoggedIn() = authHolder.isLoggedIn()

Expand Down Expand Up @@ -139,8 +138,6 @@ class TicketsViewModel(
}
}
price.let { prices += price * qty[index] }
if (ticket.type == TICKET_TYPE_PAID)
hasPaidTickets = true
index++
}
prices += totalTaxAmount
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/res/layout/fragment_attendee.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,25 @@
tools:itemCount="3"
tools:listitem="@layout/item_attendee" />

<RelativeLayout
android:id="@+id/billingInfoCheckboxSection"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/billing_information"
android:textColor="@color/black"
android:textSize="@dimen/heading_text_size"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"/>
<CheckBox
android:id="@+id/billingEnabledCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"/>
</RelativeLayout>

<LinearLayout
android:id="@+id/billingInfoContainer"
android:layout_width="match_parent"
Expand All @@ -434,13 +453,6 @@
android:visibility="gone"
tools:visibility="visible">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/billing_information"
android:textColor="@color/black"
android:textSize="@dimen/heading_text_size"/>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/billingCompanyLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/navigation/navigation_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,6 @@
app:argType="float"
app:nullable="false"
android:defaultValue="0.0"/>

<argument
android:name="hasPaidTickets"
app:argType="boolean"
android:defaultValue="false"/>
</fragment>
<fragment
android:id="@+id/orderCompletedFragment"
Expand Down

0 comments on commit 2161798

Please sign in to comment.