Skip to content

Commit cb2b5cb

Browse files
committed
Add UI for importing bookmarks from Google
1 parent 4614087 commit cb2b5cb

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
@@ -17,6 +17,7 @@
1717
package com.duckduckgo.autofill.impl.importing.takeout.webflow
1818

1919
import android.os.Parcelable
20+
import androidx.core.net.toUri
2021
import androidx.lifecycle.ViewModel
2122
import androidx.lifecycle.viewModelScope
2223
import com.duckduckgo.anvil.annotations.ContributesViewModel
@@ -25,6 +26,8 @@ import com.duckduckgo.autofill.api.domain.app.LoginCredentials
2526
import com.duckduckgo.autofill.api.domain.app.LoginTriggerType
2627
import com.duckduckgo.autofill.impl.importing.takeout.processor.TakeoutBookmarkImporter
2728
import com.duckduckgo.autofill.impl.importing.takeout.store.BookmarkImportConfigStore
29+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.HideWebPage
30+
import com.duckduckgo.autofill.impl.importing.takeout.webflow.ImportGoogleBookmarksWebFlowViewModel.ViewState.ShowWebPage
2831
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutBookmarkExtractor
2932
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutBookmarkExtractor.ExtractionResult
3033
import com.duckduckgo.autofill.impl.importing.takeout.zip.TakeoutZipDownloader
@@ -178,7 +181,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
178181
}
179182

180183
fun firstPageLoading() {
181-
_viewState.value = ViewState.ShowWebPage
184+
_viewState.value = ShowWebPage
182185
}
183186

184187
suspend fun getReauthData(originalUrl: String): ReAuthenticationDetails? {
@@ -245,6 +248,15 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
245248
reauthenticationHandler.storeForReauthentication(currentUrl, credentials.password)
246249
}
247250

251+
fun onPageStarted(url: String?) {
252+
val host = url?.toUri()?.host ?: return
253+
_viewState.value = if (host.contains("takeout.google.com", ignoreCase = true)) {
254+
HideWebPage
255+
} else {
256+
ShowWebPage
257+
}
258+
}
259+
248260
sealed interface Command {
249261
data class InjectCredentialsFromReauth(val url: String? = null, val username: String = "", val password: String?) : Command
250262
data class PromptUserToSelectFromStoredCredentials(
@@ -271,6 +283,7 @@ class ImportGoogleBookmarksWebFlowViewModel @Inject constructor(
271283
sealed interface ViewState {
272284
data object Initializing : ViewState
273285
data object ShowWebPage : ViewState
286+
data object HideWebPage : ViewState
274287
data class LoadingWebPage(val url: String) : ViewState
275288
data class UserCancelledImportFlow(val stage: String) : ViewState
276289
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)