You have to use an interface for this task. A simple use case for it is given below based on your code provided.
First create a listener in ConfirmPasswordBottomSheet
like:
class ConfirmPasswordBottomSheet : BottomSheetDialogFragment() {
private lateinit var listener: OnActionCompleteListener
fun setOnActionCompleteListener(listener: OnActionCompleteListener) {
this.listener = listener
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// your other code here
confirm_pwd_btn.setOnClickListener {
// pass the value of password here
listener.onActionComplete("your password is this")
}
}
// your other code here
interface OnActionCompleteListener {
fun onActionComplete(str: String)
}
}
Then after creating an instance of ConfirmPasswordBottomSheet
you have to invoke setOnActionCompleteListener()
by passing an instance of OnActionCompleteListener
.
Create an instance where you want to use it like below:
val listener = object: ConfirmPasswordBottomSheet.OnActionCompleteListener() {
fun onActionComplete(str: String) {
// do what you want to do here because this block will be invoked in bottom sheet
// you will receive "your password is this" here
// as per question maybe check your password / pin
if (with(activity as MainActivity) { checkCardPermission(PinOptionFragment.card.authorities[AuthoritiesCardEnum.CARTE_VIEW_PIN]!!) }) {
if (card.driverPin) {
cardViewModel.requestPinDriver(with(activity as MainActivity) { currentUser.mainCode })
} else {
cardViewModel.requestPin(card.pan)
}
}
}
}
After creating an instance of interface you have to set it to the ConfirmPasswordBottomSheet
's instance in Fragment (A) like below:
val bottomSheet = ConfirmPasswordBottomSheet()
bottomSheet.setOnActionCompleteListener(listener)
NOTE: this code is untested and might need some modification because it is off the top of my head.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…