Search in sources :

Example 6 with LiveGroup

use of org.thoughtcrime.securesms.groups.LiveGroup in project Signal-Android by signalapp.

the class GroupLinkBottomSheetDialogFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.group_link_share_bottom_sheet, container, false);
    View shareViaSignalButton = view.findViewById(R.id.group_link_bottom_sheet_share_via_signal_button);
    View copyButton = view.findViewById(R.id.group_link_bottom_sheet_copy_button);
    View viewQrButton = view.findViewById(R.id.group_link_bottom_sheet_qr_code_button);
    View shareBySystemButton = view.findViewById(R.id.group_link_bottom_sheet_share_via_system_button);
    TextView hint = view.findViewById(R.id.group_link_bottom_sheet_hint);
    GroupId.V2 groupId = GroupId.parseOrThrow(Objects.requireNonNull(requireArguments().getString(ARG_GROUP_ID))).requireV2();
    LiveGroup liveGroup = new LiveGroup(groupId);
    liveGroup.getGroupLink().observe(getViewLifecycleOwner(), groupLink -> {
        if (!groupLink.isEnabled()) {
            Toast.makeText(requireContext(), R.string.GroupLinkBottomSheet_the_link_is_not_currently_active, Toast.LENGTH_SHORT).show();
            dismiss();
            return;
        }
        hint.setText(groupLink.isRequiresApproval() ? R.string.GroupLinkBottomSheet_share_hint_requiring_approval : R.string.GroupLinkBottomSheet_share_hint_not_requiring_approval);
        hint.setVisibility(View.VISIBLE);
        shareViaSignalButton.setOnClickListener(v -> {
            Context context = requireContext();
            Intent intent = new Intent(context, ShareActivity.class);
            intent.putExtra(Intent.EXTRA_TEXT, groupLink.getUrl());
            context.startActivity(intent);
            dismiss();
        });
        copyButton.setOnClickListener(v -> {
            Context context = requireContext();
            Util.copyToClipboard(context, groupLink.getUrl());
            Toast.makeText(context, R.string.GroupLinkBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
            dismiss();
        });
        viewQrButton.setOnClickListener(v -> {
            GroupLinkShareQrDialogFragment.show(requireFragmentManager(), groupId);
            dismiss();
        });
        shareBySystemButton.setOnClickListener(v -> {
            ShareCompat.IntentBuilder.from(requireActivity()).setType("text/plain").setText(groupLink.getUrl()).startChooser();
            dismiss();
        });
    });
    return view;
}
Also used : LiveGroup(org.thoughtcrime.securesms.groups.LiveGroup) Context(android.content.Context) TextView(android.widget.TextView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Aggregations

LiveGroup (org.thoughtcrime.securesms.groups.LiveGroup)6 View (android.view.View)4 GroupId (org.thoughtcrime.securesms.groups.GroupId)4 Dialog (android.app.Dialog)2 Context (android.content.Context)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 TextUtils (android.text.TextUtils)2 LayoutInflater (android.view.LayoutInflater)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 DialogFragment (androidx.fragment.app.DialogFragment)2 FragmentManager (androidx.fragment.app.FragmentManager)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 List (java.util.List)2 R (org.thoughtcrime.securesms.R)2 EmojiTextView (org.thoughtcrime.securesms.components.emoji.EmojiTextView)2 ParcelableGroupId (org.thoughtcrime.securesms.groups.ParcelableGroupId)2