-
Notifications
You must be signed in to change notification settings - Fork 1k
Show import promo in autofill management #6266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CDRussell
merged 2 commits into
develop
from
feature/cristian/autofill/promo_import_in_management
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...l-impl/src/main/java/com/duckduckgo/autofill/impl/importing/AutofillImportLaunchSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.autofill.impl.importing | ||
|
||
enum class AutofillImportLaunchSource(val value: String) { | ||
PasswordManagementPromo("passwords_management_promo"), | ||
AutofillSettings("autofill_settings"), | ||
PasswordManagementEmpty("passwords_management_empty"), | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
.../src/main/java/com/duckduckgo/autofill/impl/importing/promo/ImportInPasswordsPromotion.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.autofill.impl.importing.promo | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.FrameLayout | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.findViewTreeLifecycleOwner | ||
import androidx.lifecycle.findViewTreeViewModelStoreOwner | ||
import androidx.lifecycle.lifecycleScope | ||
import com.duckduckgo.anvil.annotations.InjectWith | ||
import com.duckduckgo.anvil.annotations.PriorityKey | ||
import com.duckduckgo.autofill.api.promotion.PasswordsScreenPromotionPlugin | ||
import com.duckduckgo.autofill.api.promotion.PasswordsScreenPromotionPlugin.Callback | ||
import com.duckduckgo.autofill.api.promotion.PasswordsScreenPromotionPlugin.Companion.PRIORITY_KEY_IMPORT_PROMO | ||
import com.duckduckgo.autofill.impl.R | ||
import com.duckduckgo.autofill.impl.databinding.ViewImportPasswordsPromoBinding | ||
import com.duckduckgo.autofill.impl.importing.promo.ImportInPasswordsPromotionViewModel.Command | ||
import com.duckduckgo.autofill.impl.importing.promo.ImportInPasswordsPromotionViewModel.Command.DismissImport | ||
import com.duckduckgo.common.ui.view.MessageCta.Message | ||
import com.duckduckgo.common.ui.view.MessageCta.MessageType.REMOTE_MESSAGE | ||
import com.duckduckgo.common.ui.view.show | ||
import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
import com.duckduckgo.common.utils.ConflatedJob | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.common.utils.ViewViewModelFactory | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.di.scopes.ViewScope | ||
import com.duckduckgo.navigation.api.GlobalActivityStarter | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.android.support.AndroidSupportInjection | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import logcat.logcat | ||
|
||
@ContributesMultibinding(scope = AppScope::class) | ||
@PriorityKey(PRIORITY_KEY_IMPORT_PROMO) | ||
class ImportInPasswordsPromotion @Inject constructor( | ||
private val importInPasswordsVisibility: ImportInPasswordsVisibility, | ||
) : PasswordsScreenPromotionPlugin { | ||
|
||
override suspend fun getView( | ||
context: Context, | ||
numberSavedPasswords: Int, | ||
): View? { | ||
if (importInPasswordsVisibility.canShowImportInPasswords(numberSavedPasswords).not()) return null | ||
logcat { "Autofill: returning view for ImportInPasswordsPromotion" } | ||
return ImportInPasswordsPromotionView(context) | ||
} | ||
} | ||
|
||
@InjectWith(ViewScope::class) | ||
class ImportInPasswordsPromotionView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0, | ||
) : FrameLayout(context, attrs, defStyle) { | ||
|
||
@Inject | ||
lateinit var viewModelFactory: ViewViewModelFactory | ||
|
||
@Inject | ||
lateinit var globalActivityStarter: GlobalActivityStarter | ||
|
||
@Inject | ||
lateinit var dispatchers: DispatcherProvider | ||
|
||
private val binding: ViewImportPasswordsPromoBinding by viewBinding() | ||
|
||
private val viewModel: ImportInPasswordsPromotionViewModel by lazy { | ||
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[ImportInPasswordsPromotionViewModel::class.java] | ||
} | ||
|
||
private var job: ConflatedJob = ConflatedJob() | ||
|
||
override fun onAttachedToWindow() { | ||
AndroidSupportInjection.inject(this) | ||
super.onAttachedToWindow() | ||
|
||
job += viewModel.commands() | ||
.onEach { processCommand(it) } | ||
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!) | ||
|
||
showPromo() | ||
viewModel.onPromoShown() | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
job.cancel() | ||
} | ||
|
||
private fun processCommand(command: Command) { | ||
when (command) { | ||
DismissImport -> notifyPromoDismissed() | ||
} | ||
} | ||
|
||
private fun notifyPromoDismissed() { | ||
(context as? Callback)?.onPromotionDismissed() | ||
} | ||
|
||
private fun showPromo() { | ||
with(binding.importPromo) { | ||
setMessage( | ||
Message( | ||
topAnimation = R.raw.anim_password_keys, | ||
title = context.getString(R.string.passwords_import_promo_title), | ||
subtitle = context.getString(R.string.passwords_import_promo_subtitle), | ||
action = context.getString(R.string.passwords_import_promo_action), | ||
messageType = REMOTE_MESSAGE, | ||
), | ||
) | ||
onTopAnimationConfigured { view -> | ||
view.repeatCount = 1 | ||
view.playAnimation() | ||
} | ||
onPrimaryActionClicked { | ||
viewModel.onUserClickedToImport() | ||
} | ||
onCloseButtonClicked { | ||
viewModel.onUserDismissedPromo() | ||
} | ||
show() | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../java/com/duckduckgo/autofill/impl/importing/promo/ImportInPasswordsPromotionViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.autofill.impl.importing.promo | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.duckduckgo.anvil.annotations.ContributesViewModel | ||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.autofill.impl.importing.AutofillImportLaunchSource | ||
import com.duckduckgo.autofill.impl.importing.promo.ImportInPasswordsPromotionViewModel.Command.DismissImport | ||
import com.duckduckgo.autofill.impl.pixel.AutofillPixelNames | ||
import com.duckduckgo.autofill.impl.pixel.AutofillPixelNames.AUTOFILL_IMPORT_GOOGLE_PASSWORDS_EMPTY_STATE_CTA_BUTTON_TAPPED | ||
import com.duckduckgo.autofill.impl.store.AutofillEffect | ||
import com.duckduckgo.autofill.impl.store.AutofillEffectDispatcher | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.ViewScope | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.receiveAsFlow | ||
import kotlinx.coroutines.launch | ||
|
||
@ContributesViewModel(ViewScope::class) | ||
class ImportInPasswordsPromotionViewModel @Inject constructor( | ||
private val pixel: Pixel, | ||
private val dispatchers: DispatcherProvider, | ||
private val promoEventDispatcher: AutofillEffectDispatcher, | ||
private val importInPasswordsVisibility: ImportInPasswordsVisibility, | ||
) : ViewModel() { | ||
|
||
sealed interface Command { | ||
data object DismissImport : Command | ||
} | ||
|
||
private val command = Channel<Command>(1, DROP_OLDEST) | ||
internal fun commands(): Flow<Command> = command.receiveAsFlow() | ||
|
||
// want to ensure this pixel doesn't trigger repeatedly as it's scrolled in and out of the list | ||
private var promoDisplayedPixelSent = false | ||
|
||
fun onPromoShown() { | ||
if (!promoDisplayedPixelSent) { | ||
promoDisplayedPixelSent = true | ||
val params = mapOf("source" to AutofillImportLaunchSource.PasswordManagementPromo.value) | ||
pixel.fire(AutofillPixelNames.AUTOFILL_IMPORT_GOOGLE_PASSWORDS_EMPTY_STATE_CTA_BUTTON_SHOWN, params) | ||
CDRussell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
fun onUserClickedToImport() { | ||
viewModelScope.launch(dispatchers.io()) { | ||
promoEventDispatcher.emit( | ||
AutofillEffect.LaunchImportPasswords( | ||
source = AutofillImportLaunchSource.PasswordManagementPromo, | ||
), | ||
) | ||
val params = mapOf("source" to AutofillImportLaunchSource.PasswordManagementPromo.value) | ||
pixel.fire(AUTOFILL_IMPORT_GOOGLE_PASSWORDS_EMPTY_STATE_CTA_BUTTON_TAPPED, params) | ||
CDRussell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
fun onUserDismissedPromo() { | ||
viewModelScope.launch(dispatchers.io()) { | ||
importInPasswordsVisibility.onPromoDismissed() | ||
command.send(DismissImport) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.