Update UI for PNP launch megaphone.

This commit is contained in:
Greyson Parrelli 2024-02-07 15:14:04 -05:00 committed by Cody Henthorne
parent 8797236b5a
commit ce09e9a217
3 changed files with 51 additions and 16 deletions

View file

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -103,7 +104,7 @@ public final class Megaphones {
* This is also when you would hide certain megaphones based on things like {@link FeatureFlags}.
*/
private static Map<Event, MegaphoneSchedule> buildDisplayOrder(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
return new LinkedHashMap<Event, MegaphoneSchedule>() {{
return new LinkedHashMap<>() {{
put(Event.PINS_FOR_ALL, new PinsForAllSchedule());
put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER);
put(Event.NOTIFICATIONS, shouldShowNotificationsMegaphone(context) ? RecurringSchedule.every(TimeUnit.DAYS.toMillis(30)) : NEVER);
@ -117,6 +118,7 @@ public final class Megaphones {
// Feature-introduction megaphones should *probably* be added below this divider
put(Event.ADD_A_PROFILE_PHOTO, shouldShowAddAProfilePhotoMegaphone(context) ? ALWAYS : NEVER);
put(Event.PNP_LAUNCH, shouldShowPnpLaunchMegaphone() ? ALWAYS : NEVER);
}};
}
@ -144,7 +146,8 @@ public final class Megaphones {
return buildSetUpYourUsernameMegaphone(context);
case GRANT_FULL_SCREEN_INTENT:
return buildGrantFullScreenIntentPermission(context);
case PNP_LAUNCH:
return buildPnpLaunchMegaphone();
default:
throw new IllegalArgumentException("Event not handled!");
}
@ -332,6 +335,20 @@ public final class Megaphones {
.build();
}
public static @NonNull Megaphone buildPnpLaunchMegaphone() {
return new Megaphone.Builder(Event.PNP_LAUNCH, Megaphone.Style.BASIC)
.setTitle(R.string.PnpLaunchMegaphone_title)
.setBody(R.string.PnpLaunchMegaphone_body)
.setImage(R.drawable.usernames_megaphone)
.setActionButton(R.string.PnpLaunchMegaphone_learn_more, (megaphone, controller) -> {
controller.onMegaphoneDialogFragmentRequested(new NewWaysToConnectDialogFragment());
})
.setSecondaryButton(R.string.PnpLaunchMegaphone_dismiss, (megaphone, controller) -> {
controller.onMegaphoneCompleted(Event.PNP_LAUNCH);
})
.build();
}
public static @NonNull Megaphone buildGrantFullScreenIntentPermission(@NonNull Context context) {
return new Megaphone.Builder(Event.GRANT_FULL_SCREEN_INTENT, Megaphone.Style.BASIC)
.setTitle(R.string.GrantFullScreenIntentPermission_megaphone_title)
@ -405,6 +422,10 @@ public final class Megaphones {
(System.currentTimeMillis() - phoneNumberDiscoveryDisabledAt) >= TimeUnit.DAYS.toMillis(3);
}
private static boolean shouldShowPnpLaunchMegaphone() {
return TextUtils.isEmpty(SignalStore.account().getUsername());
}
private static boolean shouldShowGrantFullScreenIntentPermission(@NonNull Context context) {
return Build.VERSION.SDK_INT >= 34 && !NotificationManagerCompat.from(context).canUseFullScreenIntent();
}
@ -450,6 +471,7 @@ public final class Megaphones {
REMOTE_MEGAPHONE("remote_megaphone"),
BACKUP_SCHEDULE_PERMISSION("backup_schedule_permission"),
SET_UP_YOUR_USERNAME("set_up_your_username"),
PNP_LAUNCH("pnp_launch"),
GRANT_FULL_SCREEN_INTENT("grant_full_screen_intent");
private final String key;

View file

@ -80,17 +80,19 @@ private fun NewWaysToConnectDialogContent(
navigationIconPainter = painterResource(id = R.drawable.symbol_x_24)
) {
Column(modifier = Modifier.padding(it)) {
Text(
text = stringResource(id = R.string.NewWaysToConnectDialogFragment__new_ways_to_connect),
style = MaterialTheme.typography.headlineMedium,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = dimensionResource(id = R.dimen.core_ui__gutter))
.padding(top = 16.dp, bottom = 36.dp)
)
LazyColumn(modifier = Modifier.weight(1f)) {
item {
Text(
text = stringResource(id = R.string.NewWaysToConnectDialogFragment__new_ways_to_connect),
style = MaterialTheme.typography.headlineMedium,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = dimensionResource(id = R.dimen.core_ui__gutter))
.padding(top = 4.dp, bottom = 36.dp)
)
}
item {
NewWaysToConnectRowItem(
title = stringResource(id = R.string.NewWaysToConnectDialogFragment__phone_number_privacy),
@ -120,7 +122,7 @@ private fun NewWaysToConnectDialogContent(
onClick = onSetUpUsernameClick,
modifier = Modifier
.padding(horizontal = dimensionResource(id = R.dimen.core_ui__gutter))
.padding(top = 36.dp)
.padding(top = 16.dp)
.defaultMinSize(minWidth = 221.dp)
.align(alignment = Alignment.CenterHorizontally)
) {
@ -133,8 +135,10 @@ private fun NewWaysToConnectDialogContent(
onClick = onNotNowClick,
modifier = Modifier
.padding(
horizontal = dimensionResource(id = R.dimen.core_ui__gutter),
vertical = 36.dp
start = dimensionResource(id = R.dimen.core_ui__gutter),
end = dimensionResource(id = R.dimen.core_ui__gutter),
top = 8.dp,
bottom = 16.dp
)
.defaultMinSize(minWidth = 221.dp)
.align(alignment = Alignment.CenterHorizontally)

View file

@ -2522,7 +2522,7 @@
<!-- Button label for not right now -->
<string name="NewWaysToConnectDialogFragment__not_now">Not now</string>
<!-- Button label for continue -->
<string name="NewWaysToConnectDialogFragment__set_up_your_username">Set up your username</string>
<string name="NewWaysToConnectDialogFragment__set_up_your_username">Set up username</string>
<!-- ThumbnailView -->
<string name="ThumbnailView_Play_video_description">Play video</string>
@ -6176,6 +6176,15 @@
<!-- Displayed as an action on a megaphone which prompts user to set up a username -->
<string name="SetUpYourUsername__learn_more">Learn more</string>
<!-- Displayed as a title on a megaphone which prompts user to set up a username -->
<string name="PnpLaunchMegaphone_title">New ways to connect</string>
<!-- Displayed as a description on a megaphone which prompts user to set up a username -->
<string name="PnpLaunchMegaphone_body">Introducing phone number privacy, optional usernames and links.</string>
<!-- Displayed as an action on a megaphone which prompts user to set up a username. Clicking it will dismiss the megaphone. -->
<string name="PnpLaunchMegaphone_dismiss">Dismiss</string>
<!-- Displayed as an action on a megaphone which prompts user to set up a username. Clicking it will open a link. -->
<string name="PnpLaunchMegaphone_learn_more">Learn more</string>
<!-- Text Formatting -->
<!-- Popup menu label for applying bold style -->
<string name="TextFormatting_bold">Bold</string>