-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/5.209.0' into main
- Loading branch information
Showing
208 changed files
with
7,889 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...ava/com/duckduckgo/mobile/android/vpn/ui/newtab/AppTrackingProtectionNewTabSettingView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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.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 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.ViewViewModelFactory | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.di.scopes.ViewScope | ||
import com.duckduckgo.feature.toggles.api.Toggle | ||
import com.duckduckgo.mobile.android.vpn.databinding.ViewApptpSettingsItemBinding | ||
import com.duckduckgo.mobile.android.vpn.feature.removal.VpnFeatureRemover | ||
import com.duckduckgo.mobile.android.vpn.ui.newtab.AppTrackingProtectionNewTabSettingsViewModel.ViewState | ||
import com.duckduckgo.mobile.android.vpn.ui.onboarding.VpnStore | ||
import com.duckduckgo.newtabpage.api.NewTabPageSection | ||
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.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@InjectWith(ViewScope::class) | ||
class AppTrackingProtectionNewTabSettingView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0, | ||
) : LinearLayout(context, attrs, defStyle) { | ||
|
||
@Inject | ||
lateinit var viewModelFactory: ViewViewModelFactory | ||
|
||
private val binding: ViewApptpSettingsItemBinding by viewBinding() | ||
|
||
private var coroutineScope: CoroutineScope? = null | ||
|
||
private val viewModel: AppTrackingProtectionNewTabSettingsViewModel by lazy { | ||
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[AppTrackingProtectionNewTabSettingsViewModel::class.java] | ||
} | ||
|
||
override fun onAttachedToWindow() { | ||
AndroidSupportInjection.inject(this) | ||
super.onAttachedToWindow() | ||
findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel) | ||
|
||
@SuppressLint("NoHardcodedCoroutineDispatcher") | ||
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) | ||
|
||
viewModel.viewState | ||
.onEach { render(it) } | ||
.launchIn(coroutineScope!!) | ||
} | ||
|
||
private fun render(viewState: ViewState) { | ||
binding.root.quietlySetIsChecked(viewState.enabled) { _, enabled -> | ||
viewModel.onSettingEnabled(enabled) | ||
} | ||
} | ||
} | ||
|
||
@ContributesMultibinding(scope = ActivityScope::class) | ||
@PriorityKey(NewTabPageSectionSettingsPlugin.APP_TRACKING_PROTECTION) | ||
class AppTrackingProtectionNewTabSettingViewPlugin @Inject constructor( | ||
private val vpnStore: VpnStore, | ||
private val vpnFeatureRemover: VpnFeatureRemover, | ||
) : NewTabPageSectionSettingsPlugin { | ||
override val name = NewTabPageSection.APP_TRACKING_PROTECTION.name | ||
|
||
override fun getView(context: Context): View { | ||
return AppTrackingProtectionNewTabSettingView(context) | ||
} | ||
|
||
override suspend fun isActive(): Boolean { | ||
if (vpnFeatureRemover.isFeatureRemoved()) { | ||
return false | ||
} | ||
return vpnStore.didShowOnboarding() | ||
} | ||
} | ||
|
||
/** | ||
* Local feature/settings - they will never be in remote config | ||
*/ | ||
@ContributesRemoteFeature( | ||
scope = AppScope::class, | ||
featureName = "newTabAppTPSectionSetting", | ||
) | ||
interface NewTabAppTrackingProtectionSectionSetting { | ||
@Toggle.DefaultValue(true) | ||
fun self(): Toggle | ||
} |
64 changes: 64 additions & 0 deletions
64
...m/duckduckgo/mobile/android/vpn/ui/newtab/AppTrackingProtectionNewTabSettingsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.mobile.android.vpn.ui.newtab | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.duckduckgo.anvil.annotations.ContributesViewModel | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.ViewScope | ||
import com.duckduckgo.feature.toggles.api.Toggle.State | ||
import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
@SuppressLint("NoLifecycleObserver") // we don't observe app lifecycle | ||
@ContributesViewModel(ViewScope::class) | ||
class AppTrackingProtectionNewTabSettingsViewModel @Inject constructor( | ||
private val dispatchers: DispatcherProvider, | ||
private val setting: NewTabAppTrackingProtectionSectionSetting, | ||
private val pixel: DeviceShieldPixels, | ||
) : ViewModel(), DefaultLifecycleObserver { | ||
|
||
private val _viewState = MutableStateFlow(ViewState(true)) | ||
val viewState = _viewState.asStateFlow() | ||
|
||
data class ViewState(val enabled: Boolean) | ||
|
||
override fun onCreate(owner: LifecycleOwner) { | ||
super.onCreate(owner) | ||
|
||
viewModelScope.launch(dispatchers.io()) { | ||
val isEnabled = setting.self().isEnabled() | ||
withContext(dispatchers.main()) { | ||
_viewState.update { ViewState(isEnabled) } | ||
} | ||
} | ||
} | ||
|
||
fun onSettingEnabled(enabled: Boolean) { | ||
setting.self().setEnabled(State(enabled)) | ||
pixel.reportNewTabSectionToggled(enabled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app-tracking-protection/vpn-impl/src/main/res/drawable/ic_announce_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<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="M16,3.5C16.552,3.5 17,3.948 17,4.5V5.5V18.5V19.5C17,20.052 16.552,20.5 16,20.5C15.448,20.5 15,20.052 15,19.5V19.212L12.744,18.431L12.656,18.694C12.092,20.387 10.319,21.361 8.587,20.928C7.067,20.548 6,19.181 6,17.614V16.097L3.926,15.379C3.777,15.743 3.418,16 3,16C2.448,16 2,15.552 2,15V14V10V9C2,8.448 2.448,8 3,8C3.418,8 3.777,8.257 3.926,8.621L15,4.788V4.5C15,3.948 15.448,3.5 16,3.5ZM4,10.712V13.288L15,17.096V6.904L4,10.712ZM10.854,17.777L8,16.789V17.614C8,18.264 8.442,18.83 9.072,18.987C9.79,19.167 10.525,18.763 10.759,18.062L10.854,17.777ZM21.894,6.553C22.141,7.047 21.941,7.647 21.447,7.894L19.447,8.894C18.953,9.141 18.353,8.941 18.106,8.447C17.859,7.953 18.059,7.353 18.553,7.106L20.553,6.106C21.047,5.859 21.647,6.059 21.894,6.553ZM18,12C18,11.448 18.448,11 19,11H21C21.552,11 22,11.448 22,12C22,12.552 21.552,13 21,13H19C18.448,13 18,12.552 18,12ZM18.106,15.553C18.353,15.059 18.953,14.859 19.447,15.106L21.447,16.105C21.941,16.353 22.141,16.953 21.894,17.447C21.647,17.941 21.047,18.141 20.553,17.894L18.553,16.894C18.059,16.647 17.859,16.047 18.106,15.553Z" | ||
android:fillColor="?attr/daxColorPrimaryIcon" | ||
android:fillAlpha="0.84" | ||
android:fillType="evenOdd"/> | ||
</vector> |
Oops, something went wrong.