Skip to content

Commit

Permalink
Show Not now as secondary button during autofill onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
cmonfortep committed Oct 27, 2024
1 parent 6415f0f commit 7957646
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.duckduckgo.autofill.impl.ui.credential.saving.AutofillSavingCredentia
import com.duckduckgo.autofill.impl.ui.credential.saving.AutofillSavingCredentialsDialogFragment.DialogEvent.Shown
import com.duckduckgo.autofill.impl.ui.credential.saving.AutofillSavingCredentialsViewModel.ViewState
import com.duckduckgo.autofill.impl.ui.credential.saving.declines.AutofillDeclineCounter
import com.duckduckgo.common.ui.view.button.DaxButton
import com.duckduckgo.common.ui.view.prependIconToText
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.FragmentViewModelFactory
Expand Down Expand Up @@ -115,6 +116,8 @@ class AutofillSavingCredentialsDialogFragment : BottomSheetDialogFragment(), Cre

private lateinit var keyFeaturesContainer: ViewGroup

private lateinit var secondaryButton: DaxButton

private val viewModel by lazy {
ViewModelProvider(this, viewModelFactory)[AutofillSavingCredentialsViewModel::class.java]
}
Expand Down Expand Up @@ -157,12 +160,14 @@ class AutofillSavingCredentialsDialogFragment : BottomSheetDialogFragment(), Cre

private fun renderViewState(viewState: ViewState) {
keyFeaturesContainer.isVisible = viewState.expandedDialog
configureSecondaryButtons(viewState.expandedDialog)
(dialog as? BottomSheetDialog)?.behavior?.isDraggable = viewState.expandedDialog
pixelNameDialogEvent(Shown, viewState.expandedDialog)?.let { pixel.fire(it) }
}

private fun configureViews(binding: ContentAutofillSaveNewCredentialsBinding) {
keyFeaturesContainer = binding.keyFeaturesContainer
secondaryButton = binding.secondaryButton
(dialog as BottomSheetDialog).behavior.state = BottomSheetBehavior.STATE_EXPANDED
configureCloseButtons(binding)
configureSaveButton(binding)
Expand Down Expand Up @@ -222,6 +227,16 @@ class AutofillSavingCredentialsDialogFragment : BottomSheetDialogFragment(), Cre
}
}

private fun onUserChoseNotNow() {
pixelNameDialogEvent(Dismissed, isOnboardingMode())?.let { pixel.fire(it) }

// this is another way to refuse saving credentials, so ensure that normal logic still runs
onUserRejectedToSaveCredentials()

// avoid the standard cancellation logic from running
ignoreCancellationEvents = true
}

private fun onUserChoseNeverSaveThisSite() {
pixelNameDialogEvent(Exclude, isOnboardingMode())?.let { pixel.fire(it) }
viewModel.addSiteToNeverSaveList(getOriginalUrl())
Expand All @@ -239,9 +254,21 @@ class AutofillSavingCredentialsDialogFragment : BottomSheetDialogFragment(), Cre
*/
private fun configureCloseButtons(binding: ContentAutofillSaveNewCredentialsBinding) {
binding.closeButton.setOnClickListener { animateClosed() }
binding.neverSaveForThisSiteButton.setOnClickListener {
onUserChoseNeverSaveThisSite()
animateClosed()
}

private fun configureSecondaryButtons(isOnboarding: Boolean) {
if (isOnboarding) {
secondaryButton.text = getString(R.string.saveOnboardingLoginDialogNotNow)
secondaryButton.setOnClickListener {
onUserChoseNotNow()
animateClosed()
}
} else {
secondaryButton.text = getString(R.string.saveLoginDialogNeverForThisSite)
secondaryButton.setOnClickListener {
onUserChoseNeverSaveThisSite()
animateClosed()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AutofillSavingCredentialsViewModel @Inject constructor(
viewModelScope.launch(dispatchers.io()) {
val shouldShowExpandedView = autofillDeclineCounter.declineCount() < 2 && autofillDeclineCounter.isDeclineCounterActive()
_viewState.value = ViewState(shouldShowExpandedView)
Timber.d("Autofill: AutofillSavingCredentialsViewModel initialized")
Timber.d("Autofill: AutofillSavingCredentialsViewModel initialized with expanded view state: $shouldShowExpandedView")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@
app:layout_constraintTop_toBottomOf="@id/keyFeaturesContainer" />

<com.duckduckgo.common.ui.view.button.DaxButtonGhost
android:id="@+id/neverSaveForThisSiteButton"
android:id="@+id/secondaryButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/saveLoginDialogNeverForThisSite"
app:buttonSize="large"
app:layout_constraintEnd_toEndOf="@id/saveLoginButton"
app:layout_constraintStart_toStartOf="@id/saveLoginButton"
Expand Down
2 changes: 2 additions & 0 deletions autofill/autofill-impl/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
<resources>
<!-- New Tab -->
<string name="newTabPageShortcutPasswords">Passwords</string>

<string name="saveOnboardingLoginDialogNotNow">Not Now</string>
</resources>

0 comments on commit 7957646

Please sign in to comment.