use of org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto in project Signal-Android by signalapp.
the class SingleRecipientNotificationBuilder method setThread.
public void setThread(@NonNull Recipient recipient) {
if (privacy.isDisplayContact()) {
setContentTitle(recipient.toShortString());
if (recipient.getContactUri() != null) {
addPerson(recipient.getContactUri().toString());
}
ContactPhoto contactPhoto = recipient.getContactPhoto();
FallbackContactPhoto fallbackContactPhoto = recipient.getFallbackContactPhoto();
if (contactPhoto != null) {
try {
setLargeIcon(GlideApp.with(context.getApplicationContext()).load(contactPhoto).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().submit(context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height)).get());
} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getColor().toConversationColor(context)));
}
} else {
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getColor().toConversationColor(context)));
}
} else {
setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal));
setLargeIcon(new GeneratedContactPhoto("Unknown").asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context)));
}
}
use of org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto in project Signal-Android by WhisperSystems.
the class RecipientBottomSheetDialogFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View fragmentView, @Nullable Bundle savedInstanceState) {
super.onViewCreated(fragmentView, savedInstanceState);
Bundle arguments = requireArguments();
RecipientId recipientId = RecipientId.from(Objects.requireNonNull(arguments.getString(ARGS_RECIPIENT_ID)));
GroupId groupId = GroupId.parseNullableOrThrow(arguments.getString(ARGS_GROUP_ID));
RecipientDialogViewModel.Factory factory = new RecipientDialogViewModel.Factory(requireContext().getApplicationContext(), recipientId, groupId);
viewModel = ViewModelProviders.of(this, factory).get(RecipientDialogViewModel.class);
viewModel.getRecipient().observe(getViewLifecycleOwner(), recipient -> {
interactionsContainer.setVisibility(recipient.isSelf() ? View.GONE : View.VISIBLE);
avatar.setFallbackPhotoProvider(new Recipient.FallbackPhotoProvider() {
@Override
@NonNull
public FallbackContactPhoto getPhotoForLocalNumber() {
return new FallbackPhoto80dp(R.drawable.ic_note_80, recipient.getAvatarColor());
}
});
avatar.setAvatar(recipient);
if (!recipient.isSelf()) {
badgeImageView.setBadgeFromRecipient(recipient);
}
if (recipient.isSelf()) {
avatar.setOnClickListener(v -> {
dismiss();
viewModel.onMessageClicked(requireActivity());
});
}
String name = recipient.isSelf() ? requireContext().getString(R.string.note_to_self) : recipient.getDisplayName(requireContext());
fullName.setVisibility(TextUtils.isEmpty(name) ? View.GONE : View.VISIBLE);
SpannableStringBuilder nameBuilder = new SpannableStringBuilder(name);
if (recipient.isSystemContact() && !recipient.isSelf()) {
Drawable systemContact = DrawableUtil.tint(ContextUtil.requireDrawable(requireContext(), R.drawable.ic_profile_circle_outline_16), ContextCompat.getColor(requireContext(), R.color.signal_text_primary));
SpanUtil.appendCenteredImageSpan(nameBuilder, systemContact, 16, 16);
} else if (recipient.isReleaseNotes()) {
SpanUtil.appendCenteredImageSpan(nameBuilder, ContextUtil.requireDrawable(requireContext(), R.drawable.ic_official_28), 28, 28);
}
fullName.setText(nameBuilder);
String aboutText = recipient.getCombinedAboutAndEmoji();
if (recipient.isReleaseNotes()) {
aboutText = getString(R.string.ReleaseNotes__signal_release_notes_and_news);
}
if (!Util.isEmpty(aboutText)) {
about.setText(aboutText);
about.setVisibility(View.VISIBLE);
} else {
about.setVisibility(View.GONE);
}
String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext()) && !recipient.isSelf() ? recipient.getSmsAddress().transform(PhoneNumberFormatter::prettyPrint).or("").trim() : "";
usernameNumber.setText(usernameNumberString);
usernameNumber.setVisibility(TextUtils.isEmpty(usernameNumberString) ? View.GONE : View.VISIBLE);
usernameNumber.setOnLongClickListener(v -> {
Util.copyToClipboard(v.getContext(), usernameNumber.getText().toString());
ServiceUtil.getVibrator(v.getContext()).vibrate(250);
Toast.makeText(v.getContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
return true;
});
noteToSelfDescription.setVisibility(recipient.isSelf() ? View.VISIBLE : View.GONE);
if (RecipientUtil.isBlockable(recipient)) {
boolean blocked = recipient.isBlocked();
blockButton.setVisibility(recipient.isSelf() || blocked ? View.GONE : View.VISIBLE);
unblockButton.setVisibility(recipient.isSelf() || !blocked ? View.GONE : View.VISIBLE);
} else {
blockButton.setVisibility(View.GONE);
unblockButton.setVisibility(View.GONE);
}
ButtonStripPreference.State buttonStripState = new ButtonStripPreference.State(/* isMessageAvailable = */
!recipient.isBlocked() && !recipient.isSelf() && !recipient.isReleaseNotes(), /* isVideoAvailable = */
!recipient.isBlocked() && !recipient.isSelf() && recipient.isRegistered(), /* isAudioAvailable = */
!recipient.isBlocked() && !recipient.isSelf() && !recipient.isReleaseNotes(), /* isMuteAvailable = */
false, /* isSearchAvailable = */
false, /* isAudioSecure = */
recipient.isRegistered(), /* isMuted = */
false);
ButtonStripPreference.Model buttonStripModel = new ButtonStripPreference.Model(buttonStripState, DSLSettingsIcon.from(ContextUtil.requireDrawable(requireContext(), R.drawable.selectable_recipient_bottom_sheet_icon_button)), () -> {
dismiss();
viewModel.onMessageClicked(requireActivity());
return Unit.INSTANCE;
}, () -> {
viewModel.onSecureVideoCallClicked(requireActivity());
return Unit.INSTANCE;
}, () -> {
if (buttonStripState.isAudioSecure()) {
viewModel.onSecureCallClicked(requireActivity());
} else {
viewModel.onInsecureCallClicked(requireActivity());
}
return Unit.INSTANCE;
}, () -> Unit.INSTANCE, () -> Unit.INSTANCE);
new ButtonStripPreference.ViewHolder(buttonStrip).bind(buttonStripModel);
if (recipient.isReleaseNotes()) {
buttonStrip.setVisibility(View.GONE);
}
if (recipient.isSystemContact() || recipient.isGroup() || recipient.isSelf() || recipient.isBlocked() || recipient.isReleaseNotes()) {
addContactButton.setVisibility(View.GONE);
} else {
addContactButton.setVisibility(View.VISIBLE);
addContactButton.setOnClickListener(v -> {
openSystemContactSheet(RecipientExporter.export(recipient).asAddContactIntent());
});
}
if (recipient.isSystemContact() && !recipient.isGroup() && !recipient.isSelf()) {
contactDetailsButton.setVisibility(View.VISIBLE);
contactDetailsButton.setOnClickListener(v -> {
openSystemContactSheet(new Intent(Intent.ACTION_VIEW, recipient.getContactUri()));
});
} else {
contactDetailsButton.setVisibility(View.GONE);
}
});
viewModel.getCanAddToAGroup().observe(getViewLifecycleOwner(), canAdd -> {
addToGroupButton.setText(groupId == null ? R.string.RecipientBottomSheet_add_to_a_group : R.string.RecipientBottomSheet_add_to_another_group);
addToGroupButton.setVisibility(canAdd ? View.VISIBLE : View.GONE);
});
viewModel.getAdminActionStatus().observe(getViewLifecycleOwner(), adminStatus -> {
makeGroupAdminButton.setVisibility(adminStatus.isCanMakeAdmin() ? View.VISIBLE : View.GONE);
removeAdminButton.setVisibility(adminStatus.isCanMakeNonAdmin() ? View.VISIBLE : View.GONE);
removeFromGroupButton.setVisibility(adminStatus.isCanRemove() ? View.VISIBLE : View.GONE);
});
viewModel.getIdentity().observe(getViewLifecycleOwner(), identityRecord -> {
viewSafetyNumberButton.setVisibility(identityRecord != null ? View.VISIBLE : View.GONE);
if (identityRecord != null) {
viewSafetyNumberButton.setOnClickListener(view -> {
dismiss();
viewModel.onViewSafetyNumberClicked(requireActivity(), identityRecord);
});
}
});
avatar.setOnClickListener(view -> {
dismiss();
viewModel.onAvatarClicked(requireActivity());
});
badgeImageView.setOnClickListener(view -> {
dismiss();
ViewBadgeBottomSheetDialogFragment.show(getParentFragmentManager(), recipientId, null);
});
blockButton.setOnClickListener(view -> viewModel.onBlockClicked(requireActivity()));
unblockButton.setOnClickListener(view -> viewModel.onUnblockClicked(requireActivity()));
makeGroupAdminButton.setOnClickListener(view -> viewModel.onMakeGroupAdminClicked(requireActivity()));
removeAdminButton.setOnClickListener(view -> viewModel.onRemoveGroupAdminClicked(requireActivity()));
removeFromGroupButton.setOnClickListener(view -> viewModel.onRemoveFromGroupClicked(requireActivity(), this::dismiss));
addToGroupButton.setOnClickListener(view -> {
dismiss();
viewModel.onAddToGroupButton(requireActivity());
});
viewModel.getAdminActionBusy().observe(getViewLifecycleOwner(), busy -> {
adminActionBusy.setVisibility(busy ? View.VISIBLE : View.GONE);
makeGroupAdminButton.setEnabled(!busy);
removeAdminButton.setEnabled(!busy);
removeFromGroupButton.setEnabled(!busy);
});
}
use of org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto in project Signal-Android by WhisperSystems.
the class CallParticipantView method setPipAvatar.
private void setPipAvatar(@NonNull Recipient recipient) {
ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar()) : recipient.getContactPhoto();
FallbackContactPhoto fallbackPhoto = recipient.getFallbackContactPhoto(FALLBACK_PHOTO_PROVIDER);
GlideApp.with(this).load(contactPhoto).fallback(fallbackPhoto.asCallCard(getContext())).error(fallbackPhoto.asCallCard(getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(pipAvatar);
pipAvatar.setScaleType(contactPhoto == null ? ImageView.ScaleType.CENTER_INSIDE : ImageView.ScaleType.CENTER_CROP);
ChatColors chatColors = recipient.getChatColors();
pipAvatar.setBackground(chatColors.getChatBubbleMask());
}
use of org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto in project Signal-Android by WhisperSystems.
the class AvatarPreviewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
super.onCreate(savedInstanceState, ready);
setTheme(R.style.TextSecure_MediaPreview);
setContentView(R.layout.contact_photo_preview_activity);
if (Build.VERSION.SDK_INT >= 21) {
postponeEnterTransition();
TransitionInflater inflater = TransitionInflater.from(this);
getWindow().setSharedElementEnterTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_enter_transition_set));
getWindow().setSharedElementReturnTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_return_transition_set));
}
Toolbar toolbar = findViewById(R.id.toolbar);
EmojiTextView title = findViewById(R.id.title);
ImageView avatar = findViewById(R.id.avatar);
setSupportActionBar(toolbar);
requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
requireSupportActionBar().setDisplayShowTitleEnabled(false);
Context context = getApplicationContext();
RecipientId recipientId = RecipientId.from(getIntent().getStringExtra(RECIPIENT_ID_EXTRA));
Recipient.live(recipientId).observe(this, recipient -> {
ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar()) : recipient.getContactPhoto();
FallbackContactPhoto fallbackPhoto = recipient.isSelf() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large) : recipient.getFallbackContactPhoto();
Resources resources = this.getResources();
GlideApp.with(this).asBitmap().load(contactPhoto).fallback(fallbackPhoto.asCallCard(this)).error(fallbackPhoto.asCallCard(this)).diskCacheStrategy(DiskCacheStrategy.ALL).addListener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
Log.w(TAG, "Unable to load avatar, or avatar removed, closing");
finish();
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
avatar.setImageDrawable(RoundedBitmapDrawableFactory.create(resources, resource));
if (Build.VERSION.SDK_INT >= 21) {
startPostponedEnterTransition();
}
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
title.setText(recipient.getDisplayName(context));
});
FullscreenHelper fullscreenHelper = new FullscreenHelper(this);
findViewById(android.R.id.content).setOnClickListener(v -> fullscreenHelper.toggleUiVisibility());
fullscreenHelper.configureToolbarSpacer(findViewById(R.id.toolbar_cutout_spacer));
fullscreenHelper.showAndHideWithSystemUI(getWindow(), findViewById(R.id.toolbar_layout));
}
Aggregations