Skip to content

Instantly share code, notes, and snippets.

Avatar

ChanoknadM annchar

View GitHub Profile
View MainActivity.kt
private fun getPaymentDetailToString(payment: Payment): String {
return when (payment) {
is Payment.CreditCard ->
"Credit Card \nName: ${payment.name} \nCard Number: ${payment.number} \nExpired Date: ${payment.expiredDate} \nTransfer Amount: ${payment.transferAmount}"
is Payment.CashBank ->
"Cash Bank \nBank Code: ${payment.bankCode} \nBank Name: ${payment.bankName} \nTransfer Amount: ${payment.transferAmount}"
is Payment.Promptpay ->
"Promptpay \nName: ${payment.name} \nCitizen Id: ${payment.citizenId} \nMobile Number: ${payment.mobileNumber} \nTransfer Amount: ${payment.transferAmount}"
Payment.NonePayment -> "None Payment"
}
View MainViewModel.kt
class MainViewModel : ViewModel() {
private val _paymentData = MutableLiveData<Payment>()
val paymentData = _paymentData
private val paymentByCreditCardData: Payment = Payment.CreditCard(
name = "AnnChar",
number = "123456789123",
expiredDate = "02/23",
transferAmount = 100.50
)
View PaymentEnumNormal.kt
enum class PaymentEnumNormal {
CREDIT_CARD, CASH_BANK, PROMTPAY, NONE
}
data class CreditCard(
val name: String,
val number: String,
val expiredDate: String,
val transferAmount: Double
)
View Payment.kt
sealed class Payment {
data class CreditCard(
val name: String,
val number: String,
val expiredDate: String,
val transferAmount: Double
) : Payment()
data class CashBank(
val bankCode: String,
View fragment_team_detail.xml
<layout... >
<data>
<variable
name="viewModel"
type="com.azaless.cheerball.viewmodels.TeamDetailViewModel" />
</data>
...
View TeamDetailViewModel.kt
class TeamDetailViewModel(private val cheerBallDataRepository: CheerBallDataRepository,
private val teamId: Int) : ViewModel() {
private val players = MutableLiveData<List<Player>>()
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
val adapter = MutableLiveData<PlayerListAdapter>()
val layoutManager = MutableLiveData<RecyclerView.LayoutManager>()
fun getPlayers(): LiveData<List<Player>> {
return players
View list_item_player.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android" >
<data>
<variable
name="player"
type="com.azaless.cheerball.view.model.Player" />
</data>
View PlayerListAdapter.kt
class PlayerListAdapter : DataBindingAdapter<List<Player>, PlayerListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = DataBindingUtil.inflate<ListItemPlayerBinding>(layoutInflater, R.layout.list_item_player, parent, false)
return ViewHolder(binding)
}
override fun getItemCount() = values?.size ?: 0
View list_item_team_small.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
View GroupBallItemAdapter.kt
class GroupBallItemAdapter : RecyclerView.Adapter<GroupBallItemAdapter.ViewHolder>(){
var values: List<GroupDetail> = listOf()
set(items) {
field = items
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_team_small, parent, false))
You can’t perform that action at this time.