|
|
|
@ -6,11 +6,15 @@ package org.mozilla.fenix.settings.creditcards
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
|
import kotlinx.android.synthetic.main.fragment_credit_card_editor.view.*
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.ext.showToolbar
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.Calendar
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a credit card editor for adding and editing a credit card.
|
|
|
|
@ -23,6 +27,7 @@ class CreditCardEditorFragment : Fragment(R.layout.fragment_credit_card_editor)
|
|
|
|
|
showToolbar(getString(R.string.credit_cards_add_card))
|
|
|
|
|
|
|
|
|
|
setupButtonClickListeners(view)
|
|
|
|
|
setupExpiryMonthDropDown(view)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -33,4 +38,29 @@ class CreditCardEditorFragment : Fragment(R.layout.fragment_credit_card_editor)
|
|
|
|
|
findNavController().popBackStack()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup the expiry month dropdown by formatting and populating it with the months in a calendar
|
|
|
|
|
* year.
|
|
|
|
|
*/
|
|
|
|
|
private fun setupExpiryMonthDropDown(view: View) {
|
|
|
|
|
val adapter =
|
|
|
|
|
ArrayAdapter<String>(view.context, android.R.layout.simple_spinner_dropdown_item)
|
|
|
|
|
val dateFormat = SimpleDateFormat("MMMM (MM)", Locale.getDefault())
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance()
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1)
|
|
|
|
|
|
|
|
|
|
for (month in 0..NUMBER_OF_MONTHS) {
|
|
|
|
|
calendar.set(Calendar.MONTH, month)
|
|
|
|
|
adapter.add(dateFormat.format(calendar.time))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view.expiry_month_drop_down.adapter = adapter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
// Number of months in a year (0-indexed).
|
|
|
|
|
private const val NUMBER_OF_MONTHS = 11
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|