Skip to content

Commit 8c9b783

Browse files
committed
Add kill switch
1 parent f9b3dee commit 8c9b783

File tree

2 files changed

+68
-23
lines changed

2 files changed

+68
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.savedsites.impl.newtab
18+
19+
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
20+
import com.duckduckgo.di.scopes.AppScope
21+
import com.duckduckgo.feature.toggles.api.Toggle
22+
import com.duckduckgo.feature.toggles.api.Toggle.DefaultFeatureValue
23+
24+
@ContributesRemoteFeature(
25+
scope = AppScope::class,
26+
featureName = "favoritesSwipeHandling",
27+
)
28+
interface FavoritesSwipeHandling {
29+
/**
30+
* Kill switch for intercepting touch events in Favorites section to allow swiping
31+
* If disabled remotely, the interception will not be requested
32+
* Defaults to `true`
33+
*/
34+
@Toggle.DefaultValue(DefaultFeatureValue.TRUE)
35+
fun self(): Toggle
36+
}

saved-sites/saved-sites-impl/src/main/java/com/duckduckgo/savedsites/impl/newtab/FavouritesNewTabSectionView.kt

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class FavouritesNewTabSectionView @JvmOverloads constructor(
112112
@Inject
113113
lateinit var swipingTabsFeature: SwipingTabsFeatureProvider
114114

115+
@Inject
116+
lateinit var favoritesSwipeHandling: FavoritesSwipeHandling
117+
115118
private var isExpandable = true
116119
private var showPlaceholders = false
117120
private var placement: FavoritesPlacement = FavoritesPlacement.NEW_TAB_PAGE
@@ -196,34 +199,40 @@ class FavouritesNewTabSectionView @JvmOverloads constructor(
196199
}
197200

198201
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
199-
if (!swipingTabsFeature.isEnabled) return super.dispatchTouchEvent(ev)
200-
201-
when (ev?.actionMasked) {
202-
MotionEvent.ACTION_DOWN -> {
203-
viewModel.onTouchDown(ev.x, ev.y)
204-
removeCallbacks(longPressRunnable)
205-
postDelayed(longPressRunnable, longPressTimeoutMs)
206-
parent?.requestDisallowInterceptTouchEvent(false)
207-
}
202+
val favoritesSwipeHandlingEnabled = favoritesSwipeHandling.self().isEnabled()
208203

209-
MotionEvent.ACTION_MOVE -> {
210-
if (viewModel.isLongPressActive()) {
211-
parent?.requestDisallowInterceptTouchEvent(true)
212-
} else {
213-
viewModel.onTouchMove(ev.x, ev.y, touchSlop)?.let { decision ->
214-
when (decision) {
215-
SwipeDecision.CANCEL_LONG_PRESS -> removeCallbacks(longPressRunnable)
216-
SwipeDecision.HORIZONTAL -> parent?.requestDisallowInterceptTouchEvent(false)
217-
SwipeDecision.VERTICAL -> parent?.requestDisallowInterceptTouchEvent(true)
204+
if (swipingTabsFeature.isEnabled && !favoritesSwipeHandlingEnabled) {
205+
parent?.requestDisallowInterceptTouchEvent(true)
206+
}
207+
208+
if (favoritesSwipeHandlingEnabled) {
209+
when (ev?.actionMasked) {
210+
MotionEvent.ACTION_DOWN -> {
211+
viewModel.onTouchDown(ev.x, ev.y)
212+
removeCallbacks(longPressRunnable)
213+
postDelayed(longPressRunnable, longPressTimeoutMs)
214+
parent?.requestDisallowInterceptTouchEvent(false)
215+
}
216+
217+
MotionEvent.ACTION_MOVE -> {
218+
if (viewModel.isLongPressActive()) {
219+
parent?.requestDisallowInterceptTouchEvent(true)
220+
} else {
221+
viewModel.onTouchMove(ev.x, ev.y, touchSlop)?.let { decision ->
222+
when (decision) {
223+
SwipeDecision.CANCEL_LONG_PRESS -> removeCallbacks(longPressRunnable)
224+
SwipeDecision.HORIZONTAL -> parent?.requestDisallowInterceptTouchEvent(false)
225+
SwipeDecision.VERTICAL -> parent?.requestDisallowInterceptTouchEvent(true)
226+
}
218227
}
219228
}
220229
}
221-
}
222230

223-
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
224-
removeCallbacks(longPressRunnable)
225-
viewModel.onTouchUp()
226-
parent?.requestDisallowInterceptTouchEvent(false)
231+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
232+
removeCallbacks(longPressRunnable)
233+
viewModel.onTouchUp()
234+
parent?.requestDisallowInterceptTouchEvent(false)
235+
}
227236
}
228237
}
229238
return super.dispatchTouchEvent(ev)

0 commit comments

Comments
 (0)