althaf
03/08/2022, 12:08 PMwhen(args.approvalType) {
ApprovalType.MULTI_SELECT_BATCH_APPROVAL.ordinal,
ApprovalType.MULTI_SELECT_SINGLE_APPROVAL.ordinal -> {
context?.apply {
bgView.setBackgroundColor(getColor(R.color.sc_palette_green))
subTitleTextView.text = getString(R.string.approvalSuccessLabelText)
}
}
ApprovalType.MULTI_SELECT_SINGLE_APPROVAL.ordinal,
ApprovalType.MULTI_SELECT_SINGLE_REJECT.ordinal -> {
//TODO move to string resource
titleLineTitleTextView.text = "List of Transactions"
}
ApprovalType.MULTI_SELECT_BATCH_APPROVAL.ordinal,
ApprovalType.MULTI_SELECT_BATCH_REJECT.ordinal -> {
//TODO move to string resource
titleLineTitleTextView.text = "List of Batches"
}
ApprovalType.MULTI_SELECT_SINGLE_REJECT.ordinal,
ApprovalType.MULTI_SELECT_BATCH_REJECT.ordinal -> {
context?.apply {
subTitleTextView.text = getString(R.string.rejectSuccessLabelText)
bgView.setBackgroundColor(getColor(R.color.sc_palette_dark_blue))
}
}
}
Is this possible with when() to match two different blocks at the same time ?
Here i need to match multiple blocks are the same time, in different context, to show the text "List of Transactions" and "List of Batches"MR3Y
03/08/2022, 12:26 PMApprovalType.MULTI_SELECT_SINGLE_REJECT.ordinal
is true, when will stop here and choose that path even if you have another branch (i.e ApprovalType.MULTI_SELECT_BATCH_REJECT.ordinal
) that is true as wellRoukanken
03/08/2022, 12:39 PMisApproval()
/ isReject()
and isSingle()
/ isBatch()
to the enum, and then do something like this:
when {
approvalType.isApproval() -> doApprovalStuff()
approvalType.isBatch() -> doBatchStuff()
}
when {
approvalType.isSingle() -> doSingleStuff()
approvalType.isBatch() -> doBatchStuff()
}
?
with maybe some else -> throw ...
or else -> {}
added, depending on what you want.
this is way more readable, and the logic is grouped togetherRichard Gomez
03/08/2022, 12:54 PMalthaf
03/08/2022, 5:41 PMalthaf
03/08/2022, 6:00 PMwhen {
ApprovalType.isMultiSelectApproval(args.approvalType) -> {
context?.apply {
bgView.setBackgroundColor(getColor(R.color.sc_palette_green))
subTitleTextView.text = getString(R.string.approvalSuccessLabelText)
}
}
ApprovalType.isMultiSelectReject(args.approvalType) -> {
context?.apply {
subTitleTextView.text = getString(R.string.rejectSuccessLabelText)
bgView.setBackgroundColor(getColor(R.color.sc_palette_dark_blue))
}
}
}
when {
ApprovalType.isMultiSelectBatch(args.approvalType) -> {
//TODO move to string resource
titleLineTitleTextView.text = "List of Batches"
}
ApprovalType.isMultiSelectSingle(args.approvalType) -> {
//TODO move to string resource
titleLineTitleTextView.text = "List of Transactions"
}
}
thank you @MR3Y, @Richard Gomezalthaf
03/08/2022, 6:00 PMpackage com.alephlabs.clients.scb.s2b.ui.dashboard.approvals
enum class ApprovalType {
SINGLE,
BATCH,
PAYEE,
TEMPLATE,
TRANSACTION,
MULTI_SELECT_SINGLE_APPROVAL,
MULTI_SELECT_BATCH_APPROVAL,
MULTI_SELECT_SINGLE_REJECT,
MULTI_SELECT_BATCH_REJECT;
companion object {
fun isMultiSelectApproval(ordinal: Int) =
ordinal == MULTI_SELECT_BATCH_APPROVAL.ordinal
|| ordinal == MULTI_SELECT_SINGLE_APPROVAL.ordinal
fun isMultiSelectReject(ordinal: Int) =
ordinal == MULTI_SELECT_BATCH_REJECT.ordinal
|| ordinal == MULTI_SELECT_SINGLE_REJECT.ordinal
fun isMultiSelectBatch(ordinal: Int) =
ordinal == MULTI_SELECT_BATCH_REJECT.ordinal
|| ordinal == MULTI_SELECT_BATCH_APPROVAL.ordinal
fun isMultiSelectSingle(ordinal: Int) =
ordinal == MULTI_SELECT_SINGLE_REJECT.ordinal
|| ordinal == MULTI_SELECT_SINGLE_APPROVAL.ordinal
}
}
Roukanken
03/08/2022, 6:46 PMMULTI_SELECT_BATCH_APPROVAL
would get you executed all 4 branches, not just the 2 you want
meaning you would have "List of Batches"
and R.string.rejectSuccessLabelText
set, which is definitely not BATCH_APPROVAL