-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new screens with instructions for importing passwords via sync
- Loading branch information
Showing
18 changed files
with
1,037 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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
79 changes: 79 additions & 0 deletions
79
...ckduckgo/autofill/impl/ui/credential/management/importpassword/ImportPasswordsActivity.kt
This file contains 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,79 @@ | ||
/* | ||
* Copyright (c) 2024 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.ui.credential.management.importpassword | ||
|
||
import android.os.Bundle | ||
import androidx.annotation.StringRes | ||
import com.duckduckgo.anvil.annotations.ContributeToActivityStarter | ||
import com.duckduckgo.anvil.annotations.InjectWith | ||
import com.duckduckgo.autofill.impl.R | ||
import com.duckduckgo.autofill.impl.databinding.ActivityImportPasswordsBinding | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.GetDesktopAppParams | ||
import com.duckduckgo.common.ui.DuckDuckGoActivity | ||
import com.duckduckgo.common.ui.view.text.DaxTextView | ||
import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
import com.duckduckgo.common.utils.extensions.html | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import com.duckduckgo.navigation.api.GlobalActivityStarter | ||
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams | ||
import com.duckduckgo.sync.api.SyncActivityWithEmptyParams | ||
import javax.inject.Inject | ||
|
||
@InjectWith(ActivityScope::class) | ||
@ContributeToActivityStarter(ImportPasswordActivityParams::class) | ||
class ImportPasswordsActivity : DuckDuckGoActivity() { | ||
|
||
val binding: ActivityImportPasswordsBinding by viewBinding() | ||
|
||
@Inject | ||
lateinit var globalActivityStarter: GlobalActivityStarter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(binding.root) | ||
setupToolbar(binding.includeToolbar.toolbar) | ||
configureEventHandlers() | ||
configureNumberedInstructions() | ||
} | ||
|
||
private fun configureEventHandlers() { | ||
binding.getDesktopBrowserButton.setOnClickListener { | ||
globalActivityStarter.start(this, GetDesktopAppParams) | ||
} | ||
binding.syncWithDesktopButton.setOnClickListener { | ||
globalActivityStarter.start(this, SyncActivityWithEmptyParams) | ||
} | ||
} | ||
|
||
private fun configureNumberedInstructions() { | ||
with(binding) { | ||
importFromDesktopInstructions1.applyHtml(R.string.autofillManagementImportPasswordsImportFromDesktopInstructionOne) | ||
importFromDesktopInstructions2.applyHtml(R.string.autofillManagementImportPasswordsImportFromDesktopInstructionTwo) | ||
importFromDesktopInstructions3.applyHtml(R.string.autofillManagementImportPasswordsImportFromDesktopInstructionThree) | ||
importFromDesktopInstructions4.applyHtml(R.string.autofillManagementImportPasswordsImportFromDesktopInstructionFour) | ||
} | ||
} | ||
|
||
private fun DaxTextView.applyHtml(@StringRes resId: Int) { | ||
text = getString(resId).html(this@ImportPasswordsActivity) | ||
} | ||
} | ||
|
||
data object ImportPasswordActivityParams : ActivityParams { | ||
private fun readResolve(): Any = ImportPasswordActivityParams | ||
} |
110 changes: 110 additions & 0 deletions
110
...i/credential/management/importpassword/desktopapp/ImportPasswordsGetDesktopAppActivity.kt
This file contains 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,110 @@ | ||
/* | ||
* Copyright (c) 2023 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.ui.credential.management.importpassword.desktopapp | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.ActivityNotFoundException | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.duckduckgo.anvil.annotations.ContributeToActivityStarter | ||
import com.duckduckgo.anvil.annotations.InjectWith | ||
import com.duckduckgo.autofill.impl.R | ||
import com.duckduckgo.autofill.impl.databinding.ActivityGetDesktopAppBinding | ||
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillClipboardInteractor | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.ImportPasswordsGetDesktopAppViewModel.Command | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.ImportPasswordsGetDesktopAppViewModel.Command.ShareLink | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.ImportPasswordsGetDesktopAppViewModel.Command.ShowCopiedNotification | ||
import com.duckduckgo.common.ui.DuckDuckGoActivity | ||
import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import com.duckduckgo.navigation.api.GlobalActivityStarter | ||
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams | ||
import com.google.android.material.snackbar.Snackbar | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import timber.log.Timber | ||
|
||
data object GetDesktopAppParams : ActivityParams { | ||
private fun readResolve(): Any = GetDesktopAppParams | ||
} | ||
|
||
@InjectWith(ActivityScope::class) | ||
@ContributeToActivityStarter(GetDesktopAppParams::class) | ||
class ImportPasswordsGetDesktopAppActivity : DuckDuckGoActivity() { | ||
|
||
private val viewModel: ImportPasswordsGetDesktopAppViewModel by bindViewModel() | ||
private val binding: ActivityGetDesktopAppBinding by viewBinding() | ||
|
||
@Inject | ||
lateinit var globalActivityStarter: GlobalActivityStarter | ||
|
||
@Inject | ||
lateinit var clipboardInteractor: AutofillClipboardInteractor | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
viewModel.commands.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) | ||
.onEach { executeCommand(it) } | ||
.launchIn(lifecycleScope) | ||
|
||
setContentView(binding.root) | ||
setupToolbar(binding.includeToolbar.toolbar) | ||
configureUiEventHandlers() | ||
} | ||
|
||
private fun configureUiEventHandlers() { | ||
binding.shareLinkButton.setOnClickListener { | ||
viewModel.onShareClicked() | ||
} | ||
binding.downloadLinkText.setOnClickListener { | ||
viewModel.onLinkClicked() | ||
} | ||
} | ||
|
||
private fun executeCommand(command: Command) { | ||
when (command) { | ||
is ShareLink -> launchSharePageChooser(command.link) | ||
is ShowCopiedNotification -> showCopiedNotification() | ||
} | ||
} | ||
|
||
private fun showCopiedNotification() { | ||
Snackbar.make(binding.root, R.string.autofillManagementImportPasswordsGetDesktopBrowserLinkCopied, Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
@SuppressLint("UnspecifiedImmutableFlag") | ||
private fun launchSharePageChooser(link: String) { | ||
val share = Intent(Intent.ACTION_SEND).apply { | ||
type = "text/plain" | ||
val message = getString(R.string.autofillManagementImportPasswordsGetDesktopBrowserIntentMessage, link) | ||
putExtra(Intent.EXTRA_TEXT, message) | ||
putExtra(Intent.EXTRA_TITLE, getString(R.string.autofillManagementImportPasswordsGetDesktopBrowserIntentTitle)) | ||
} | ||
|
||
try { | ||
startActivity(Intent.createChooser(share, null)) | ||
} catch (e: ActivityNotFoundException) { | ||
Timber.w(e, "Activity not found") | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
.../credential/management/importpassword/desktopapp/ImportPasswordsGetDesktopAppViewModel.kt
This file contains 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,75 @@ | ||
/* | ||
* Copyright (c) 2023 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.ui.credential.management.importpassword.desktopapp | ||
|
||
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.ui.credential.management.AutofillClipboardInteractor | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.ImportPasswordsGetDesktopAppViewModel.Command.ShareLink | ||
import com.duckduckgo.autofill.impl.ui.credential.management.importpassword.desktopapp.ImportPasswordsGetDesktopAppViewModel.Command.ShowCopiedNotification | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.channels.BufferOverflow | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.receiveAsFlow | ||
import kotlinx.coroutines.launch | ||
|
||
@ContributesViewModel(AppScope::class) | ||
class ImportPasswordsGetDesktopAppViewModel @Inject constructor( | ||
private val pixel: Pixel, | ||
private val dispatchers: DispatcherProvider, | ||
private val autofillClipboardInteractor: AutofillClipboardInteractor, | ||
) : ViewModel() { | ||
|
||
private val commandChannel = Channel<Command>(capacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) | ||
val commands = commandChannel.receiveAsFlow() | ||
|
||
sealed class Command { | ||
data class ShareLink(val link: String) : Command() | ||
data object ShowCopiedNotification : Command() | ||
} | ||
|
||
data class ViewState(val windowsFeatureEnabled: Boolean) | ||
|
||
fun onShareClicked() { | ||
viewModelScope.launch { | ||
commandChannel.send(ShareLink(buildLink())) | ||
} | ||
} | ||
|
||
fun onLinkClicked() { | ||
viewModelScope.launch(dispatchers.io()) { | ||
autofillClipboardInteractor.copyToClipboard(buildLink(), isSensitive = false) | ||
|
||
if (autofillClipboardInteractor.shouldShowCopyNotification()) { | ||
commandChannel.send(ShowCopiedNotification) | ||
} | ||
} | ||
} | ||
|
||
private fun buildLink(): String { | ||
return "$BASE_LINK?$ATTRIBUTION" | ||
} | ||
|
||
companion object { | ||
private const val BASE_LINK = "https://duckduckgo.com/browser" | ||
private const val ATTRIBUTION = "origin=funnel_browser_android_sync" | ||
} | ||
} |
Oops, something went wrong.