Skip to content

Commit 566d0e5

Browse files
committed
Add UI for importing bookmarks from Google
1 parent a8e4b48 commit 566d0e5

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.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(
@@ -261,6 +273,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
261273
sealed interface ViewState {
262274
data object Initializing : ViewState
263275
data object ShowWebPage : ViewState
276+
data object HideWebPage : ViewState
264277
data class LoadingWebPage(val url: String) : ViewState
265278
data class UserCancelledImportFlow(val stage: String) : ViewState
266279
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
@@ -42,6 +43,50 @@ class ImportGoogleBookmarksWebFlowViewModelTest {
4243
bookmarkImportConfigStore = mock(),
4344
)
4445

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

0 commit comments

Comments
 (0)