Essentially these changes don't change the behavior of anything from the Login library. This just changes the visibility of a couple of constant values as well as getStep() function from private to protecrted or public depending on the case.
Why we need this in WooCommerce? We are extending some of the existing Fragments in the login library to add some UI changes or like in this specific case to be able to handle custom actions when loginState is updated. With these small changes we now can do this in WooCommerce Android:
class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
companion object {
@Suppress("LongParameterList")
fun newInstance(
emailAddress: String?,
password: String?,
idToken: String?,
service: String?,
isSocialLogin: Boolean,
allowMagicLink: Boolean = false,
verifyMagicLinkEmail: Boolean = false
): WooLoginEmailPasswordFragment {
val fragment = WooLoginEmailPasswordFragment()
val args = Bundle()
args.putString(ARG_EMAIL_ADDRESS, emailAddress)
args.putString(ARG_PASSWORD, password)
args.putString(ARG_SOCIAL_ID_TOKEN, idToken)
args.putString(ARG_SOCIAL_SERVICE, service)
args.putBoolean(ARG_SOCIAL_LOGIN, isSocialLogin)
args.putBoolean(ARG_ALLOW_MAGIC_LINK, allowMagicLink)
args.putBoolean(ARG_VERIFY_MAGIC_LINK_EMAIL, verifyMagicLinkEmail)
fragment.arguments = args
return fragment
}
}
interface Listener {
fun onPasswordError()
}
private lateinit var onPassWordErrorListener: Listener
override fun onAttach(context: Context) {
super.onAttach(context)
if (activity is Listener) {
onPassWordErrorListener = activity as Listener
}
}
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
override fun onLoginStateUpdated(loginState: LoginState) {
super.onLoginStateUpdated(loginState)
if (loginState.step == FAILURE_EMAIL_WRONG_PASSWORD) {
onPassWordErrorListener.onPasswordError()
}
}
}
Basically, create a new WooLoginEmailPasswordFragment that enables us overriding fun onLoginStateUpdated() and that way schedule a "local" notification when the user runs into issues entering a valid password for their account.
Part of WooCommerce Login Help Notifications Itearion 3
Description
Essentially these changes don't change the behavior of anything from the Login library. This just changes the visibility of a couple of constant values as well as
getStep()
function fromprivate
toprotecrted
orpublic
depending on the case.Why we need this in WooCommerce? We are extending some of the existing Fragments in the login library to add some UI changes or like in this specific case to be able to handle custom actions when
loginState
is updated. With these small changes we now can do this in WooCommerce Android:Basically, create a new
WooLoginEmailPasswordFragment
that enables us overridingfun onLoginStateUpdated()
and that way schedule a "local" notification when the user runs into issues entering a valid password for their account.