Skip to content

Commit

Permalink
Merge branch 'feature/ondrej/swiping-tabs' into feature/ondrej/swipin…
Browse files Browse the repository at this point in the history
…g-tabs-pixels

# Conflicts:
#	app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
#	app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt
#	app/src/main/java/com/duckduckgo/app/browser/tabs/DefaultTabManager.kt
#	app/src/main/java/com/duckduckgo/app/browser/tabs/adapter/TabPagerAdapter.kt
#	app/src/test/java/com/duckduckgo/app/browser/BrowserViewModelTest.kt
  • Loading branch information
0nko committed Dec 20, 2024
2 parents 7b3e155 + 2ee109f commit f5058fd
Show file tree
Hide file tree
Showing 256 changed files with 3,365 additions and 38,014 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/action-pr-approved.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/pr-review-notifications.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Pull Request Reviewed -> Asana Sync
name: Pull Request Reviewed -> Sync With Asana

on:
pull_request_review:
types: [submitted]

jobs:
pr-reviewed:
name: Update Asana task -> PR reviewed
uses: duckduckgo/native-github-asana-sync/.github/workflows/pr-review-notifications.yml@david/improve-pr-notifications
name: Add PR reviewed comment
uses: duckduckgo/native-github-asana-sync/.github/workflows/pr-review-notifications.yml@v1.4.1
with:
trigger-phrase: "Task/Issue URL:"
secrets:
Expand Down
11 changes: 11 additions & 0 deletions app/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7679,4 +7679,15 @@
column="9"/>
</issue>

<issue
id="InvalidColorAttribute"
message="@colors are not allowed, used ?attr/daxColor instead"
errorLine1=" android:textColor=&quot;@color/blue50&quot;"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/layout/view_menu_item_default_browser.xml"
line="35"
column="13"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
"requestType": "script",
"expectAction": "ignore"
},
{
"name": "same party ignore with deeper subdomain",
"siteURL": "https://bad.etld-plus-two.site/",
"requestURL": "https://bad.etld-plus-two.site/script.js",
"requestType": "script",
"expectAction": "ignore"
},
{
"name": "tracker loads ignore",
"siteURL": "https://bad.third-party.site/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@
"rules": [],
"default": "ignore"
},
"bad.etld-plus-two.site": {
"domain": "bad.etld-plus-two.site",
"owner": {
"name": "Test Site for Tracker Blocking With eTLD+2",
"displayName": "Bad Third Party Site eTLD+2",
"privacyPolicy": "",
"url": "http://bad.etld-plus-two.site"
},
"prevalence": 0.1,
"fingerprinting": 3,
"cookies": 0.1,
"categories": [],
"default": "block",
"rules": []
},
"tracker.test": {
"domain": "tracker.test",
"owner": {
Expand Down Expand Up @@ -819,6 +834,13 @@
"prevalence": 0.1,
"displayName": "Test Site for Tracker Blocking"
},
"Test Site for Tracker Blocking With eTLD+2": {
"domains": [
"bad.etld-plus-two.site"
],
"prevalence": 0.1,
"displayName": "Bad Third Party Site eTLD+2"
},
"Tests for formatting": {
"domains": [
"format.test"
Expand Down Expand Up @@ -876,6 +898,7 @@
"bad.third-party.site": "Test Site for Tracker Blocking",
"sometimes-bad.third-party.site": "Test Site for Tracker Blocking",
"broken.third-party.site": "Test Site for Tracker Blocking",
"bad.etld-plus-two.site": "Test Site for Tracker Blocking With eTLD+2",
"format.test": "Tests for formatting",
"third-party.site": "Test Site for Tracker Blocking",
"tracker.test": "Test Site for Tracker Blocking",
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.VisibleForTesting
import androidx.core.view.isVisible
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.MarginPageTransformer
Expand Down Expand Up @@ -186,7 +187,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
wasSwipingStarted = false

viewModel.onTabsSwiped()
tabManager.tabPagerAdapter.onPageChanged(position)
tabManager.onTabPageSwiped(position)
}
}

Expand Down Expand Up @@ -234,6 +235,9 @@ open class BrowserActivity : DuckDuckGoActivity() {
}

setContentView(binding.root)

initializeTabs()

viewModel.viewState.observe(this) {
renderer.renderBrowserViewState(it)
}
Expand Down Expand Up @@ -420,7 +424,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
val existingTabId = intent.getStringExtra(OPEN_EXISTING_TAB_ID_EXTRA)
if (existingTabId != null) {
if (swipingTabsFeature.isEnabled) {
tabManager.openExistingTab(existingTabId)
tabManager.switchToTab(existingTabId)
} else {
openExistingTab(existingTabId)
}
Expand All @@ -442,7 +446,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
} else {
Timber.w("can't use current tab, opening in new tab instead")
if (swipingTabsFeature.isEnabled) {
tabManager.openInNewTab(query = sharedText, skipHome = true)
tabManager.launchNewTab(query = sharedText, skipHome = true)
} else {
lifecycleScope.launch { viewModel.onOpenInNewTabRequested(query = sharedText, skipHome = true) }
}
Expand All @@ -459,7 +463,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
val sourceTabId = if (selectedText) currentTab?.tabId else null
val skipHome = !selectedText
if (swipingTabsFeature.isEnabled) {
tabManager.openInNewTab(sourceTabId = sourceTabId, query = sharedText, skipHome = skipHome)
tabManager.launchNewTab(sourceTabId = sourceTabId, query = sharedText, skipHome = skipHome)
} else {
lifecycleScope.launch { viewModel.onOpenInNewTabRequested(sourceTabId = sourceTabId, query = sharedText, skipHome = skipHome) }
}
Expand All @@ -480,7 +484,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
if (swipingTabsFeature.isEnabled) {
lifecycleScope.launch {
viewModel.tabsFlow.flowWithLifecycle(lifecycle).collectLatest {
tabManager.onTabsUpdated(it)
tabManager.onTabsChanged(it)
}
}

Expand Down Expand Up @@ -562,8 +566,8 @@ open class BrowserActivity : DuckDuckGoActivity() {
is Command.ShowAppRatingPrompt -> showAppRatingDialog(command.promptCount)
is Command.ShowAppFeedbackPrompt -> showGiveFeedbackDialog(command.promptCount)
is Command.LaunchFeedbackView -> startActivity(FeedbackActivity.intent(this))
is Command.SwitchToTab -> tabManager.openExistingTab(command.tabId)
is Command.OpenInNewTab -> tabManager.openInNewTab(command.url)
is Command.SwitchToTab -> tabManager.switchToTab(command.tabId)
is Command.OpenInNewTab -> tabManager.launchNewTab(command.url)
is Command.OpenSavedSite -> currentTab?.submitQuery(command.url)
}
}
Expand Down Expand Up @@ -777,19 +781,15 @@ open class BrowserActivity : DuckDuckGoActivity() {
}
}

@SuppressLint("ClickableViewAccessibility", "WrongConstant")
private fun initializeTabs() {
if (swipingTabsFeature.isEnabled) {
tabPager.adapter = tabManager.tabPagerAdapter
tabPager.registerOnPageChangeCallback(onTabPageChangeListener)
tabPager.setPageTransformer(MarginPageTransformer(resources.getDimension(com.duckduckgo.mobile.android.R.dimen.keyline_2).toPx().toInt()))

binding.fragmentContainer.gone()
tabPager.show()
} else {
binding.fragmentContainer.show()
tabPager.gone()
}

binding.fragmentContainer.isVisible = !swipingTabsFeature.isEnabled
tabPager.isVisible = swipingTabsFeature.isEnabled
}

private val Intent.launchedFromRecents: Boolean
Expand Down
30 changes: 17 additions & 13 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,9 @@ class BrowserTabFragment :
}
}

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

omnibar = Omnibar(settingsDataStore.omnibarPosition, changeOmnibarPositionFeature.refactor().isEnabled(), binding)

webViewContainer = binding.webViewContainer
Expand Down Expand Up @@ -1076,6 +1075,9 @@ class BrowserTabFragment :
onMenuItemClicked(changeBrowserModeMenuItem) {
viewModel.onChangeBrowserModeClicked()
}
onMenuItemClicked(defaultBrowserMenuItem) {
viewModel.onSetDefaultBrowserSelected()
}
onMenuItemClicked(sharePageMenuItem) {
pixel.fire(AppPixelName.MENU_ACTION_SHARE_PRESSED)
viewModel.onShareSelected()
Expand Down Expand Up @@ -1530,7 +1532,7 @@ class BrowserTabFragment :
is NavigationCommand.Refresh -> refresh()
is Command.OpenInNewTab -> {
if (swipingTabsFeature.isEnabled) {
requireBrowserActivity().tabManager.openInNewTab(it.query, it.sourceTabId)
requireBrowserActivity().tabManager.launchNewTab(it.query, it.sourceTabId)
} else {
browserActivity?.openInNewTab(it.query, it.sourceTabId)
}
Expand Down Expand Up @@ -1808,7 +1810,7 @@ class BrowserTabFragment :
binding.autoCompleteSuggestionsList.gone()

if (swipingTabsFeature.isEnabled) {
requireBrowserActivity().tabManager.openExistingTab(it.tabId)
requireBrowserActivity().tabManager.switchToTab(it.tabId)
} else {
browserActivity?.openExistingTab(it.tabId)
}
Expand Down Expand Up @@ -3017,15 +3019,17 @@ class BrowserTabFragment :
}

override fun onContextItemSelected(item: MenuItem): Boolean {
runCatching {
webView?.safeHitTestResult?.let {
val target = getLongPressTarget(it)
if (target != null && viewModel.userSelectedItemFromLongPressMenu(target, item)) {
return true
if (this.isResumed) {
runCatching {
webView?.safeHitTestResult?.let {
val target = getLongPressTarget(it)
if (target != null && viewModel.userSelectedItemFromLongPressMenu(target, item)) {
return true
}
}
}.onFailure { exception ->
Timber.e(exception, "Failed to get HitTestResult")
}
}.onFailure { exception ->
Timber.e(exception, "Failed to get HitTestResult")
}
return super.onContextItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun onSetDefaultBrowserSelected() {
// no-op, to be implemented
}

fun onShareSelected() {
url?.let {
viewModelScope.launch(dispatchers.io()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class BrowserPopupMenu(
}
}

internal val defaultBrowserMenuItem: View by lazy {
when (omnibarPosition) {
TOP -> topBinding.includeDefaultBrowserMenuItem.defaultBrowserMenuItem
BOTTOM -> bottomBinding.includeDefaultBrowserMenuItem.defaultBrowserMenuItem
}
}

internal val sharePageMenuItem: View by lazy {
when (omnibarPosition) {
TOP -> topBinding.sharePageMenuItem
Expand Down Expand Up @@ -240,6 +247,8 @@ class BrowserPopupMenu(
newTabMenuItem.isVisible = browserShowing && !displayedInCustomTabScreen
sharePageMenuItem.isVisible = viewState.canSharePage

defaultBrowserMenuItem.isVisible = viewState.showSelectDefaultBrowserMenuItem

bookmarksMenuItem.isVisible = !displayedInCustomTabScreen
downloadsMenuItem.isVisible = !displayedInCustomTabScreen
settingsMenuItem.isVisible = !displayedInCustomTabScreen
Expand Down
Loading

0 comments on commit f5058fd

Please sign in to comment.