Search in sources :

Example 6 with LearnMoreTextView

use of org.thoughtcrime.securesms.util.views.LearnMoreTextView in project Signal-Android by WhisperSystems.

the class EditProfileFragment method initializeResources.

private void initializeResources(@NonNull View view, @Nullable GroupId groupId) {
    Bundle arguments = requireArguments();
    boolean isEditingGroup = groupId != null;
    this.toolbar = view.findViewById(R.id.toolbar);
    this.title = view.findViewById(R.id.title);
    this.avatar = view.findViewById(R.id.avatar);
    this.givenName = view.findViewById(R.id.given_name);
    this.familyName = view.findViewById(R.id.family_name);
    this.finishButton = view.findViewById(R.id.finish_button);
    this.reveal = view.findViewById(R.id.reveal);
    this.preview = view.findViewById(R.id.name_preview);
    this.avatarPreviewBackground = view.findViewById(R.id.avatar_background);
    this.avatarPreview = view.findViewById(R.id.avatar_placeholder);
    this.nextIntent = arguments.getParcelable(NEXT_INTENT);
    this.avatar.setOnClickListener(v -> startAvatarSelection());
    view.findViewById(R.id.mms_group_hint).setVisibility(isEditingGroup && groupId.isMms() ? View.VISIBLE : View.GONE);
    if (isEditingGroup) {
        EditTextUtil.addGraphemeClusterLimitFilter(givenName, FeatureFlags.getMaxGroupNameGraphemeLength());
        givenName.addTextChangedListener(new AfterTextChanged(s -> viewModel.setGivenName(s.toString())));
        givenName.setHint(R.string.EditProfileFragment__group_name);
        givenName.requestFocus();
        toolbar.setTitle(R.string.EditProfileFragment__edit_group);
        preview.setVisibility(View.GONE);
        if (groupId.isV2()) {
            EditTextUtil.addGraphemeClusterLimitFilter(familyName, MAX_DESCRIPTION_GLYPHS);
            familyName.addTextChangedListener(new AfterTextChanged(s -> {
                EditProfileNameFragment.trimFieldToMaxByteLength(s, MAX_DESCRIPTION_BYTES);
                viewModel.setFamilyName(s.toString());
            }));
            familyName.setHint(R.string.EditProfileFragment__group_description);
            familyName.setSingleLine(false);
            familyName.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            LearnMoreTextView descriptionText = view.findViewById(R.id.description_text);
            descriptionText.setLearnMoreVisible(false);
            descriptionText.setText(R.string.CreateProfileActivity_group_descriptions_will_be_visible_to_members_of_this_group_and_people_who_have_been_invited);
        } else {
            familyName.setVisibility(View.GONE);
            familyName.setEnabled(false);
            view.findViewById(R.id.description_text).setVisibility(View.GONE);
        }
        view.<ImageView>findViewById(R.id.avatar_placeholder).setImageResource(R.drawable.ic_group_outline_40);
    } else {
        EditTextUtil.addGraphemeClusterLimitFilter(givenName, EditProfileNameFragment.NAME_MAX_GLYPHS);
        EditTextUtil.addGraphemeClusterLimitFilter(familyName, EditProfileNameFragment.NAME_MAX_GLYPHS);
        this.givenName.addTextChangedListener(new AfterTextChanged(s -> {
            EditProfileNameFragment.trimFieldToMaxByteLength(s);
            viewModel.setGivenName(s.toString());
        }));
        this.familyName.addTextChangedListener(new AfterTextChanged(s -> {
            EditProfileNameFragment.trimFieldToMaxByteLength(s);
            viewModel.setFamilyName(s.toString());
        }));
        LearnMoreTextView descriptionText = view.findViewById(R.id.description_text);
        descriptionText.setLearnMoreVisible(true);
        descriptionText.setOnLinkClickListener(v -> CommunicationActions.openBrowserLink(requireContext(), getString(R.string.EditProfileFragment__support_link)));
    }
    this.finishButton.setOnClickListener(v -> {
        this.finishButton.setIndeterminateProgressMode(true);
        this.finishButton.setProgress(50);
        handleUpload();
    });
    this.finishButton.setText(arguments.getInt(NEXT_BUTTON_TEXT, R.string.CreateProfileActivity_next));
    if (arguments.getBoolean(SHOW_TOOLBAR, true)) {
        this.toolbar.setVisibility(View.VISIBLE);
        this.toolbar.setNavigationOnClickListener(v -> requireActivity().finish());
        this.title.setVisibility(View.GONE);
    }
}
Also used : RequiresApi(androidx.annotation.RequiresApi) AvatarColor(org.thoughtcrime.securesms.conversation.colors.AvatarColor) Bundle(android.os.Bundle) EditTextUtil(org.signal.core.util.EditTextUtil) NonNull(androidx.annotation.NonNull) AvatarPickerFragment(org.thoughtcrime.securesms.avatar.picker.AvatarPickerFragment) ImageView(android.widget.ImageView) SHOW_TOOLBAR(org.thoughtcrime.securesms.profiles.edit.EditProfileActivity.SHOW_TOOLBAR) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) Media(org.thoughtcrime.securesms.mediasend.Media) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) Avatars(org.thoughtcrime.securesms.avatar.Avatars) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) InputType(android.text.InputType) ViewAnimationUtils(android.view.ViewAnimationUtils) ViewGroup(android.view.ViewGroup) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) EXCLUDE_SYSTEM(org.thoughtcrime.securesms.profiles.edit.EditProfileActivity.EXCLUDE_SYSTEM) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) GROUP_ID(org.thoughtcrime.securesms.profiles.edit.EditProfileActivity.GROUP_ID) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) NEXT_BUTTON_TEXT(org.thoughtcrime.securesms.profiles.edit.EditProfileActivity.NEXT_BUTTON_TEXT) Intent(android.content.Intent) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Build(android.os.Build) NEXT_INTENT(org.thoughtcrime.securesms.profiles.edit.EditProfileActivity.NEXT_INTENT) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) CircularProgressButton(com.dd.CircularProgressButton) Parcelable(android.os.Parcelable) LayoutInflater(android.view.LayoutInflater) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) StreamUtil(org.signal.core.util.StreamUtil) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) IOException(java.io.IOException) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) Navigation(androidx.navigation.Navigation) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) EditText(android.widget.EditText) EditProfileNameFragment(org.thoughtcrime.securesms.profiles.manage.EditProfileNameFragment) InputStream(java.io.InputStream) Bundle(android.os.Bundle) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged)

Example 7 with LearnMoreTextView

use of org.thoughtcrime.securesms.util.views.LearnMoreTextView 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)

Aggregations

LearnMoreTextView (org.thoughtcrime.securesms.util.views.LearnMoreTextView)7 Toolbar (androidx.appcompat.widget.Toolbar)6 View (android.view.View)5 TextView (android.widget.TextView)5 Bundle (android.os.Bundle)4 Toast (android.widget.Toast)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 Navigation (androidx.navigation.Navigation)4 R (org.thoughtcrime.securesms.R)4 Context (android.content.Context)3 LayoutInflater (android.view.LayoutInflater)3 ViewGroup (android.view.ViewGroup)3 LoggingFragment (org.thoughtcrime.securesms.LoggingFragment)3 Intent (android.content.Intent)2 EditText (android.widget.EditText)2 ImageView (android.widget.ImageView)2 DiskCacheStrategy (com.bumptech.glide.load.engine.DiskCacheStrategy)2 CircularProgressButton (com.dd.CircularProgressButton)2