Skip to content

Commit

Permalink
Modify autofill update credential pixel to include backfilled parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
CDRussell committed Dec 19, 2024
1 parent a36b674 commit ca2147f
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.autofill.api.CredentialUpdateExistingCredentialsDialog
Expand All @@ -47,6 +48,10 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.android.support.AndroidSupportInjection
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import javax.inject.Inject
import timber.log.Timber

Expand Down Expand Up @@ -77,6 +82,14 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm
ViewModelProvider(this, viewModelFactory)[AutofillUpdatingExistingCredentialViewModel::class.java]
}

private val wasUsernameBackFilled: Deferred<Boolean> = lifecycleScope.async(start = LAZY) {
val usernameToSave = getCredentialsToSave().username ?: return@async false
partialCredentialSaveStore.wasBackFilledRecently(url = getOriginalUrl(), username = usernameToSave).also {
Timber.v("Determined that username was %sbackFilled", if (it) "" else "not ")
}
}


override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
Expand All @@ -96,7 +109,11 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
pixelNameDialogEvent(Shown)?.let { pixel.fire(it) }
pixelNameDialogEvent(Shown)?.let {
lifecycleScope.launch {
pixel.fire(it, paramsForUpdateLoginPixel())
}
}

autofillFireproofDialogSuppressor.autofillSaveOrUpdateDialogVisibilityChanged(visible = true)

Expand Down Expand Up @@ -144,7 +161,11 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm
}

binding.updateCredentialsButton.setOnClickListener {
pixelNameDialogEvent(Updated)?.let { pixel.fire(it) }
pixelNameDialogEvent(Updated)?.let {
lifecycleScope.launch {
pixel.fire(it, paramsForUpdateLoginPixel())
}
}

val result = Bundle().also {
it.putString(CredentialUpdateExistingCredentialsDialog.KEY_URL, originalUrl)
Expand Down Expand Up @@ -186,7 +207,11 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm

Timber.v("onCancel: AutofillUpdatingExistingCredentialsDialogFragment. User declined to update credentials")
autofillFireproofDialogSuppressor.autofillSaveOrUpdateDialogVisibilityChanged(visible = false)
pixelNameDialogEvent(Dismissed)?.let { pixel.fire(it) }
pixelNameDialogEvent(Dismissed)?.let {
lifecycleScope.launch {
pixel.fire(it, paramsForUpdateLoginPixel())
}
}
}

private fun pixelNameDialogEvent(dialogEvent: DialogEvent): AutofillPixelNames? {
Expand All @@ -198,6 +223,10 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm
}
}

private suspend fun paramsForUpdateLoginPixel(): Map<String, String> {
return mapOf(PIXEL_PARAM_WAS_USERNAME_BACKFILLED to wasUsernameBackFilled.await().toString())
}

private interface DialogEvent {
object Shown : DialogEvent
object Dismissed : DialogEvent
Expand Down Expand Up @@ -228,5 +257,7 @@ class AutofillUpdatingExistingCredentialsDialogFragment : BottomSheetDialogFragm
}
return fragment
}

private const val PIXEL_PARAM_WAS_USERNAME_BACKFILLED = "backfilled"
}
}

0 comments on commit ca2147f

Please sign in to comment.