Skip to content

Commit 2575f8d

Browse files
committed
Add UI for importing bookmarks from Google
1 parent 8393d44 commit 2575f8d

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
@@ -53,6 +53,7 @@ import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookma
5353
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.InjectCredentialsFromReauth
5454
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.NoCredentialsAvailable
5555
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.PromptUserToSelectFromStoredCredentials
56+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
5657
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.Initializing
5758
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.LoadingWebPage
5859
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.NavigatingBack
@@ -64,6 +65,8 @@ import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubTy
6465
import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubType.PASSWORD
6566
import com.duckduckgo.autofill.impl.store.ReAuthenticationDetails
6667
import com.duckduckgo.common.ui.DuckDuckGoFragment
68+
import com.duckduckgo.common.ui.view.hide
69+
import com.duckduckgo.common.ui.view.show
6770
import com.duckduckgo.common.utils.DispatcherProvider
6871
import com.duckduckgo.common.utils.FragmentViewModelFactory
6972
import com.duckduckgo.common.utils.plugins.PluginPoint
@@ -174,7 +177,14 @@ class ImportGoogleBookmarksWebFlowFragment :
174177
is LoadingWebPage -> loadFirstWebpage(viewState.url)
175178
is NavigatingBack -> binding?.webView?.goBack()
176179
is Initializing -> {}
177-
is ShowWebPage -> {}
180+
is ShowWebPage -> {
181+
binding?.webView?.show()
182+
logcat { "cdr showing webview ${Thread.currentThread().name}" }
183+
}
184+
is HideWebPage -> {
185+
binding?.webView?.hide()
186+
logcat { "cdr hiding webview ${Thread.currentThread().name}" }
187+
}
178188
}
179189
}.launchIn(lifecycleScope)
180190
}
@@ -327,6 +337,7 @@ class ImportGoogleBookmarksWebFlowFragment :
327337
private fun getToolbar() = (activity as ImportGoogleBookmarksWebFlowActivity).binding.includeToolbar.toolbar
328338

329339
override fun onPageStarted(url: String?) {
340+
viewModel.onPageStarted(url)
330341
lifecycleScope.launch(dispatchers.main()) {
331342
binding?.let {
332343
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.BookmarkImportProcessor
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.store.ReAuthenticationDetails
2831
import com.duckduckgo.autofill.impl.store.ReauthenticationHandler
2932
import com.duckduckgo.common.utils.DispatcherProvider
@@ -146,7 +149,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
146149
}
147150

148151
fun firstPageLoading() {
149-
_viewState.value = ViewState.ShowWebPage
152+
_viewState.value = ShowWebPage
150153
}
151154

152155
suspend fun getReauthData(originalUrl: String): ReAuthenticationDetails? =
@@ -217,6 +220,15 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
217220
reauthenticationHandler.storeForReauthentication(currentUrl, credentials.password)
218221
}
219222

223+
fun onPageStarted(url: String?) {
224+
val host = url?.toUri()?.host ?: return
225+
_viewState.value = if (host.contains("takeout.google.com", ignoreCase = true)) {
226+
HideWebPage
227+
} else {
228+
ShowWebPage
229+
}
230+
}
231+
220232
sealed interface Command {
221233
data class InjectCredentialsFromReauth(
222234
val url: String? = null,
@@ -245,6 +257,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
245257
data object Initializing : ViewState
246258

247259
data object ShowWebPage : ViewState
260+
data object HideWebPage : ViewState
248261

249262
data class LoadingWebPage(
250263
val url: String,

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
@@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
44
import app.cash.turbine.test
55
import com.duckduckgo.autofill.impl.importing.takeout.processor.BookmarkImportProcessor
66
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command
7+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
78
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.NavigatingBack
89
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.ShowWebPage
910
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.UserCancelledImportFlow
@@ -35,6 +36,50 @@ class ImportGoogleBookmarksWebFlowViewModelTest {
3536
bookmarkImportConfigStore = mock(),
3637
)
3738

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

0 commit comments

Comments
 (0)