Fix responsiveness of profile photo edit UI.

There were various issues around the profile photo updating correctly in
the edit view. We want to make sure that what the user sees there is
what other people are seeing.

So I made some changes to make sure that when you remove your profile
photo the UI updates right away, as well as fixed most flickering
issues.
This commit is contained in:
Greyson Parrelli
2022-03-11 18:35:43 -05:00
committed by Cody Henthorne
parent e7a370a549
commit 78de70881f
6 changed files with 70 additions and 36 deletions

View File

@@ -227,8 +227,7 @@ public final class ProfileUtil {
public static void uploadProfileWithBadges(@NonNull Context context, @NonNull List<Badge> badges) throws IOException {
Log.d(TAG, "uploadProfileWithBadges()");
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
uploadProfile(context,
Recipient.self().getProfileName(),
uploadProfile(Recipient.self().getProfileName(),
Optional.fromNullable(Recipient.self().getAbout()).or(""),
Optional.fromNullable(Recipient.self().getAboutEmoji()).or(""),
getSelfPaymentsAddressProtobuf(),
@@ -245,8 +244,7 @@ public final class ProfileUtil {
public static void uploadProfileWithName(@NonNull Context context, @NonNull ProfileName profileName) throws IOException {
Log.d(TAG, "uploadProfileWithName()");
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
uploadProfile(context,
profileName,
uploadProfile(profileName,
Optional.fromNullable(Recipient.self().getAbout()).or(""),
Optional.fromNullable(Recipient.self().getAboutEmoji()).or(""),
getSelfPaymentsAddressProtobuf(),
@@ -263,8 +261,7 @@ public final class ProfileUtil {
public static void uploadProfileWithAbout(@NonNull Context context, @NonNull String about, @NonNull String emoji) throws IOException {
Log.d(TAG, "uploadProfileWithAbout()");
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
uploadProfile(context,
Recipient.self().getProfileName(),
uploadProfile(Recipient.self().getProfileName(),
about,
emoji,
getSelfPaymentsAddressProtobuf(),
@@ -279,7 +276,7 @@ public final class ProfileUtil {
public static void uploadProfile(@NonNull Context context) throws IOException {
Log.d(TAG, "uploadProfile()");
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
uploadProfileWithAvatar(context, avatar);
uploadProfileWithAvatar(avatar);
}
}
@@ -288,10 +285,9 @@ public final class ProfileUtil {
* avatar instead. This is useful when you want to ensure that the profile has been uploaded
* successfully before persisting the change to disk.
*/
public static void uploadProfileWithAvatar(@NonNull Context context, @Nullable StreamDetails avatar) throws IOException {
public static void uploadProfileWithAvatar(@Nullable StreamDetails avatar) throws IOException {
Log.d(TAG, "uploadProfileWithAvatar()");
uploadProfile(context,
Recipient.self().getProfileName(),
uploadProfile(Recipient.self().getProfileName(),
Optional.fromNullable(Recipient.self().getAbout()).or(""),
Optional.fromNullable(Recipient.self().getAboutEmoji()).or(""),
getSelfPaymentsAddressProtobuf(),
@@ -299,8 +295,7 @@ public final class ProfileUtil {
Recipient.self().getBadges());
}
private static void uploadProfile(@NonNull Context context,
@NonNull ProfileName profileName,
private static void uploadProfile(@NonNull ProfileName profileName,
@Nullable String about,
@Nullable String aboutEmoji,
@Nullable SignalServiceProtos.PaymentAddress paymentsAddress,
@@ -308,7 +303,6 @@ public final class ProfileUtil {
@NonNull List<Badge> badges)
throws IOException
{
List<String> badgeIds = badges.stream()
.filter(Badge::getVisible)
.map(Badge::getId)
@@ -333,6 +327,7 @@ public final class ProfileUtil {
badgeIds).orNull();
SignalStore.registrationValues().markHasUploadedProfile();
SignalDatabase.recipients().setProfileAvatar(Recipient.self().getId(), avatarPath);
ApplicationDependencies.getJobManager().add(new RefreshOwnProfileJob());
}
private static @Nullable SignalServiceProtos.PaymentAddress getSelfPaymentsAddressProtobuf() {