Skip to content

Commit

Permalink
Update Settings: Update Ppro Purchasing and Setting items (#5385)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1207908166761516/1208966262488270/f

### Description

Initial changes to start moving Ppro settings to new Settings world.
This PR focuses specifically on the Purchasing state as well as the
Subscription Setting item state, as these are part of the same plugin.


[Designs](https://www.figma.com/design/CjH849hL53lhsPlf6Ufeo4/%E2%9A%99%EF%B8%8F-Browser-Settings-Documentation-(All-Platforms)?node-id=7605-431390&node-type=instance&t=ZKIMXkdZqzh5gEjU-11)

### Steps to test this PR

Prerequisite: Enable `newSettings` feature toggle

Prerequisite: Apply the patch in the [Asana
task](https://app.asana.com/0/1207908166761516/1208966262488270/f)

Also remember VPN, PIR, and ITR are **not** changed in this PR

### _Not purchased_
- [x] Set ln 99 of `ProSettingViewModel` to
`_viewState.emit(viewState.value.copy(status = EXPIRED, region =
SubscriptionRegion.US))`
- [x] Open Settings
- [x] Check against
[designs](https://www.figma.com/design/CjH849hL53lhsPlf6Ufeo4/%E2%9A%99%EF%B8%8F-Browser-Settings-Documentation-(All-Platforms)?node-id=7605-431390&node-type=instance&t=ZKIMXkdZqzh5gEjU-11)
- [x] Click items
- [x] Ensure correct screens are open

| Before  | After |
| ------ | ----- |

![not_purchased_original](https://github.com/user-attachments/assets/bfc77f48-77f2-49f6-96fd-c650b082fa15)|![Screenshot_20241212_192120](https://github.com/user-attachments/assets/316945a7-b5ae-4777-aa37-05822f19ec0b)|

### _Purchased_
- [x] Set ln 99 of `ProSettingViewModel` to
`_viewState.emit(viewState.value.copy(status = AUTO_RENEWABLE, region =
SubscriptionRegion.US))`
- [x] Open Settings
- [x] Check against
[designs](https://www.figma.com/design/CjH849hL53lhsPlf6Ufeo4/%E2%9A%99%EF%B8%8F-Browser-Settings-Documentation-(All-Platforms)?node-id=7605-431390&node-type=instance&t=ZKIMXkdZqzh5gEjU-11)
- [x] Click Subscription Settings
- [x] Ensure Subscription Settings is opened

| Before  | After |
| ------ | ----- |

![purchased_original](https://github.com/user-attachments/assets/d0c244c0-5535-4adc-944a-a324a8f1eda7)|![subscribed](https://github.com/user-attachments/assets/459f5e63-f161-4809-b25c-d01422ebfcfa)|

### _Activating (Waiting)_
- [x] Set ln 99 of `ProSettingViewModel` to
`_viewState.emit(viewState.value.copy(status = WAITING, region =
SubscriptionRegion.US))`
- [x] Open Settings
- [x] Check against
[designs](https://www.figma.com/design/CjH849hL53lhsPlf6Ufeo4/%E2%9A%99%EF%B8%8F-Browser-Settings-Documentation-(All-Platforms)?node-id=7605-431390&node-type=instance&t=ZKIMXkdZqzh5gEjU-11)
- [x] Click Subscription Settings
- [x] Ensure Subscription Settings is opened

| Before  | After |
| ------ | ----- |

![original_waiting](https://github.com/user-attachments/assets/05934c81-c3da-4b40-bfd7-c453f07f919e)|![activating](https://github.com/user-attachments/assets/40ec262f-b764-44f0-9d80-eaabb5ce6f73)|

### _Expired_
- [x] Set ln 99 of `ProSettingViewModel` to
`_viewState.emit(viewState.value.copy(status = EXPIRED, region =
SubscriptionRegion.US))`
- [x] Open Settings
- [x] Check against
[designs](https://www.figma.com/design/CjH849hL53lhsPlf6Ufeo4/%E2%9A%99%EF%B8%8F-Browser-Settings-Documentation-(All-Platforms)?node-id=7605-431390&node-type=instance&t=ZKIMXkdZqzh5gEjU-11)
- [x] Click Subscription Settings
- [x] Ensure Subscription Settings is opened

| Before  | After |
| ------ | ----- |

![original_expired](https://github.com/user-attachments/assets/3d26f2b7-382c-4d2a-b5ee-3c16b28e413f)|![expired](https://github.com/user-attachments/assets/3972412e-6daf-4a10-99b1-48f85d104914)|
  • Loading branch information
mikescamell authored Dec 13, 2024
1 parent 47e27c4 commit cc21a12
Show file tree
Hide file tree
Showing 25 changed files with 695 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class NewSettingsActivity : DuckDuckGoActivity() {
get() = binding.includeSettings.contentSettingsInternal

private val viewsPro
get() = binding.includeSettings.settingsSectionPro
get() = binding.includeSettings.contentSettingsPrivacyPro

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/content_settings_new.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
android:layout_marginTop="@dimen/keyline_4" />

<LinearLayout
android:id="@+id/settingsSectionPro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/contentSettingsPrivacyPro"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<com.duckduckgo.common.ui.view.divider.HorizontalDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

<include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.LayoutRes
import com.duckduckgo.common.ui.view.gone
import com.duckduckgo.common.ui.view.listitem.DaxListItem.IconSize
import com.duckduckgo.common.ui.view.listitem.DaxListItem.ImageBackground
import com.duckduckgo.common.ui.view.listitem.DaxListItem.LeadingIconSize
import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.ui.view.updateLayoutParams
import com.duckduckgo.common.ui.viewbinding.viewBinding
Expand Down Expand Up @@ -100,7 +100,7 @@ class DaxExpandableMenuItem @JvmOverloads constructor(
}

if (hasValue(R.styleable.DaxExpandableMenuItem_leadingIconSize)) {
val imageSize = LeadingIconSize.from(getInt(R.styleable.DaxExpandableMenuItem_leadingIconSize, 1))
val imageSize = IconSize.from(getInt(R.styleable.DaxExpandableMenuItem_leadingIconSize, 1))
setLeadingIconSize(imageSize)
}

Expand Down Expand Up @@ -163,8 +163,8 @@ class DaxExpandableMenuItem @JvmOverloads constructor(
}

/** Sets the leading icon background image type */
fun setLeadingIconSize(imageSize: LeadingIconSize) {
val size = resources.getDimensionPixelSize(LeadingIconSize.dimension(imageSize))
fun setLeadingIconSize(imageSize: IconSize) {
val size = resources.getDimensionPixelSize(IconSize.dimension(imageSize))
binding.daxExpandableMenuItemIcon.layoutParams.width = size
binding.daxExpandableMenuItemIcon.layoutParams.height = size
}
Expand Down Expand Up @@ -270,7 +270,7 @@ class DaxExpandableMenuItem @JvmOverloads constructor(
this.expandableMenuItem.setLeadingIconBackgroundType(value)
}

fun setLeadingIconSize(value: LeadingIconSize) = apply {
fun setLeadingIconSize(value: IconSize) = apply {
this.expandableMenuItem.setLeadingIconSize(value)
}
fun setPrimaryButtonText(value: String?) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BookmarksListItem @JvmOverloads constructor(
}

if (hasValue(R.styleable.TwoLineListItem_leadingIconSize)) {
val imageSize = LeadingIconSize.from(getInt(R.styleable.TwoLineListItem_leadingIconSize, 1))
val imageSize = IconSize.from(getInt(R.styleable.TwoLineListItem_leadingIconSize, 1))
setLeadingIconSize(imageSize)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ abstract class DaxListItem(
}

/** Sets the leading icon background image type */
fun setLeadingIconSize(imageSize: LeadingIconSize) {
val size = resources.getDimensionPixelSize(LeadingIconSize.dimension(imageSize))
fun setLeadingIconSize(imageSize: IconSize) {
val size = resources.getDimensionPixelSize(IconSize.dimension(imageSize))
leadingIcon.layoutParams.width = size
leadingIcon.layoutParams.height = size
}
Expand All @@ -145,8 +145,8 @@ abstract class DaxListItem(
* depends on the size of the image
*/

fun setLeadingIconSize(imageSize: LeadingIconSize, type: ImageBackground) {
val iconSize = resources.getDimensionPixelSize(LeadingIconSize.dimension(imageSize))
fun setLeadingIconSize(imageSize: IconSize, type: ImageBackground) {
val iconSize = resources.getDimensionPixelSize(IconSize.dimension(imageSize))
val backgroundSize = if (type == ImageBackground.None) {
iconSize
} else {
Expand Down Expand Up @@ -213,6 +213,13 @@ abstract class DaxListItem(
trailingSwitch.gone()
}

/** Sets the trailing icon size */
fun setTrailingIconSize(imageSize: IconSize) {
val size = resources.getDimensionPixelSize(IconSize.dimension(imageSize))
trailingIcon.layoutParams.width = size
trailingIcon.layoutParams.height = size
}

/** Hides all trailing items */
fun hideTrailingItems() {
trailingIconContainer.gone()
Expand Down Expand Up @@ -287,15 +294,15 @@ abstract class DaxListItem(
}
}

enum class LeadingIconSize {
enum class IconSize {
Small,
Medium,
Large,
ExtraLarge,
;

companion object {
fun from(size: Int): LeadingIconSize {
fun from(size: Int): IconSize {
// same order as attrs-lists.xml
return when (size) {
0 -> Small
Expand All @@ -306,7 +313,7 @@ abstract class DaxListItem(
}
}

fun dimension(size: LeadingIconSize): Int {
fun dimension(size: IconSize): Int {
return when (size) {
Small -> R.dimen.listItemImageSmallSize
Medium -> R.dimen.listItemImageMediumSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import com.duckduckgo.common.ui.view.DaxSwitch
import com.duckduckgo.common.ui.view.listitem.DaxListItem.LeadingIconSize.Medium
import com.duckduckgo.common.ui.view.listitem.DaxListItem.IconSize.Medium
import com.duckduckgo.common.ui.view.text.DaxTextView
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.mobile.android.R
Expand Down Expand Up @@ -93,13 +93,13 @@ class OneLineListItem @JvmOverloads constructor(
ImageBackground.None
}

val leadingIconSize = if (hasValue(R.styleable.OneLineListItem_leadingIconSize)) {
LeadingIconSize.from(getInt(R.styleable.OneLineListItem_leadingIconSize, 1))
val iconSize = if (hasValue(R.styleable.OneLineListItem_leadingIconSize)) {
IconSize.from(getInt(R.styleable.OneLineListItem_leadingIconSize, 1))
} else {
Medium
}

setLeadingIconSize(leadingIconSize, leadingIconBackground)
setLeadingIconSize(iconSize, leadingIconBackground)

val showTrailingIcon = hasValue(R.styleable.OneLineListItem_trailingIcon)
val showSwitch = getBoolean(R.styleable.OneLineListItem_showSwitch, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.common.ui.view.listitem
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.duckduckgo.common.ui.view.StatusIndicatorView
Expand All @@ -38,13 +39,13 @@ class SettingsListItem @JvmOverloads constructor(

private val binding: ViewSettingsListItemBinding by viewBinding()

val primaryText: DaxTextView
private val primaryText: DaxTextView
get() = binding.primaryText
val leadingIcon: ImageView
private val leadingIcon: ImageView
get() = binding.leadingIcon
val betaPill: ImageView
private val betaPill: ImageView
get() = binding.betaPill
val statusIndicator: StatusIndicatorView
private val statusIndicator: StatusIndicatorView
get() = binding.statusIndicator

init {
Expand All @@ -65,9 +66,9 @@ class SettingsListItem @JvmOverloads constructor(
leadingIcon.gone()
}

setPillVisible(getBoolean(R.styleable.SettingsListItem_showBetaPill, false))
betaPill.isVisible = getBoolean(R.styleable.SettingsListItem_showBetaPill, false)

val indicatorStatus = Status.from(getInt(R.styleable.SettingsListItem_indicatorStatus, 0))
val indicatorStatus = Status.from(getInt(R.styleable.SettingsListItem_indicatorStatus, 2))
statusIndicator.setStatus(indicatorStatus)

recycle()
Expand All @@ -79,11 +80,13 @@ class SettingsListItem @JvmOverloads constructor(
binding.root.setOnClickListener { onClick() }
}

/** Sets whether the status indicator is on or off */
fun setStatus(isOn: Boolean) {
statusIndicator.setStatus(if (isOn) Status.ON else Status.OFF)
}

private fun setPillVisible(isVisible: Boolean) {
betaPill.isVisible = isVisible
/** Sets the leading icon image resource */
fun setLeadingIconResource(@DrawableRes idRes: Int) {
leadingIcon.setImageResource(idRes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import com.duckduckgo.common.ui.view.DaxSwitch
import com.duckduckgo.common.ui.view.listitem.DaxListItem.LeadingIconSize.Medium
import com.duckduckgo.common.ui.view.listitem.DaxListItem.IconSize.Medium
import com.duckduckgo.common.ui.view.text.DaxTextView
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.mobile.android.R
Expand Down Expand Up @@ -100,7 +100,7 @@ class TwoLineListItem @JvmOverloads constructor(
}

val leadingIconSize = if (hasValue(R.styleable.TwoLineListItem_leadingIconSize)) {
LeadingIconSize.from(getInt(R.styleable.TwoLineListItem_leadingIconSize, 1))
IconSize.from(getInt(R.styleable.TwoLineListItem_leadingIconSize, 1))
} else {
Medium
}
Expand All @@ -114,6 +114,10 @@ class TwoLineListItem @JvmOverloads constructor(
setPillVisible(getBoolean(R.styleable.TwoLineListItem_showBetaPill, false))

val showTrailingIcon = hasValue(R.styleable.TwoLineListItem_trailingIcon)

val trailingIconSize = IconSize.from(getInt(R.styleable.TwoLineListItem_trailingIconSize, Medium.ordinal))
setTrailingIconSize(trailingIconSize)

val showSwitch = getBoolean(R.styleable.TwoLineListItem_showSwitch, false)
when {
showSwitch -> showSwitch()
Expand Down
26 changes: 25 additions & 1 deletion common/common-ui/src/main/res/layout/component_two_line_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,37 @@
app:trailingIcon="@drawable/ic_menu_vertical_24" />

<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
android:id="@+id/twoLineListItemWithBetaPill"
android:id="@+id/twoLineListItemWithSmallTrailingIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/twoLineListItemWithTrailingIcon"
app:primaryText="Two Line Item"
app:secondaryText="With Small Trailing Image"
app:trailingIcon="@drawable/ic_exclamation_red_16"
app:trailingIconSize="small" />

<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
android:id="@+id/twoLineListItemWithMediumTrailingIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/twoLineListItemWithSmallTrailingIcon"
app:primaryText="Two Line Item"
app:secondaryText="With Medium (default) Trailing Image"
app:trailingIcon="@drawable/ic_exclamation_red_16"
app:trailingIconSize="medium" />

<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
android:id="@+id/twoLineListItemWithBetaPill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/twoLineListItemWithMediumTrailingIcon"
app:primaryText="Two Line Item"
app:secondaryText="With Beta Pill"
app:showBetaPill="true" />

Expand Down
7 changes: 7 additions & 0 deletions common/common-ui/src/main/res/values/attrs-lists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<!-- Extra Large 40dp -->
<enum name="extra_large" value="3" />
</attr>
<attr name="trailingIconSize">
<!-- Small 16dp -->
<enum name="small" value="0" />
<!-- Medium 24dp (default) -->
<enum name="medium" value="1" />
</attr>
<attr name="textColorOverride" format="color"/>
<attr name="showOverflowMenu" format="boolean"/>

Expand Down Expand Up @@ -87,6 +93,7 @@
<attr name="leadingIconBackground"/>
<attr name="leadingIconSize"/>
<attr name="trailingIcon"/>
<attr name="trailingIconSize"/>
<attr name="showBetaPill"/>
<attr name="showSwitch"/>
<attr name="switchEnabled"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<!--
~ 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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<!--
~ 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import android.view.View
import com.duckduckgo.anvil.annotations.PriorityKey
import com.duckduckgo.common.ui.view.listitem.SectionHeaderListItem
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.settings.api.NewSettingsFeature
import com.duckduckgo.settings.api.ProSettingsPlugin
import com.duckduckgo.subscriptions.impl.R
import com.duckduckgo.subscriptions.impl.settings.views.ItrSettingView
import com.duckduckgo.subscriptions.impl.settings.views.LegacyProSettingView
import com.duckduckgo.subscriptions.impl.settings.views.PirSettingView
import com.duckduckgo.subscriptions.impl.settings.views.ProSettingView
import com.squareup.anvil.annotations.ContributesMultibinding
Expand All @@ -41,9 +43,13 @@ class ProSettingsTitle @Inject constructor() : ProSettingsPlugin {

@ContributesMultibinding(scope = ActivityScope::class)
@PriorityKey(500)
class ProSettings @Inject constructor() : ProSettingsPlugin {
class ProSettings @Inject constructor(private val newSettingsFeature: NewSettingsFeature) : ProSettingsPlugin {
override fun getView(context: Context): View {
return ProSettingView(context)
return if (newSettingsFeature.self().isEnabled()) {
ProSettingView(context)
} else {
LegacyProSettingView(context)
}
}
}

Expand Down
Loading

0 comments on commit cc21a12

Please sign in to comment.