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;
}
Aggregations