Skip to content

Commit a6a0478

Browse files
authored
Merge pull request #9001 from woocommerce/feature/new_privacy_screen
[Feature] New privacy screen
2 parents 26e5d20 + 8ef3651 commit a6a0478

26 files changed

+971
-330
lines changed

RELEASE-NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- [*] [Internal] Fixed a crash related to a product image viewing [https://github.com/woocommerce/woocommerce-android/pull/9111]
66
- [*] [Internal] Fixes crashes in order details list when activity gets destroyed and recreated [https://github.com/woocommerce/woocommerce-android/pull/9113]
77
- [***] In-Person Payments: A merchant can now scan to add product during order creation. [https://github.com/woocommerce/woocommerce-android/pull/9125]
8+
- [*] Allow EU merchants to have better control of their privacy choices. A privacy choices banner will be shown the next time they open the app.
9+
[https://github.com/woocommerce/woocommerce-android/pull/9001]
810

911
13.7
1012
-----

WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefsWrapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,10 @@ class AppPrefsWrapper @Inject constructor() {
335335
fun getStorePhoneNumber(siteId: Int): String = AppPrefs.getStorePhoneNumber(siteId)
336336

337337
var savedPrivacyBannerSettings by AppPrefs::savedPrivacySettings
338+
339+
fun isCrashReportingEnabled(): Boolean = AppPrefs.isCrashReportingEnabled()
340+
341+
fun setCrashReportingEnabled(enabled: Boolean) {
342+
AppPrefs.setCrashReportingEnabled(enabled)
343+
}
338344
}

WooCommerce/src/main/kotlin/com/woocommerce/android/AppUrls.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ object AppUrls {
1515

1616
const val WOOCOMMERCE_UPGRADE = "https://docs.woocommerce.com/document/how-to-update-woocommerce/"
1717
const val WOOCOMMERCE_PLUGIN = "https://wordpress.org/plugins/woocommerce/"
18+
const val WOOCOMMERCE_WEB_OPTIONS = "https://woocommerce.com/tracking-and-opt-outs/"
19+
const val WOOCOMMERCE_USAGE_TRACKER = "https://woocommerce.com/usage-tracking/"
1820

1921
const val URL_LEARN_MORE_REVIEWS = "https://woocommerce.com/posts/reviews-woocommerce-best-practices/"
2022
const val URL_LEARN_MORE_ORDERS = "https://woocommerce.com/blog/"

WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsEvent.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,9 @@ enum class AnalyticsEvent(val siteless: Boolean = false) {
423423
SETTINGS_WE_ARE_HIRING_BUTTON_TAPPED,
424424
SETTINGS_IMAGE_OPTIMIZATION_TOGGLED,
425425
SETTINGS_CARD_PRESENT_SELECT_PAYMENT_GATEWAY_TAPPED,
426-
PRIVACY_SETTINGS_COLLECT_INFO_TOGGLED,
427426
PRIVACY_SETTINGS_PRIVACY_POLICY_LINK_TAPPED,
428427
PRIVACY_SETTINGS_SHARE_INFO_LINK_TAPPED,
429428
PRIVACY_SETTINGS_THIRD_PARTY_TRACKING_INFO_LINK_TAPPED,
430-
PRIVACY_SETTINGS_CRASH_REPORTING_TOGGLED,
431429
SETTINGS_DOMAINS_TAPPED,
432430

433431
// -- Payments Hub
@@ -844,5 +842,10 @@ enum class AnalyticsEvent(val siteless: Boolean = false) {
844842
// EU Shipping Notice
845843
EU_SHIPPING_NOTICE_SHOWN,
846844
EU_SHIPPING_NOTICE_DISMISSED,
847-
EU_SHIPPING_NOTICE_LEARN_MORE_TAPPED
845+
EU_SHIPPING_NOTICE_LEARN_MORE_TAPPED,
846+
847+
// Privacy Banner
848+
PRIVACY_CHOICES_BANNER_PRESENTED,
849+
PRIVACY_CHOICES_BANNER_SETTINGS_BUTTON_TAPPED,
850+
PRIVACY_CHOICES_BANNER_SAVE_BUTTON_TAPPED
848851
}

WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsTrackerWrapper.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
package com.woocommerce.android.analytics
22

3+
import android.content.SharedPreferences
4+
import com.woocommerce.android.AppPrefs
5+
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.PREFKEY_SEND_USAGE_STATS
36
import dagger.Reusable
7+
import kotlinx.coroutines.channels.awaitClose
8+
import kotlinx.coroutines.flow.Flow
9+
import kotlinx.coroutines.flow.callbackFlow
10+
import kotlinx.coroutines.flow.onStart
411
import javax.inject.Inject
512

613
@Reusable
7-
class AnalyticsTrackerWrapper @Inject constructor() {
8-
var sendUsageStats: Boolean by AnalyticsTracker.Companion::sendUsageStats
14+
open class AnalyticsTrackerWrapper @Inject constructor() {
15+
open var sendUsageStats: Boolean by AnalyticsTracker.Companion::sendUsageStats
16+
17+
open fun observeSendUsageStats(): Flow<Boolean> {
18+
return callbackFlow {
19+
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
20+
if (key == PREFKEY_SEND_USAGE_STATS) {
21+
trySend(sendUsageStats)
22+
}
23+
}
24+
AppPrefs.getPreferences().registerOnSharedPreferenceChangeListener(listener)
25+
26+
awaitClose {
27+
AppPrefs.getPreferences().unregisterOnSharedPreferenceChangeListener(listener)
28+
}
29+
}.onStart {
30+
emit(sendUsageStats)
31+
}
32+
}
933

1034
fun track(stat: AnalyticsEvent, properties: Map<String, *> = emptyMap<String, Any>()) {
1135
AnalyticsTracker.track(stat, properties)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@file:Suppress("MagicNumber")
2+
package com.woocommerce.android.ui.icons
3+
4+
import androidx.compose.material.icons.materialIcon
5+
import androidx.compose.material.icons.materialPath
6+
import androidx.compose.ui.graphics.vector.ImageVector
7+
8+
val OpenInNew: ImageVector
9+
get() {
10+
if (_openInNew != null) {
11+
return _openInNew!!
12+
}
13+
_openInNew = materialIcon(name = "Filled.OpenInNew") {
14+
materialPath {
15+
moveTo(19.0f, 19.0f)
16+
horizontalLineTo(5.0f)
17+
verticalLineTo(5.0f)
18+
horizontalLineToRelative(7.0f)
19+
verticalLineTo(3.0f)
20+
horizontalLineTo(5.0f)
21+
curveToRelative(-1.11f, 0.0f, -2.0f, 0.9f, -2.0f, 2.0f)
22+
verticalLineToRelative(14.0f)
23+
curveToRelative(0.0f, 1.1f, 0.89f, 2.0f, 2.0f, 2.0f)
24+
horizontalLineToRelative(14.0f)
25+
curveToRelative(1.1f, 0.0f, 2.0f, -0.9f, 2.0f, -2.0f)
26+
verticalLineToRelative(-7.0f)
27+
horizontalLineToRelative(-2.0f)
28+
verticalLineToRelative(7.0f)
29+
close()
30+
moveTo(14.0f, 3.0f)
31+
verticalLineToRelative(2.0f)
32+
horizontalLineToRelative(3.59f)
33+
lineToRelative(-9.83f, 9.83f)
34+
lineToRelative(1.41f, 1.41f)
35+
lineTo(19.0f, 6.41f)
36+
verticalLineTo(10.0f)
37+
horizontalLineToRelative(2.0f)
38+
verticalLineTo(3.0f)
39+
horizontalLineToRelative(-7.0f)
40+
close()
41+
}
42+
}
43+
return _openInNew!!
44+
}
45+
46+
private var _openInNew: ImageVector? = null

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivity.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.os.Build.VERSION
1212
import android.os.Build.VERSION_CODES
1313
import android.os.Bundle
1414
import android.os.Handler
15+
import android.os.Parcelable
1516
import android.text.method.LinkMovementMethod
1617
import android.view.Menu
1718
import android.view.MenuItem
@@ -99,6 +100,7 @@ import com.woocommerce.android.ui.plans.di.StartUpgradeFlowFactory
99100
import com.woocommerce.android.ui.plans.di.TrialStatusBarFormatterFactory
100101
import com.woocommerce.android.ui.plans.trial.DetermineTrialStatusBarState.TrialStatusBarState
101102
import com.woocommerce.android.ui.prefs.AppSettingsActivity
103+
import com.woocommerce.android.ui.prefs.RequestedAnalyticsValue
102104
import com.woocommerce.android.ui.products.ProductListFragmentDirections
103105
import com.woocommerce.android.ui.reviews.ReviewListFragmentDirections
104106
import com.woocommerce.android.ui.sitepicker.SitePickerFragmentDirections
@@ -600,6 +602,17 @@ class MainActivity :
600602
startActivityForResult(intent, RequestCodes.SETTINGS)
601603
}
602604

605+
private fun showPrivacySettingsScreen(requestedAnalyticsValue: Parcelable) {
606+
val intent = Intent(this, AppSettingsActivity::class.java).apply {
607+
putExtra(AppSettingsActivity.EXTRA_SHOW_PRIVACY_SETTINGS, true)
608+
putExtra(
609+
AppSettingsActivity.EXTRA_REQUESTED_ANALYTICS_VALUE_FROM_ERROR,
610+
requestedAnalyticsValue
611+
)
612+
}
613+
startActivityForResult(intent, RequestCodes.SETTINGS)
614+
}
615+
603616
override fun showAnalytics(targetPeriod: StatsTimeRangeSelection.SelectionType) {
604617
val action = MyStoreFragmentDirections.actionMyStoreToAnalytics(targetPeriod)
605618
navController.navigateSafely(action)
@@ -756,6 +769,12 @@ class MainActivity :
756769
viewModel.onRequestPrivacyUpdate(event.analyticsEnabled)
757770
}.show()
758771
}
772+
MainActivityViewModel.ShowPrivacySettings -> {
773+
showPrivacySettingsScreen(RequestedAnalyticsValue.NONE)
774+
}
775+
is MainActivityViewModel.ShowPrivacySettingsWithError -> {
776+
showPrivacySettingsScreen(event.requestedAnalyticsValue)
777+
}
759778
}
760779
}
761780

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivityViewModel.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.woocommerce.android.ui.moremenu.MoreMenuNewFeature
3030
import com.woocommerce.android.ui.moremenu.MoreMenuNewFeatureHandler
3131
import com.woocommerce.android.ui.plans.trial.DetermineTrialStatusBarState
3232
import com.woocommerce.android.ui.prefs.PrivacySettingsRepository
33+
import com.woocommerce.android.ui.prefs.RequestedAnalyticsValue
3334
import com.woocommerce.android.ui.whatsnew.FeatureAnnouncementRepository
3435
import com.woocommerce.android.util.BuildConfigWrapper
3536
import com.woocommerce.android.util.WooLog
@@ -283,6 +284,14 @@ class MainActivityViewModel @Inject constructor(
283284
}
284285
}
285286

287+
fun onPrivacySettingsTapped() {
288+
triggerEvent(ShowPrivacySettings)
289+
}
290+
291+
fun onSettingsPrivacyPreferenceUpdateFailed(requestedAnalyticsPreference: RequestedAnalyticsValue) {
292+
triggerEvent(ShowPrivacySettingsWithError(requestedAnalyticsPreference))
293+
}
294+
286295
object ViewOrderList : Event()
287296
object ViewReviewList : Event()
288297
object ViewMyStoreStats : Event()
@@ -301,6 +310,8 @@ class MainActivityViewModel @Inject constructor(
301310
data class ViewReviewDetail(val uniqueId: Long) : Event()
302311
data class ViewOrderDetail(val uniqueId: Long, val remoteNoteId: Long) : Event()
303312
data class ShowPrivacyPreferenceUpdatedFailed(val analyticsEnabled: Boolean) : Event()
313+
object ShowPrivacySettings : Event()
314+
data class ShowPrivacySettingsWithError(val requestedAnalyticsValue: RequestedAnalyticsValue) : Event()
304315

305316
sealed class MoreMenuBadgeState {
306317
data class UnseenReviews(val count: Int) : MoreMenuBadgeState()

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/prefs/AppSettingsActivity.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.woocommerce.android.ui.main.AppBarStatus
2727
import com.woocommerce.android.ui.main.MainActivity
2828
import com.woocommerce.android.ui.prefs.MainSettingsFragment.AppSettingsListener
2929
import com.woocommerce.android.util.AnalyticsUtils
30+
import com.woocommerce.android.util.parcelable
3031
import dagger.android.DispatchingAndroidInjector
3132
import dagger.hilt.android.AndroidEntryPoint
3233
import javax.inject.Inject
@@ -37,6 +38,8 @@ class AppSettingsActivity :
3738
AppSettingsListener,
3839
AppSettingsContract.View {
3940
companion object {
41+
const val EXTRA_SHOW_PRIVACY_SETTINGS = "extra_show_privacy_settings"
42+
const val EXTRA_REQUESTED_ANALYTICS_VALUE_FROM_ERROR = "extra_requested_analytics_value_from_error"
4043
const val RESULT_CODE_BETA_OPTIONS_CHANGED = 2
4144
const val KEY_BETA_OPTION_CHANGED = "key_beta_option_changed"
4245
}
@@ -75,6 +78,19 @@ class AppSettingsActivity :
7578
if (isBetaOptionChanged) {
7679
setResult(RESULT_CODE_BETA_OPTIONS_CHANGED)
7780
}
81+
82+
if (intent.getBooleanExtra(EXTRA_SHOW_PRIVACY_SETTINGS, false)) {
83+
84+
val requestedAnalyticsValue =
85+
intent.parcelable(EXTRA_REQUESTED_ANALYTICS_VALUE_FROM_ERROR)
86+
?: RequestedAnalyticsValue.NONE
87+
88+
navHostFragment.navController.navigate(
89+
MainSettingsFragmentDirections.actionMainSettingsFragmentToPrivacySettingsFragment(
90+
requestedAnalyticsValue
91+
)
92+
)
93+
}
7894
}
7995

8096
private val fragmentLifecycleObserver: FragmentLifecycleCallbacks = object : FragmentLifecycleCallbacks() {

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/prefs/MainSettingsFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ class MainSettingsFragment : Fragment(R.layout.fragment_settings_main), MainSett
184184

185185
binding.optionPrivacy.setOnClickListener {
186186
AnalyticsTracker.track(SETTINGS_PRIVACY_SETTINGS_BUTTON_TAPPED)
187-
findNavController().navigateSafely(R.id.action_mainSettingsFragment_to_privacySettingsFragment)
187+
findNavController().navigateSafely(
188+
MainSettingsFragmentDirections.actionMainSettingsFragmentToPrivacySettingsFragment(
189+
RequestedAnalyticsValue.NONE
190+
)
191+
)
188192
}
189193

190194
binding.optionSendFeedback.setOnClickListener {

0 commit comments

Comments
 (0)