Skip to content

Commit 7f7ff4b

Browse files
committed
Add UI for importing bookmarks from Google
1 parent e890ed7 commit 7f7ff4b

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/importing/takeout/webflow/ImportGoogleBookmarksWebFlowFragment.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookma
5555
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.NoCredentialsAvailable
5656
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.ProcessDownloadedZipData
5757
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.PromptUserToSelectFromStoredCredentials
58+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
5859
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.Initializing
5960
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.LoadingWebPage
6061
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.NavigatingBack
@@ -66,6 +67,8 @@ import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubTy
6667
import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubType.PASSWORD
6768
import com.duckduckgo.autofill.impl.store.ReAuthenticationDetails
6869
import com.duckduckgo.common.ui.DuckDuckGoFragment
70+
import com.duckduckgo.common.ui.view.hide
71+
import com.duckduckgo.common.ui.view.show
6972
import com.duckduckgo.common.utils.DispatcherProvider
7073
import com.duckduckgo.common.utils.FragmentViewModelFactory
7174
import com.duckduckgo.common.utils.plugins.PluginPoint
@@ -177,7 +180,14 @@ class ImportGoogleBookmarksWebFlowFragment :
177180
is LoadingWebPage -> loadFirstWebpage(viewState.url)
178181
is NavigatingBack -> binding?.webView?.goBack()
179182
is Initializing -> {}
180-
is ShowWebPage -> {}
183+
is ShowWebPage -> {
184+
binding?.webView?.show()
185+
logcat { "cdr showing webview ${Thread.currentThread().name}" }
186+
}
187+
is HideWebPage -> {
188+
binding?.webView?.hide()
189+
logcat { "cdr hiding webview ${Thread.currentThread().name}" }
190+
}
181191
}
182192
}.launchIn(lifecycleScope)
183193
}
@@ -338,6 +348,7 @@ class ImportGoogleBookmarksWebFlowFragment :
338348
private fun getToolbar() = (activity as ImportGoogleBookmarksWebFlowActivity).binding.includeToolbar.toolbar
339349

340350
override fun onPageStarted(url: String?) {
351+
viewModel.onPageStarted(url)
341352
lifecycleScope.launch(dispatchers.main()) {
342353
binding?.let {
343354
val reauthDetails = url?.let { viewModel.getReauthData(url) } ?: ReAuthenticationDetails()

autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/importing/takeout/webflow/ImportGoogleBookmarksWebFlowViewModel.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.duckduckgo.autofill.impl.importing.takeout.webflow
1818

19+
import androidx.core.net.toUri
1920
import androidx.lifecycle.ViewModel
2021
import androidx.lifecycle.viewModelScope
2122
import com.duckduckgo.anvil.annotations.ContributesViewModel
@@ -24,6 +25,8 @@ import com.duckduckgo.autofill.api.domain.app.LoginCredentials
2425
import com.duckduckgo.autofill.api.domain.app.LoginTriggerType
2526
import com.duckduckgo.autofill.impl.importing.takeout.processor.TakeoutBookmarkImporter
2627
import com.duckduckgo.autofill.impl.importing.takeout.store.BookmarkImportConfigStore
28+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
29+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.ShowWebPage
2730
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutBookmarkExtractor
2831
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutBookmarkExtractor.ExtractionResult
2932
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutZipDownloader
@@ -179,7 +182,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
179182
}
180183

181184
fun firstPageLoading() {
182-
_viewState.value = ViewState.ShowWebPage
185+
_viewState.value = ShowWebPage
183186
}
184187

185188
suspend fun getReauthData(originalUrl: String): ReAuthenticationDetails? {
@@ -246,6 +249,15 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
246249
reauthenticationHandler.storeForReauthentication(currentUrl, credentials.password)
247250
}
248251

252+
fun onPageStarted(url: String?) {
253+
val host = url?.toUri()?.host ?: return
254+
_viewState.value = if (host.contains("takeout.google.com", ignoreCase = true)) {
255+
HideWebPage
256+
} else {
257+
ShowWebPage
258+
}
259+
}
260+
249261
sealed interface Command {
250262
data class InjectCredentialsFromReauth(val url: String? = null, val username: String = "", val password: String?) : Command
251263
data class PromptUserToSelectFromStoredCredentials(
@@ -272,6 +284,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
272284
sealed interface ViewState {
273285
data object Initializing : ViewState
274286
data object ShowWebPage : ViewState
287+
data object HideWebPage : ViewState
275288
data class LoadingWebPage(val url: String) : ViewState
276289
data class UserCancelledImportFlow(val stage: String) : ViewState
277290
data class UserFinishedCannotImport(val reason: UserCannotImportReason) : ViewState

autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/importing/takeout/webflow/ImportGoogleBookmarksWebFlowViewModelTest.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.duckduckgo.autofill.impl.importing.takeout.webflow
33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import app.cash.turbine.test
55
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command
6+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
67
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.NavigatingBack
78
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.ShowWebPage
89
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.UserCancelledImportFlow
@@ -38,6 +39,50 @@ class ImportGoogleBookmarksWebFlowViewModelTest {
3839
bookmarkImportConfigStore = mock(),
3940
)
4041

42+
@Test
43+
fun whenOnPageStartedWithTakeoutUrlThenHideWebPage() = runTest {
44+
testee.onPageStarted("https://takeout.google.com")
45+
assertEquals(HideWebPage, testee.viewState.value)
46+
}
47+
48+
@Test
49+
fun whenOnPageStartedWithUppercaseTakeoutUrlThenHideWebPage() = runTest {
50+
testee.onPageStarted("https://TAKEOUT.GOOGLE.COM")
51+
assertEquals(HideWebPage, testee.viewState.value)
52+
}
53+
54+
@Test
55+
fun whenOnPageStartedWithAccountsGoogleUrlThenShowWebPage() = runTest {
56+
testee.onPageStarted("https://accounts.google.com/signin")
57+
assertEquals(ShowWebPage, testee.viewState.value)
58+
}
59+
60+
@Test
61+
fun whenOnPageStartedWithExampleUrlThenShowWebPage() = runTest {
62+
testee.onPageStarted("https://example.com/page")
63+
assertEquals(ShowWebPage, testee.viewState.value)
64+
}
65+
66+
@Test
67+
fun whenOnPageStartedWithAccountsGoogleUrlContainingTakeoutInPathThenShowWebPage() = runTest {
68+
testee.onPageStarted("https://accounts.google.com/signin?continue=https://takeout.google.com")
69+
assertEquals(ShowWebPage, testee.viewState.value)
70+
}
71+
72+
@Test
73+
fun whenOnPageStartedWithNullUrlThenViewStateRemainsUnchanged() = runTest {
74+
val initialState = testee.viewState.value
75+
testee.onPageStarted(null)
76+
assertEquals(initialState, testee.viewState.value)
77+
}
78+
79+
@Test
80+
fun whenOnPageStartedWithMalformedUrlThenViewStateRemainsUnchanged() = runTest {
81+
val initialState = testee.viewState.value
82+
testee.onPageStarted("not-a-valid-url")
83+
assertEquals(initialState, testee.viewState.value)
84+
}
85+
4186
@Test
4287
fun whenFirstPageLoadingThenShowWebPageState() = runTest {
4388
testee.firstPageLoading()

0 commit comments

Comments
 (0)