Skip to content

Commit

Permalink
Mode UI to impl
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Aug 2, 2024
1 parent 53c8c62 commit 9fd2a15
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ import com.duckduckgo.downloads.api.DownloadConfirmationDialogListener
import com.duckduckgo.downloads.api.DownloadsFileActions
import com.duckduckgo.downloads.api.FileDownloader
import com.duckduckgo.downloads.api.FileDownloader.PendingFileDownload
import com.duckduckgo.duckplayer.api.DuckPlayerBottomSheet
import com.duckduckgo.duckplayer.api.DuckPlayerFragment
import com.duckduckgo.duckplayer.api.DuckPlayer
import com.duckduckgo.duckplayer.api.DuckPlayerSettingsNoParams
import com.duckduckgo.js.messaging.api.JsCallbackData
import com.duckduckgo.js.messaging.api.JsMessageCallback
Expand Down Expand Up @@ -533,6 +532,9 @@ class BrowserTabFragment :
@Inject
lateinit var singlePrintSafeguardFeature: SinglePrintSafeguardFeature

@Inject
lateinit var duckPlayer: DuckPlayer

/**
* We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
* This is needed because the activity stack will be cleared if an external link is opened in our browser
Expand Down Expand Up @@ -1583,10 +1585,8 @@ class BrowserTabFragment :
is Command.HideOnboardingDaxDialog -> hideOnboardingDaxDialog(it.onboardingCta)
is Command.OpenDuckPlayerSettings -> globalActivityStarter.start(binding.root.context, DuckPlayerSettingsNoParams)
is Command.OpenDuckPlayerInfo -> {
if (context?.resources?.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) {
DuckPlayerFragment.newInstance().show(childFragmentManager, null)
} else {
DuckPlayerBottomSheet.newInstance().show(childFragmentManager, null)
context?.resources?.configuration?.let {
duckPlayer.showDuckPlayerPrimeModal(it, childFragmentManager)
}
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.duckduckgo.duckplayer.api

import android.content.res.Configuration
import android.net.Uri
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.fragment.app.FragmentManager
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.AlwaysAsk
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Disabled
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled
Expand Down Expand Up @@ -121,6 +123,8 @@ interface DuckPlayer {
webView: WebView,
): WebResourceResponse?

fun showDuckPlayerPrimeModal(configuration: Configuration, fragmentManager: FragmentManager)

/**
* Data class representing user preferences for Duck Player.
*
Expand Down
21 changes: 0 additions & 21 deletions duckplayer/duckplayer-api/src/main/res/values/donottranslate.xml

This file was deleted.

1 change: 1 addition & 0 deletions duckplayer/duckplayer-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation Google.android.material
implementation Google.dagger

implementation "com.airbnb.android:lottie:_"
implementation "com.squareup.logcat:logcat:_"

testImplementation Testing.junit4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.duckduckgo.duckplayer.impl

import android.content.res.Configuration
import android.net.Uri
import android.webkit.MimeTypeMap
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.core.net.toUri
import androidx.fragment.app.FragmentManager
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.UrlScheme
Expand All @@ -32,6 +34,8 @@ import com.duckduckgo.duckplayer.api.DuckPlayer.UserPreferences
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.AlwaysAsk
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Disabled
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled
import com.duckduckgo.duckplayer.impl.ui.DuckPlayerPrimeBottomSheet
import com.duckduckgo.duckplayer.impl.ui.DuckPlayerPrimeDialogFragment
import com.squareup.anvil.annotations.ContributesBinding
import dagger.SingleInstanceIn
import java.io.InputStream
Expand Down Expand Up @@ -260,4 +264,12 @@ class RealDuckPlayer @Inject constructor(
}
return WebResourceResponse(null, null, null)
}

override fun showDuckPlayerPrimeModal(configuration: Configuration, fragmentManager: FragmentManager) {
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
DuckPlayerPrimeDialogFragment.newInstance().show(fragmentManager, null)
} else {
DuckPlayerPrimeBottomSheet.newInstance().show(fragmentManager, null)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package com.duckduckgo.duckplayer.api
/*
* Copyright (c) 2024 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.duckplayer.impl.ui

import android.app.Dialog
import android.content.res.Configuration
Expand All @@ -8,28 +24,32 @@ import android.view.View
import android.view.ViewGroup
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import com.duckduckgo.duckplayer.api.databinding.BottomSheetDuckPlayerBinding
import com.duckduckgo.duckplayer.impl.R
import com.duckduckgo.duckplayer.impl.databinding.ModalDuckPlayerBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class DuckPlayerBottomSheet : BottomSheetDialogFragment() {
class DuckPlayerPrimeBottomSheet : BottomSheetDialogFragment() {

private lateinit var binding: BottomSheetDuckPlayerBinding
private lateinit var binding: ModalDuckPlayerBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
binding = BottomSheetDuckPlayerBinding.inflate(inflater, container, false)
binding = ModalDuckPlayerBinding.inflate(inflater, container, false)
LottieCompositionFactory.fromRawRes(context, R.raw.duckplayer)
binding.duckPlayerAnimation.setAnimation(R.raw.duckplayer)
binding.duckPlayerAnimation.playAnimation()
binding.duckPlayerAnimation.repeatCount = LottieDrawable.INFINITE
binding.dismissButton.setOnClickListener {
dismiss()
}
binding.closeButton.setOnClickListener {
dismiss()
}
return binding.root
}

Expand All @@ -45,7 +65,7 @@ class DuckPlayerBottomSheet : BottomSheetDialogFragment() {
}

companion object {
fun newInstance(): DuckPlayerBottomSheet =
DuckPlayerBottomSheet()
fun newInstance(): DuckPlayerPrimeBottomSheet =
DuckPlayerPrimeBottomSheet()
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
package com.duckduckgo.duckplayer.api
/*
* Copyright (c) 2024 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.duckplayer.impl.ui

import android.content.res.Configuration
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
import android.view.WindowInsets
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import com.duckduckgo.duckplayer.api.databinding.BottomSheetDuckPlayerBinding
import com.duckduckgo.duckplayer.impl.R
import com.duckduckgo.duckplayer.impl.databinding.ModalDuckPlayerBinding

class DuckPlayerFragment : DialogFragment() {
class DuckPlayerPrimeDialogFragment : DialogFragment() {

private lateinit var binding: BottomSheetDuckPlayerBinding
private lateinit var binding: ModalDuckPlayerBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
binding = BottomSheetDuckPlayerBinding.inflate(inflater, container, false)
binding = ModalDuckPlayerBinding.inflate(inflater, container, false)
LottieCompositionFactory.fromRawRes(context, R.raw.duckplayer)
binding.duckPlayerAnimation.setAnimation(R.raw.duckplayer)
binding.duckPlayerAnimation.playAnimation()
binding.duckPlayerAnimation.repeatCount = LottieDrawable.INFINITE
binding.dismissButton.setOnClickListener {
dismiss()
}
binding.closeButton.setOnClickListener {
dismiss()
}
return binding.root
}

Expand All @@ -41,6 +64,11 @@ class DuckPlayerFragment : DialogFragment() {
dialog?.window?.let { window ->
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
if (VERSION.SDK_INT >= VERSION_CODES.R) {
window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
}
}
}

Expand All @@ -49,7 +77,7 @@ class DuckPlayerFragment : DialogFragment() {
dismiss()
}
companion object {
fun newInstance(): DuckPlayerFragment =
DuckPlayerFragment()
fun newInstance(): DuckPlayerPrimeDialogFragment =
DuckPlayerPrimeDialogFragment()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
android:pathData="M64,80a7,7 0,0 0,3.55 -13.03c-0.87,-0.51 -1.73,-1.05 -2.35,-1.85L48.15,43.19c-1.08,-1.39 -3.26,-0.1 -2.56,1.51l11.01,25.68c0.35,0.82 0.41,1.73 0.41,2.62"
android:fillColor="#444"/>
</vector>

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="16dp" /> <!-- Adjust the radius as needed -->
<solid android:color="#17000000" /> <!-- Background color -->
<corners android:radius="8dp" />
<solid android:color="@color/black9" />
</shape>
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2024 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:tools="http://schemas.android.com/tools"
Expand All @@ -8,14 +24,13 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/daxDialogContentPaddingTop"
tools:context=".DuckPlayerBottomSheet">
tools:context="com.duckduckgo.duckplayer.impl.ui.DuckPlayerPrimeBottomSheet">

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:id="@+id/animationContainer"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/keyline_2"
app:cardBackgroundColor="@color/gray20"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand All @@ -35,6 +50,20 @@

</androidx.cardview.widget.CardView>

<ImageButton
android:id="@+id/closeButton"
android:src="@drawable/ic_close_24"
android:layout_marginEnd="@dimen/keyline_4"
android:layout_marginBottom="@dimen/keyline_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/animationContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?actionBarItemBackground"
android:layout_gravity="end"
android:contentDescription="@string/duck_player_close_modal_content_description"
/>

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/title"
app:layout_constraintTop_toBottomOf="@id/animationContainer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@
<string name="duck_player_mode_always_ask">Always Ask</string>
<string name="duck_player_mode_dialog_title">Open Youtube videos in Duck Player?</string>
<string name="duck_player_mode_dialog_description">Duck Player lets you watch YouTube without targeted ads in a theater-like experience in DuckDuckGo.</string>
<string name="duck_player_close_modal_content_description">Close</string>
<string name="duck_player_info_modal_title">Drowning in ads on YouTube? Try Duck Player!</string>
<string name="duck_player_info_modal_text">Duck Player lets you watch YouTube without targeted ads in a theater-like experience in DuckDuckGo and what you watch won’t influence your recommendations.</string>
<string name="duck_player_info_modal_button">Got it!</string>
</resources>

0 comments on commit 9fd2a15

Please sign in to comment.