Skip to content

Commit

Permalink
Merge branch 'ondrej/feature/tab-swiping-animation-fix' into feature/…
Browse files Browse the repository at this point in the history
…ondrej/tab-swiping-typing-animation-fix
  • Loading branch information
0nko committed Jan 31, 2025
2 parents b0c991f + e3eda05 commit 3f12856
Show file tree
Hide file tree
Showing 60 changed files with 2,385 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

package com.duckduckgo.mobile.android.vpn.ui.newtab

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import androidx.lifecycle.lifecycleScope
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.anvil.annotations.PriorityKey
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.ViewViewModelFactory
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -42,9 +44,7 @@ import com.duckduckgo.newtabpage.api.NewTabPageSectionSettingsPlugin
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand All @@ -58,9 +58,12 @@ class AppTrackingProtectionNewTabSettingView @JvmOverloads constructor(
@Inject
lateinit var viewModelFactory: ViewViewModelFactory

@Inject
lateinit var dispatchers: DispatcherProvider

private val binding: ViewApptpSettingsItemBinding by viewBinding()

private var coroutineScope: CoroutineScope? = null
private val conflatedJob = ConflatedJob()

private val viewModel: AppTrackingProtectionNewTabSettingsViewModel by lazy {
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[AppTrackingProtectionNewTabSettingsViewModel::class.java]
Expand All @@ -71,12 +74,14 @@ class AppTrackingProtectionNewTabSettingView @JvmOverloads constructor(
super.onAttachedToWindow()
findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel)

@SuppressLint("NoHardcodedCoroutineDispatcher")
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

viewModel.viewState
conflatedJob += viewModel.viewState
.onEach { render(it) }
.launchIn(coroutineScope!!)
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)
}

override fun onDetachedFromWindow() {
conflatedJob.cancel()
super.onDetachedFromWindow()
}

private fun render(viewState: ViewState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.duckduckgo.mobile.android.vpn.ui.newtab

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
Expand All @@ -28,6 +27,8 @@ import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.common.ui.view.gone
import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.ViewViewModelFactory
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.di.scopes.ViewScope
Expand All @@ -46,9 +47,7 @@ import com.duckduckgo.newtabpage.api.NewTabPageSection
import com.duckduckgo.newtabpage.api.NewTabPageSectionPlugin
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand All @@ -69,30 +68,35 @@ class AppTrackingProtectionStateView @JvmOverloads constructor(
@Inject
lateinit var viewModelFactory: ViewViewModelFactory

@Inject
lateinit var dispatchers: DispatcherProvider

private val viewModel: PrivacyReportViewModel by lazy {
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[PrivacyReportViewModel::class.java]
}

private var coroutineScope: CoroutineScope? = null
private val conflatedJob = ConflatedJob()

private val binding: FragmentDeviceShieldCtaBinding by viewBinding()

override fun onAttachedToWindow() {
AndroidSupportInjection.inject(this)
super.onAttachedToWindow()

@SuppressLint("NoHardcodedCoroutineDispatcher")
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

viewModel.viewStateFlow
conflatedJob += viewModel.viewStateFlow
.onEach { viewState -> renderViewState(viewState) }
.launchIn(coroutineScope!!)
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)

deviceShieldPixels.didShowNewTabSummary()

configureViewReferences()
}

override fun onDetachedFromWindow() {
conflatedJob.cancel()
super.onDetachedFromWindow()
}

private fun configureViewReferences() {
binding.deviceShieldCtaLayout.setOnClickListener {
deviceShieldPixels.didPressNewTabSummary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"siteURL": "https://bad.etld-plus-two.site/",
"requestURL": "https://bad.etld-plus-two.site/script.js",
"requestType": "script",
"expectAction": "ignore"
"expectAction": "ignore",
"exceptPlatforms": ["ios-browser"]
},
{
"name": "tracker loads ignore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ class BrowserWebViewClient @Inject constructor(

private var shouldOpenDuckPlayerInNewTab: Boolean = true

private val confirmationCallback: (isMalicious: Boolean) -> Unit = {
// TODO (cbarreiro): Handle site blocked asynchronously
}

init {
appCoroutineScope.launch {
duckPlayer.observeShouldOpenInNewTab().collect {
Expand Down Expand Up @@ -165,7 +161,7 @@ class BrowserWebViewClient @Inject constructor(
try {
Timber.v("shouldOverride webViewUrl: ${webView.url} URL: $url")
webViewClientListener?.onShouldOverride()
if (requestInterceptor.shouldOverrideUrlLoading(url, isForMainFrame)) {
if (requestInterceptor.shouldOverrideUrlLoading(webView, url, isForMainFrame)) {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.duckduckgo.httpsupgrade.api.HttpsUpgrader
import com.duckduckgo.privacy.config.api.Gpc
import com.duckduckgo.request.filterer.api.RequestFilterer
import com.duckduckgo.user.agent.api.UserAgentProvider
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.withContext
import timber.log.Timber

Expand All @@ -62,6 +63,7 @@ interface RequestInterceptor {

@WorkerThread
fun shouldOverrideUrlLoading(
webView: WebView,
url: Uri,
isForMainFrame: Boolean,
): Boolean
Expand Down Expand Up @@ -105,10 +107,12 @@ class WebViewRequestInterceptor(
): WebResourceResponse? {
val url: Uri? = request.url

maliciousSiteBlockerWebViewIntegration.shouldIntercept(request, documentUri) {
handleSiteBlocked()
maliciousSiteBlockerWebViewIntegration.shouldIntercept(request, documentUri) { isMalicious ->
if (isMalicious) {
handleSiteBlocked(webView)
}
}?.let {
handleSiteBlocked()
handleSiteBlocked(webView)
return it
}

Expand Down Expand Up @@ -177,22 +181,24 @@ class WebViewRequestInterceptor(
return getWebResourceResponse(request, documentUrl, null)
}

override fun shouldOverrideUrlLoading(url: Uri, isForMainFrame: Boolean): Boolean {
override fun shouldOverrideUrlLoading(webView: WebView, url: Uri, isForMainFrame: Boolean): Boolean {
if (maliciousSiteBlockerWebViewIntegration.shouldOverrideUrlLoading(
url,
isForMainFrame,
) {
handleSiteBlocked()
) { isMalicious ->
if (isMalicious) {
handleSiteBlocked(webView)
}
}
) {
handleSiteBlocked()
handleSiteBlocked(webView)
return true
}
return false
}

private fun handleSiteBlocked() {
// TODO (cbarreiro): Handle site blocked
private fun handleSiteBlocked(webView: WebView) {
Snackbar.make(webView, "Site blocked", Snackbar.LENGTH_SHORT).show()
}

private fun getWebResourceResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.duckduckgo.app.browser.favicon.setting

import android.annotation.SuppressLint
import android.content.*
import android.util.*
import android.widget.*
Expand All @@ -26,13 +25,11 @@ import com.duckduckgo.app.browser.databinding.ViewSyncFaviconsFetchingBinding
import com.duckduckgo.app.browser.favicon.setting.FaviconFetchingViewModel.ViewState
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.*
import com.duckduckgo.saved.sites.impl.databinding.*
import dagger.android.support.*
import javax.inject.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand All @@ -47,7 +44,8 @@ class FaviconFetchingSyncSetting @JvmOverloads constructor(
@Inject
lateinit var viewModelFactory: FaviconFetchingViewModel.Factory

private var coroutineScope: CoroutineScope? = null
@Inject
lateinit var dispatchers: DispatcherProvider

private var job: ConflatedJob = ConflatedJob()

Expand All @@ -65,19 +63,14 @@ class FaviconFetchingSyncSetting @JvmOverloads constructor(
viewModel.onFaviconFetchingSettingChanged(isChecked)
}

@SuppressLint("NoHardcodedCoroutineDispatcher")
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

job += viewModel.viewState()
.onEach { render(it) }
.launchIn(coroutineScope!!)
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
coroutineScope?.cancel()
job.cancel()
coroutineScope = null
}

private fun render(it: ViewState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.duckduckgo.app.browser.indonesiamessage

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import androidx.lifecycle.lifecycleScope
import com.duckduckgo.anvil.annotations.ContributesActivePlugin
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.browser.R
Expand All @@ -33,16 +33,16 @@ import com.duckduckgo.common.ui.view.MessageCta.Message
import com.duckduckgo.common.ui.view.gone
import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.ViewViewModelFactory
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.di.scopes.ViewScope
import com.duckduckgo.newtabpage.api.NewTabPageSection
import com.duckduckgo.newtabpage.api.NewTabPageSectionPlugin
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand All @@ -56,26 +56,31 @@ class IndonesiaNewTabSectionView @JvmOverloads constructor(
@Inject
lateinit var viewModelFactory: ViewViewModelFactory

private var coroutineScope: CoroutineScope? = null
@Inject
lateinit var dispatchers: DispatcherProvider

private val binding: ViewIndonesiaNewTabSectionBinding by viewBinding()

private val viewModel: IndonesiaNewTabSectionViewModel by lazy {
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[IndonesiaNewTabSectionViewModel::class.java]
}

private val conflatedJob = ConflatedJob()

override fun onAttachedToWindow() {
AndroidSupportInjection.inject(this)
super.onAttachedToWindow()

findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel)

@SuppressLint("NoHardcodedCoroutineDispatcher")
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

viewModel.viewState
conflatedJob += viewModel.viewState
.onEach { render(it) }
.launchIn(coroutineScope!!)
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)
}

override fun onDetachedFromWindow() {
conflatedJob.cancel()
super.onDetachedFromWindow()
}

private fun render(viewState: ViewState) {
Expand Down
Loading

0 comments on commit 3f12856

Please sign in to comment.