Use user avatar or avatar color for bubble on wallpaper fragment.
This commit is contained in:
parent
4bdd07db16
commit
b8f1b98c74
4 changed files with 49 additions and 12 deletions
|
@ -1,11 +1,7 @@
|
|||
package org.thoughtcrime.securesms.wallpaper;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -29,6 +25,7 @@ import androidx.navigation.Navigation;
|
|||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ColorizerView;
|
||||
import org.thoughtcrime.securesms.util.DisplayMetricsUtil;
|
||||
import org.thoughtcrime.securesms.util.Projection;
|
||||
|
@ -52,7 +49,7 @@ public class ChatWallpaperFragment extends Fragment {
|
|||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
|
||||
|
||||
ImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
|
||||
AvatarImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
|
||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
|
||||
View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
|
||||
|
@ -74,6 +71,9 @@ public class ChatWallpaperFragment extends Fragment {
|
|||
|
||||
forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
|
||||
|
||||
viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(),
|
||||
wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
|
||||
|
||||
viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
|
||||
if (wallpaper.isPresent()) {
|
||||
wallpaper.get().loadInto(chatWallpaperPreview);
|
||||
|
@ -187,8 +187,6 @@ public class ChatWallpaperFragment extends Fragment {
|
|||
Drawable colorCircle = chatColors.asCircle();
|
||||
colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
|
||||
TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
|
||||
|
||||
portrait.setImageDrawable(chatColors.asCircle());
|
||||
});
|
||||
|
||||
sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
|
||||
|
|
|
@ -10,12 +10,14 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
import org.thoughtcrime.securesms.util.MappingModel;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
@ -34,6 +36,7 @@ public class ChatWallpaperViewModel extends ViewModel {
|
|||
private final RecipientId recipientId;
|
||||
private final LiveRecipient liveRecipient;
|
||||
private final RecipientForeverObserver recipientObserver = r -> refreshChatColors();
|
||||
private final LiveData<WallpaperPreviewPortrait> wallpaperPreviewPortrait;
|
||||
|
||||
private ChatWallpaperViewModel(@Nullable RecipientId recipientId) {
|
||||
this.recipientId = recipientId;
|
||||
|
@ -46,8 +49,16 @@ public class ChatWallpaperViewModel extends ViewModel {
|
|||
if (recipientId != null) {
|
||||
liveRecipient = Recipient.live(recipientId);
|
||||
liveRecipient.observeForever(recipientObserver);
|
||||
wallpaperPreviewPortrait = Transformations.map(liveRecipient.getLiveData(), recipient -> {
|
||||
if (recipient.getContactPhoto() != null) {
|
||||
return new WallpaperPreviewPortrait.ContactPhoto(recipient);
|
||||
} else {
|
||||
return new WallpaperPreviewPortrait.SolidColor(recipient.getAvatarColor());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
liveRecipient = null;
|
||||
liveRecipient = null;
|
||||
wallpaperPreviewPortrait = new DefaultValueLiveData<>(new WallpaperPreviewPortrait.SolidColor(AvatarColor.ULTRAMARINE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,15 +128,19 @@ public class ChatWallpaperViewModel extends ViewModel {
|
|||
@NonNull LiveData<Optional<ChatWallpaper>> getCurrentWallpaper() {
|
||||
return wallpaper;
|
||||
}
|
||||
|
||||
|
||||
@NonNull LiveData<ChatColors> getCurrentChatColors() {
|
||||
return chatColors;
|
||||
}
|
||||
|
||||
@NonNull LiveData<WallpaperPreviewPortrait> getWallpaperPreviewPortrait() {
|
||||
return wallpaperPreviewPortrait;
|
||||
}
|
||||
|
||||
@NonNull LiveData<List<MappingModel<?>>> getWallpapers() {
|
||||
return LiveDataUtil.combineLatest(builtins, dimInDarkTheme, (wallpapers, dimInDarkMode) ->
|
||||
Stream.of(wallpapers)
|
||||
.map(paper -> ChatWallpaperFactory.updateWithDimming(paper, dimInDarkMode ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f))
|
||||
Stream.of(wallpapers)
|
||||
.map(paper -> ChatWallpaperFactory.updateWithDimming(paper, dimInDarkMode ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f))
|
||||
.<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package org.thoughtcrime.securesms.wallpaper
|
||||
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
||||
sealed class WallpaperPreviewPortrait {
|
||||
class ContactPhoto(private val recipient: Recipient) : WallpaperPreviewPortrait() {
|
||||
override fun applyToAvatarImageView(avatarImageView: AvatarImageView) {
|
||||
avatarImageView.setAvatar(recipient)
|
||||
avatarImageView.colorFilter = null
|
||||
}
|
||||
}
|
||||
|
||||
class SolidColor(private val avatarColor: AvatarColor) : WallpaperPreviewPortrait() {
|
||||
override fun applyToAvatarImageView(avatarImageView: AvatarImageView) {
|
||||
avatarImageView.setImageResource(R.drawable.circle_tintable)
|
||||
avatarImageView.setColorFilter(avatarColor.colorInt())
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun applyToAvatarImageView(avatarImageView: AvatarImageView)
|
||||
}
|
|
@ -83,7 +83,7 @@
|
|||
app:srcCompat="@drawable/ic_arrow_left_24"
|
||||
app:tint="@color/core_white" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/chat_wallpaper_preview_top_bar_portrait"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
|
|
Loading…
Add table
Reference in a new issue