我有一个片段 (A),其中有 3 个操作可用。当用户选择一项操作时,在此之前,我需要询问他用于登录的密码。我想使用 BottomSheetDialogFragment 来做到这一点,但如果输入的密码正确,我不知道如何让片段 A 监听。
这是 BottomSheetDialogFragment 的代码
class ConfirmPasswordBottomSheet : BottomSheetDialogFragment() {
companion object {
const val TAG = "ConfirmPasswordBottomSheet"
}
fun newInstance(): ConfirmPasswordBottomSheet {
return ConfirmPasswordBottomSheet()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.CartissimaSheetDialogTheme)
}
@Inject
lateinit var sharedPreferences: SharedPreferences
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.bottom_confirm_pwd, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
showKeyboard()
confirm_pwd_btn.setOnClickListener {
if(DesEncrypted().encrypt(confirm_pwd_edit.text.toString()) == ServiceUtils.getPassword(sharedPreferences)){
}
}else{
with(requireActivity() as MainActivity) {
buildAlertMessageOneButton(
getString(R.string.common_warning),
getString(R.string.incorrect_password),
getString(R.string.common_close)
)
}
}
}
}
}
这是片段A中我需要检查密码的地方(在2个if之间)
show_pin_btn_float.setOnClickListener {
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)
}
}
}