Search in sources :

Example 1 with AvatarImageView

use of org.thoughtcrime.securesms.components.AvatarImageView in project Signal-Android by WhisperSystems.

the class BlockedContactListItem method onModified.

@Override
public void onModified(final Recipients recipients) {
    final AvatarImageView contactPhotoImage = this.contactPhotoImage;
    final TextView nameView = this.nameView;
    Util.runOnMain(new Runnable() {

        @Override
        public void run() {
            contactPhotoImage.setAvatar(recipients, false);
            nameView.setText(recipients.toShortString());
        }
    });
}
Also used : TextView(android.widget.TextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView)

Example 2 with AvatarImageView

use of org.thoughtcrime.securesms.components.AvatarImageView in project Signal-Android by signalapp.

the class BlockedContactListItem method onModified.

@Override
public void onModified(final Recipient recipients) {
    final AvatarImageView contactPhotoImage = this.contactPhotoImage;
    final TextView nameView = this.nameView;
    Util.runOnMain(() -> {
        contactPhotoImage.setAvatar(glideRequests, recipients, false);
        nameView.setText(recipients.toShortString());
    });
}
Also used : TextView(android.widget.TextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView)

Example 3 with AvatarImageView

use of org.thoughtcrime.securesms.components.AvatarImageView in project Signal-Android by WhisperSystems.

the class PaymentDetailsFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_details_toolbar);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
    PaymentDetailsParcelable details = PaymentDetailsFragmentArgs.fromBundle(requireArguments()).getPaymentDetails();
    AvatarImageView avatar = view.findViewById(R.id.payments_details_avatar);
    BadgeImageView badge = view.findViewById(R.id.payments_details_badge);
    TextView contactFromTo = view.findViewById(R.id.payments_details_contact_to_from);
    MoneyView amount = view.findViewById(R.id.payments_details_amount);
    TextView note = view.findViewById(R.id.payments_details_note);
    TextView status = view.findViewById(R.id.payments_details_status);
    View sentByHeader = view.findViewById(R.id.payments_details_sent_by_header);
    TextView sentBy = view.findViewById(R.id.payments_details_sent_by);
    LearnMoreTextView transactionInfo = view.findViewById(R.id.payments_details_info);
    TextView sentTo = view.findViewById(R.id.payments_details_sent_to_header);
    MoneyView sentToAmount = view.findViewById(R.id.payments_details_sent_to_amount);
    View sentFeeHeader = view.findViewById(R.id.payments_details_sent_fee_header);
    MoneyView sentFeeAmount = view.findViewById(R.id.payments_details_sent_fee_amount);
    Group sentViews = view.findViewById(R.id.payments_details_sent_views);
    View blockHeader = view.findViewById(R.id.payments_details_block_header);
    TextView blockNumber = view.findViewById(R.id.payments_details_block);
    if (details.hasPayment()) {
        Payment payment = details.requirePayment();
        avatar.disableQuickContact();
        avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
        contactFromTo.setText(getContactFromToTextFromDirection(payment.getDirection()));
        amount.setMoney(payment.getAmountPlusFeeWithDirection());
        note.setVisibility(View.GONE);
        status.setText(getStatusFromPayment(payment));
        sentByHeader.setVisibility(View.GONE);
        sentBy.setVisibility(View.GONE);
        transactionInfo.setLearnMoreVisible(true);
        transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
        transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
        sentTo.setVisibility(View.GONE);
        sentToAmount.setVisibility(View.GONE);
        blockHeader.setVisibility(View.VISIBLE);
        blockNumber.setVisibility(View.VISIBLE);
        blockNumber.setText(String.valueOf(payment.getBlockIndex()));
        if (payment.getDirection() == Direction.SENT) {
            sentFeeAmount.setMoney(payment.getFee());
            sentFeeHeader.setVisibility(View.VISIBLE);
            sentFeeAmount.setVisibility(View.VISIBLE);
        }
    } else {
        PaymentsDetailsViewModel viewModel = ViewModelProviders.of(this, new PaymentsDetailsViewModel.Factory(details.requireUuid())).get(PaymentsDetailsViewModel.class);
        viewModel.getViewState().observe(getViewLifecycleOwner(), state -> {
            if (state.getRecipient().getId().isUnknown() || state.getPayment().isDefrag()) {
                avatar.disableQuickContact();
                avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
            } else {
                avatar.setRecipient(state.getRecipient(), true);
                badge.setBadgeFromRecipient(state.getRecipient());
            }
            contactFromTo.setText(describeToOrFrom(state));
            if (state.getPayment().getState() == State.FAILED) {
                amount.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_text_primary_disabled));
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection(), false);
                transactionInfo.setVisibility(View.GONE);
            } else {
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection());
                if (state.getPayment().isDefrag()) {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__coin_cleanup_information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__cleanup_fee));
                } else {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
                }
                transactionInfo.setVisibility(View.VISIBLE);
            }
            String trimmedNote = state.getPayment().getNote().trim();
            note.setText(trimmedNote);
            note.setVisibility(TextUtils.isEmpty(trimmedNote) ? View.GONE : View.VISIBLE);
            status.setText(describeStatus(state.getPayment()));
            sentBy.setText(describeSentBy(state));
            if (state.getPayment().getDirection().isReceived()) {
                sentToAmount.setMoney(Money.MobileCoin.ZERO);
                sentFeeAmount.setMoney(Money.MobileCoin.ZERO);
                sentViews.setVisibility(View.GONE);
            } else {
                sentTo.setText(describeSentTo(state, state.getPayment()));
                sentToAmount.setMoney(state.getPayment().getAmount());
                sentFeeAmount.setMoney(state.getPayment().getFee());
                sentViews.setVisibility(View.VISIBLE);
            }
        });
        viewModel.getPaymentExists().observe(getViewLifecycleOwner(), exists -> {
            if (!exists) {
                Log.w(TAG, "Failed to find payment detail");
                FragmentActivity fragmentActivity = requireActivity();
                fragmentActivity.onBackPressed();
                Toast.makeText(fragmentActivity, R.string.PaymentsDetailsFragment__no_details_available, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : Group(androidx.constraintlayout.widget.Group) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) SpannableString(android.text.SpannableString) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) FragmentActivity(androidx.fragment.app.FragmentActivity) Payment(org.thoughtcrime.securesms.payments.Payment) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 4 with AvatarImageView

use of org.thoughtcrime.securesms.components.AvatarImageView in project Signal-Android by WhisperSystems.

the class ChatWallpaperFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
    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);
    SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
    View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
    TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
    TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
    ImageView sentBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_2);
    ColorizerView colorizerView = view.findViewById(R.id.colorizer);
    TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
    AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
    toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
    toolbar.setNavigationOnClickListener(nav -> {
        if (!Navigation.findNavController(nav).popBackStack()) {
            requireActivity().finish();
        }
    });
    forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
    viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(), wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
    viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
        if (wallpaper.isPresent()) {
            wallpaper.get().loadInto(chatWallpaperPreview);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.conversation_item_wallpaper_bubble_color)));
        } else {
            chatWallpaperPreview.setImageDrawable(null);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary)));
        }
    });
    viewModel.getDimInDarkTheme().observe(getViewLifecycleOwner(), shouldDimInNightMode -> {
        if (shouldDimInNightMode != dimInNightMode.isChecked()) {
            isSettingDimFromViewModel = true;
            dimInNightMode.setChecked(shouldDimInNightMode);
            isSettingDimFromViewModel = false;
        }
        chatWallpaperDim.setAlpha(ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME);
        chatWallpaperDim.setVisibility(shouldDimInNightMode && ThemeUtil.isDarkTheme(requireContext()) ? View.VISIBLE : View.GONE);
    });
    viewModel.getEnableWallpaperControls().observe(getViewLifecycleOwner(), enableWallpaperControls -> {
        dimInNightMode.setEnabled(enableWallpaperControls);
        dimInNightMode.setAlpha(enableWallpaperControls ? 1 : 0.5f);
    });
    chatWallpaperPreview.setOnClickListener(unused -> setWallpaper.performClick());
    setWallpaper.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), R.id.action_chatWallpaperFragment_to_chatWallpaperSelectionFragment));
    setChatColor.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), ChatWallpaperFragmentDirections.actionChatWallpaperFragmentToChatColorSelectionFragment(viewModel.getRecipientId())));
    if (viewModel.isGlobal()) {
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_wallpaper).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_wallpapers).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_wallpaper, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_wallpapers, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.resetAllWallpaper();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_chat_colors).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_chat_colors).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_colors, (dialog, which) -> {
                viewModel.clearChatColor();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_colors, (dialog, which) -> {
                viewModel.resetAllChatColors();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
    } else {
        resetAllWallpaper.setText(R.string.ChatWallpaperFragment__reset_wallpaper);
        resetChatColors.setText(R.string.ChatWallpaperFragment__reset_chat_color);
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_wallpaper_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                viewModel.refreshChatColors();
            }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_chat_color_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> viewModel.clearChatColor()).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
    }
    dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (!isSettingDimFromViewModel) {
            viewModel.setDimInDarkTheme(isChecked);
        }
    });
    viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
        sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
        colorizerView.setBackground(chatColors.getChatBubbleMask());
        Projection projection = Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(10)));
        colorizerView.setProjections(Collections.singletonList(projection));
        Drawable colorCircle = chatColors.asCircle();
        colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
        TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
    });
    sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DisplayMetricsUtil(org.thoughtcrime.securesms.util.DisplayMetricsUtil) ColorStateList(android.content.res.ColorStateList) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ContextCompat(androidx.core.content.ContextCompat) SwitchCompat(androidx.appcompat.widget.SwitchCompat) LayoutInflater(android.view.LayoutInflater) ImageViewCompat(androidx.core.widget.ImageViewCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) Drawable(android.graphics.drawable.Drawable) Projection(org.thoughtcrime.securesms.util.Projection) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Toolbar(androidx.appcompat.widget.Toolbar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 5 with AvatarImageView

use of org.thoughtcrime.securesms.components.AvatarImageView in project Signal-Android by WhisperSystems.

the class InsightsModalDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    View close = view.findViewById(R.id.insights_modal_close);
    Button viewInsights = view.findViewById(R.id.insights_modal_view_insights);
    progress = view.findViewById(R.id.insights_modal_progress);
    securePercentage = view.findViewById(R.id.insights_modal_percent_secure);
    avatarImageView = view.findViewById(R.id.insights_modal_avatar);
    progressContainer = view.findViewById(R.id.insights_modal_percent_container);
    close.setOnClickListener(v -> dismiss());
    viewInsights.setOnClickListener(v -> openInsightsAndDismiss());
    initializeViewModel();
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView)

Aggregations

TextView (android.widget.TextView)5 AvatarImageView (org.thoughtcrime.securesms.components.AvatarImageView)5 View (android.view.View)3 Toolbar (androidx.appcompat.widget.Toolbar)2 ColorStateList (android.content.res.ColorStateList)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 SpannableString (android.text.SpannableString)1 DisplayMetrics (android.util.DisplayMetrics)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)1 SwitchCompat (androidx.appcompat.widget.SwitchCompat)1 Group (androidx.constraintlayout.widget.Group)1 ContextCompat (androidx.core.content.ContextCompat)1 ImageViewCompat (androidx.core.widget.ImageViewCompat)1