Skip to content

Commit

Permalink
Remove unused code and simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamboushaba committed Jan 16, 2025
1 parent 3dcfa9d commit 5c7bbc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,10 @@ class LoginActivity :
}
}

private fun showEmailPasswordScreen(
email: String?,
verifyEmail: Boolean,
password: String? = null
) {
private fun showEmailPasswordScreen(email: String?, verifyEmail: Boolean) {
val wooLoginEmailPasswordFragment = WooLoginEmailPasswordFragment
.newInstance(
emailAddress = email,
password = password,
verifyMagicLinkEmail = verifyEmail
)
changeFragment(wooLoginEmailPasswordFragment, true, LoginEmailPasswordFragment.TAG)
Expand Down Expand Up @@ -969,7 +964,7 @@ class LoginActivity :
stat = AnalyticsEvent.LOGIN_APP_LOGIN_LINK_SUCCESS,
properties = mapOf(KEY_FLOW to VALUE_WP_COM)
)
showEmailPasswordScreen(email = wpComEmail, verifyEmail = false, password = null)
showEmailPasswordScreen(email = wpComEmail, verifyEmail = false)
}

siteUrl.isNotEmpty() && username.isNotEmpty() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package com.woocommerce.android.ui.login.overrides

import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import androidx.annotation.LayoutRes
import androidx.core.view.isVisible
import com.bumptech.glide.Registry.MissingComponentException
import com.woocommerce.android.R
import com.woocommerce.android.extensions.isNotNullOrEmpty
import dagger.android.support.AndroidSupportInjection
import org.wordpress.android.login.LoginEmailPasswordFragment
import org.wordpress.android.login.LoginListener
import org.wordpress.android.login.widgets.WPLoginInputRow

class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
companion object {
@Suppress("LongParameterList")
fun newInstance(
emailAddress: String?,
password: String? = null,
idToken: String? = null,
service: String? = null,
isSocialLogin: Boolean = false,
Expand All @@ -28,7 +21,6 @@ class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
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)
Expand All @@ -39,48 +31,19 @@ class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
}
}

private var loginListener: LoginListener? = null
private var email: String? = null
private var isSocialLogin: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

email = requireArguments().getString(ARG_EMAIL_ADDRESS)
isSocialLogin = requireArguments().getBoolean(ARG_SOCIAL_LOGIN)
}

override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
loginListener = if (context is LoginListener) {
context
} else {
throw MissingComponentException("$context must implement LoginListener")
}
}

override fun onDetach() {
super.onDetach()
loginListener = null
}

@LayoutRes
override fun getContentLayout(): Int = R.layout.fragment_login_email_password

override fun setupContent(rootView: ViewGroup) {
super.setupContent(rootView)

// Replace the original magic link button with the new one in bottom section
val originalMagicLinkButton = rootView.findViewById<Button>(R.id.login_get_email_link)
rootView.findViewById<Button>(R.id.bottom_button_magic_link)?.apply {
isVisible = true // this button was intentionally hidden until the password screen is shown
setOnClickListener {
loginListener?.useMagicLinkInstead(email, false, true)
originalMagicLinkButton.performClick()
}
}

val prefilledPassword = requireArguments().getString(ARG_PASSWORD)
if (prefilledPassword.isNotNullOrEmpty()) {
rootView.findViewById<WPLoginInputRow>(R.id.login_password_row)
}
}
}

0 comments on commit 5c7bbc9

Please sign in to comment.