Skip to content

Commit dfbcd8e

Browse files
committed
Add UI for importing bookmarks from Google
1 parent 17a6c44 commit dfbcd8e

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
@@ -56,6 +56,7 @@ import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookma
5656
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.NoCredentialsAvailable
5757
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.ProcessDownloadedZipData
5858
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.Command.PromptUserToSelectFromStoredCredentials
59+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
5960
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.Initializing
6061
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.LoadingWebPage
6162
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.NavigatingBack
@@ -67,6 +68,8 @@ import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubTy
6768
import com.duckduckgo.autofill.impl.jsbridge.request.SupportedAutofillInputSubType.PASSWORD
6869
import com.duckduckgo.autofill.impl.store.ReAuthenticationDetails
6970
import com.duckduckgo.common.ui.DuckDuckGoFragment
71+
import com.duckduckgo.common.ui.view.hide
72+
import com.duckduckgo.common.ui.view.show
7073
import com.duckduckgo.common.utils.DispatcherProvider
7174
import com.duckduckgo.common.utils.FragmentViewModelFactory
7275
import com.duckduckgo.common.utils.plugins.PluginPoint
@@ -181,7 +184,14 @@ class ImportGoogleBookmarksWebFlowFragment :
181184
is LoadingWebPage -> loadFirstWebpage(viewState.url)
182185
is NavigatingBack -> binding?.webView?.goBack()
183186
is Initializing -> {}
184-
is ShowWebPage -> {}
187+
is ShowWebPage -> {
188+
binding?.webView?.show()
189+
logcat { "cdr showing webview ${Thread.currentThread().name}" }
190+
}
191+
is HideWebPage -> {
192+
binding?.webView?.hide()
193+
logcat { "cdr hiding webview ${Thread.currentThread().name}" }
194+
}
185195
}
186196
}.launchIn(lifecycleScope)
187197
}
@@ -341,6 +351,7 @@ class ImportGoogleBookmarksWebFlowFragment :
341351
private fun getToolbar() = (activity as ImportGoogleBookmarksWebFlowActivity).binding.includeToolbar.toolbar
342352

343353
override fun onPageStarted(url: String?) {
354+
viewModel.onPageStarted(url)
344355
lifecycleScope.launch(dispatchers.main()) {
345356
binding?.let {
346357
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
@@ -183,7 +186,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
183186
}
184187

185188
fun firstPageLoading() {
186-
_viewState.value = ViewState.ShowWebPage
189+
_viewState.value = ShowWebPage
187190
}
188191

189192
suspend fun getReauthData(originalUrl: String): ReAuthenticationDetails? {
@@ -250,6 +253,15 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
250253
reauthenticationHandler.storeForReauthentication(currentUrl, credentials.password)
251254
}
252255

256+
fun onPageStarted(url: String?) {
257+
val host = url?.toUri()?.host ?: return
258+
_viewState.value = if (host.contains("takeout.google.com", ignoreCase = true)) {
259+
HideWebPage
260+
} else {
261+
ShowWebPage
262+
}
263+
}
264+
253265
sealed interface Command {
254266
data class InjectCredentialsFromReauth(val url: String? = null, val username: String = "", val password: String?) : Command
255267
data class PromptUserToSelectFromStoredCredentials(
@@ -276,6 +288,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
276288
sealed interface ViewState {
277289
data object Initializing : ViewState
278290
data object ShowWebPage : ViewState
291+
data object HideWebPage : ViewState
279292
data class LoadingWebPage(val url: String) : ViewState
280293
data class UserCancelledImportFlow(val stage: String) : ViewState
281294
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)