Skip to content

Commit 3d539fb

Browse files
authored
Subscriber plans (#21984)
* Updated wordpress-rs hash * Added country and email address to subscriber detail * Moved date formatting to the parent view model * Reverted date formatting change, format detail date * Added support for opening urls and emails * Moved dummy data note * Added plan to detail screen * First pass at fetching subscriber stats * Incomplete attempt at fetchSubscriber * Added logic to fetch both a subscriber and its stats * Show actual stats when available * Fetch subscriber stats when clicked * Clear stats before fetching * Use a cancellable job for stats * Hide country when not available * Use withContext(ioDispatcher) when fetching data * Fixed empty line Detekt nag * Added open email vector drawable * Removed unused detail view model * Updated wordpress-rs hash * Display multiple plans * Make plans clickable * Claude-generated plan screen * Removed plan id * Removed gift id * Shell for navigating to plan detail * Pass the plan index * Added gift icon, replaced hard-coded strings with string resources * Changed clicked icon * Fixed Detekt warning * Replaced next billing date with renewal interval * Added content description to gift icon * Added subscription status enum * Added subscription status to detail screen * Added plan status * Show status in uppercase * Fixed Copilot warnings
1 parent 7e154ad commit 3d539fb

File tree

6 files changed

+494
-28
lines changed

6 files changed

+494
-28
lines changed

WordPress/src/main/java/org/wordpress/android/ui/subscribers/SubscriberDetailScreen.kt

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import androidx.compose.foundation.rememberScrollState
1616
import androidx.compose.foundation.shape.CircleShape
1717
import androidx.compose.foundation.verticalScroll
1818
import androidx.compose.material.icons.Icons
19-
import androidx.compose.material.icons.filled.Check
2019
import androidx.compose.material.icons.filled.Delete
2120
import androidx.compose.material.icons.filled.Email
2221
import androidx.compose.material3.Button
@@ -57,6 +56,7 @@ fun SubscriberDetailScreen(
5756
subscriber: Subscriber,
5857
onUrlClick: (String) -> Unit,
5958
onEmailClick: (String) -> Unit,
59+
onPlanClick: (index: Int) -> Unit,
6060
modifier: Modifier = Modifier,
6161
subscriberStats: State<IndividualSubscriberStats?>? = null
6262
) {
@@ -77,7 +77,10 @@ fun SubscriberDetailScreen(
7777

7878
Spacer(modifier = Modifier.height(16.dp))
7979

80-
NewsletterSubscriptionCard(subscriber)
80+
NewsletterSubscriptionCard(
81+
subscriber = subscriber,
82+
onPlanClick = onPlanClick
83+
)
8184

8285
Spacer(modifier = Modifier.height(16.dp))
8386

@@ -157,7 +160,7 @@ fun EmailStatsCard(
157160
value = subscriberStats.uniqueOpens.toString()
158161
)
159162
StatItem(
160-
icon = Icons.Default.Check,
163+
icon = ImageVector.vectorResource(id = R.drawable.ic_touch),
161164
label = stringResource(R.string.subscribers_clicked_label),
162165
value = subscriberStats.uniqueClicks.toString()
163166
)
@@ -198,7 +201,10 @@ fun StatItem(
198201
}
199202

200203
@Composable
201-
fun NewsletterSubscriptionCard(subscriber: Subscriber) {
204+
fun NewsletterSubscriptionCard(
205+
subscriber: Subscriber,
206+
onPlanClick: (index: Int) -> Unit
207+
) {
202208
Card(
203209
modifier = Modifier.fillMaxWidth(),
204210
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
@@ -223,15 +229,34 @@ fun NewsletterSubscriptionCard(subscriber: Subscriber) {
223229
value = SimpleDateFormatWrapper().getDateInstance().format(subscriber.dateSubscribed)
224230
)
225231

232+
subscriber.subscriptionStatus?.let { status ->
233+
Spacer(modifier = Modifier.height(16.dp))
234+
DetailRow(
235+
label = stringResource(R.string.subscribers_status_label),
236+
value = status
237+
)
238+
}
239+
226240
if (subscriber.plans?.isNotEmpty() == true) {
227-
val plan = subscriber.plans!!.first()
228241
Spacer(modifier = Modifier.height(12.dp))
229242

230-
DetailRow(
231-
label = stringResource(R.string.subscribers_plan_label),
232-
value = plan.title,
233-
valueColor = MaterialTheme.colorScheme.primary
234-
)
243+
subscriber.plans!!.forEachIndexed { index, plan ->
244+
if (index > 0) {
245+
Spacer(modifier = Modifier.height(8.dp))
246+
}
247+
DetailRow(
248+
label = if (subscriber.plans!!.size == 1) {
249+
stringResource(R.string.subscribers_plan_label)
250+
} else {
251+
stringResource(R.string.subscribers_plan_label) + " ${index + 1}"
252+
},
253+
value = plan.title,
254+
valueColor = MaterialTheme.colorScheme.primary,
255+
modifier = Modifier.clickable {
256+
onPlanClick(index)
257+
}
258+
)
259+
}
235260
}
236261
}
237262
}
@@ -373,7 +398,8 @@ fun SubscriberDetailScreenPreview() {
373398
subscriber = subscriber,
374399
subscriberStats = remember { mutableStateOf(subscriberStats) },
375400
onUrlClick = {},
376-
onEmailClick = {}
401+
onEmailClick = {},
402+
onPlanClick = {}
377403
)
378404
}
379405
}

0 commit comments

Comments
 (0)