Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2026 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.adblocking.impl.menu

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import com.duckduckgo.adblocking.impl.databinding.BottomSheetAdBlockingMenuBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

@SuppressLint("NoBottomSheetDialog")
class AdBlockingMenuBottomSheetDialog(builderContext: Context) : BottomSheetDialog(builderContext) {

interface EventListener {
fun onAlwaysOnClicked()
fun onDisableUntilRelaunchClicked()
fun onAlwaysOffClicked()
}

var eventListener: EventListener? = null

private val binding: BottomSheetAdBlockingMenuBinding =
BottomSheetAdBlockingMenuBinding.inflate(LayoutInflater.from(context))

init {
setContentView(binding.root)

binding.adBlockingMenuCloseButton.setOnClickListener { dismiss() }
binding.adBlockingMenuAlwaysOn.setOnClickListener {
eventListener?.onAlwaysOnClicked()
dismiss()
}
binding.adBlockingMenuDisableUntilRelaunch.setOnClickListener {
eventListener?.onDisableUntilRelaunchClicked()
dismiss()
}
binding.adBlockingMenuAlwaysOff.setOnClickListener {
eventListener?.onAlwaysOffClicked()
dismiss()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import logcat.logcat
import javax.inject.Inject

@InjectWith(ViewScope::class)
Expand Down Expand Up @@ -77,7 +78,10 @@ class AdBlockingMenuItemView @JvmOverloads constructor(
super.onAttachedToWindow()

val url = this.url ?: return
menuItem.setOnClickListener { onHostClick?.invoke() }
menuItem.setOnClickListener {
showMenuBottomSheet()
onHostClick?.invoke()
}

scope?.cancel()
scope = CoroutineScope(SupervisorJob() + dispatcherProvider.main()).also { scope ->
Expand All @@ -94,6 +98,24 @@ class AdBlockingMenuItemView @JvmOverloads constructor(
super.onDetachedFromWindow()
}

private fun showMenuBottomSheet() {
AdBlockingMenuBottomSheetDialog(context).apply {
eventListener = object : AdBlockingMenuBottomSheetDialog.EventListener {
override fun onAlwaysOnClicked() {
logcat { "AdBlocking menu: Always On" }
}

override fun onDisableUntilRelaunchClicked() {
logcat { "AdBlocking menu: Disable Until Relaunch" }
}

override fun onAlwaysOffClicked() {
logcat { "AdBlocking menu: Always Off" }
}
}
}.show()
}

private fun render(state: AdBlockingMenuState) {
when (state) {
AdBlockingMenuState.Hidden -> isGone = true
Expand Down
24 changes: 24 additions & 0 deletions ad-blocking/ad-blocking-impl/src/main/res/drawable/check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
~ Copyright (c) 2026 DuckDuckGo
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M20.773,6.712C21.07,7.001 21.076,7.476 20.788,7.773L11.673,17.142C10.642,18.201 8.941,18.201 7.91,17.142L3.212,12.313C2.924,12.016 2.93,11.542 3.227,11.253C3.524,10.964 3.999,10.97 4.288,11.267L8.985,16.096C9.427,16.55 10.156,16.55 10.598,16.096L19.712,6.727C20.001,6.43 20.476,6.424 20.773,6.712Z"
android:fillColor="?attr/daxColorPrimaryIcon"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2026 DuckDuckGo
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/keyline_4"
android:paddingBottom="@dimen/keyline_4">

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/adBlockingMenuTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_5"
android:layout_marginTop="@dimen/bottomSheetTitleVerticalPadding"
android:text="@string/ad_blocking_menu_title"
app:layout_constraintEnd_toStartOf="@id/adBlockingMenuCloseButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:typography="h2" />

<ImageButton
android:id="@+id/adBlockingMenuCloseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/keyline_4"
android:background="?attr/actionBarItemBackground"
android:contentDescription="@string/ad_blocking_menu_close_content_description"
android:src="@drawable/ic_close_24"
app:layout_constraintBottom_toBottomOf="@id/adBlockingMenuTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/adBlockingMenuTitle" />

<com.duckduckgo.common.ui.view.divider.HorizontalDivider
android:id="@+id/adBlockingMenuDivider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_5"
app:defaultPadding="false"
app:layout_constraintTop_toBottomOf="@id/adBlockingMenuTitle" />

<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/adBlockingMenuAlwaysOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/adBlockingMenuDivider"
app:leadingIcon="@drawable/check"
app:primaryText="@string/ad_blocking_menu_always_on" />

<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/adBlockingMenuDisableUntilRelaunch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/adBlockingMenuAlwaysOn"
app:leadingIcon="@drawable/check"
app:primaryText="@string/ad_blocking_menu_disable_until_relaunch" />

<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/adBlockingMenuAlwaysOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/adBlockingMenuDisableUntilRelaunch"
app:leadingIcon="@drawable/check"
app:primaryText="@string/ad_blocking_menu_always_off" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<resources>
<string name="ad_blocking_menu_disable">Disable YouTube Ad Blocking</string>
<string name="ad_blocking_menu_enable">Enable YouTube Ad Blocking</string>
<string name="ad_blocking_menu_title">YouTube Ad Blocking</string>
<string name="ad_blocking_menu_close_content_description">Close</string>
<string name="ad_blocking_menu_always_on">Always On</string>
<string name="ad_blocking_menu_disable_until_relaunch">Disable Until Relaunch</string>
<string name="ad_blocking_menu_always_off">Always Off</string>
</resources>
Loading