mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Payments.
Co-authored-by: Alan Evans <alan@signal.org> Co-authored-by: Alex Hart <alex@signal.org> Co-authored-by: Cody Henthorne <cody@signal.org>
This commit is contained in:
@@ -6,13 +6,15 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.annimon.stream.function.Predicate;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.InputAwareLayout;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
@@ -24,6 +26,15 @@ import java.util.List;
|
||||
|
||||
public class AttachmentKeyboard extends FrameLayout implements InputAwareLayout.InputView {
|
||||
|
||||
private static final List<AttachmentKeyboardButton> DEFAULT_BUTTONS = Arrays.asList(
|
||||
AttachmentKeyboardButton.GALLERY,
|
||||
AttachmentKeyboardButton.GIF,
|
||||
AttachmentKeyboardButton.FILE,
|
||||
AttachmentKeyboardButton.PAYMENT,
|
||||
AttachmentKeyboardButton.CONTACT,
|
||||
AttachmentKeyboardButton.LOCATION
|
||||
);
|
||||
|
||||
private View container;
|
||||
private AttachmentKeyboardMediaAdapter mediaAdapter;
|
||||
private AttachmentKeyboardButtonAdapter buttonAdapter;
|
||||
@@ -71,19 +82,21 @@ public class AttachmentKeyboard extends FrameLayout implements InputAwareLayout.
|
||||
mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false));
|
||||
buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
buttonAdapter.setButtons(Arrays.asList(
|
||||
AttachmentKeyboardButton.GALLERY,
|
||||
AttachmentKeyboardButton.GIF,
|
||||
AttachmentKeyboardButton.FILE,
|
||||
AttachmentKeyboardButton.CONTACT,
|
||||
AttachmentKeyboardButton.LOCATION
|
||||
));
|
||||
buttonAdapter.setButtons(DEFAULT_BUTTONS);
|
||||
}
|
||||
|
||||
public void setCallback(@NonNull Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void filterAttachmentKeyboardButtons(@Nullable Predicate<AttachmentKeyboardButton> buttonPredicate) {
|
||||
if (buttonPredicate == null) {
|
||||
buttonAdapter.setButtons(DEFAULT_BUTTONS);
|
||||
} else {
|
||||
buttonAdapter.setButtons(Stream.of(DEFAULT_BUTTONS).filter(buttonPredicate).toList());
|
||||
}
|
||||
}
|
||||
|
||||
public void onMediaChanged(@NonNull List<Media> media) {
|
||||
if (StorageUtil.canReadFromMediaStore()) {
|
||||
mediaAdapter.setMedia(media);
|
||||
|
||||
@@ -10,6 +10,7 @@ public enum AttachmentKeyboardButton {
|
||||
GALLERY(R.string.AttachmentKeyboard_gallery, R.drawable.ic_photo_album_outline_32),
|
||||
GIF(R.string.AttachmentKeyboard_gif, R.drawable.ic_gif_outline_32),
|
||||
FILE(R.string.AttachmentKeyboard_file, R.drawable.ic_file_outline_32),
|
||||
PAYMENT(R.string.AttachmentKeyboard_payment, R.drawable.ic_payments_32),
|
||||
CONTACT(R.string.AttachmentKeyboard_contact, R.drawable.ic_contact_circle_outline_32),
|
||||
LOCATION(R.string.AttachmentKeyboard_location, R.drawable.ic_location_outline_32);
|
||||
|
||||
|
||||
@@ -187,6 +187,7 @@ import org.thoughtcrime.securesms.jobs.GroupV2UpdateSelfProfileKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
||||
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.PaymentsValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||
@@ -221,6 +222,7 @@ import org.thoughtcrime.securesms.mms.SlideFactory.MediaType;
|
||||
import org.thoughtcrime.securesms.mms.StickerSlide;
|
||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.payments.CanNotSendPaymentDialog;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.profiles.spoofing.ReviewBannerView;
|
||||
import org.thoughtcrime.securesms.profiles.spoofing.ReviewCardDialogFragment;
|
||||
@@ -1102,6 +1104,14 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
case LOCATION:
|
||||
AttachmentManager.selectLocation(this, PICK_LOCATION);
|
||||
break;
|
||||
case PAYMENT:
|
||||
if (recipient.get().hasProfileKeyCredential()) {
|
||||
AttachmentManager.selectPayment(this, recipient.getId());
|
||||
} else {
|
||||
CanNotSendPaymentDialog.show(this);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
container.hideCurrentInput(composeText);
|
||||
@@ -1428,6 +1438,9 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
viewModel.getRecentMedia().observe(this, media -> attachmentKeyboardStub.get().onMediaChanged(media));
|
||||
attachmentKeyboardStub.get().setCallback(this);
|
||||
attachmentKeyboardStub.get().setWallpaperEnabled(recipient.get().hasWallpaper());
|
||||
|
||||
updatePaymentsAvailable();
|
||||
|
||||
container.show(composeText, attachmentKeyboardStub.get());
|
||||
|
||||
viewModel.onAttachmentKeyboardOpen();
|
||||
@@ -1437,6 +1450,25 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePaymentsAvailable() {
|
||||
if (!attachmentKeyboardStub.resolved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PaymentsValues paymentsValues = SignalStore.paymentsValues();
|
||||
|
||||
if (paymentsValues.getPaymentsAvailability().isSendAllowed() &&
|
||||
!recipient.get().isSelf() &&
|
||||
!recipient.get().isGroup() &&
|
||||
recipient.get().isRegistered() &&
|
||||
!recipient.get().isForceSmsSelection())
|
||||
{
|
||||
attachmentKeyboardStub.get().filterAttachmentKeyboardButtons(null);
|
||||
} else {
|
||||
attachmentKeyboardStub.get().filterAttachmentKeyboardButtons(btn -> btn != AttachmentKeyboardButton.PAYMENT);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleManualMmsRequired() {
|
||||
Toast.makeText(this, R.string.MmsDownloader_error_reading_mms_settings, Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -2346,6 +2378,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
setBlockedUserState(recipient, isSecureText, isDefaultSms);
|
||||
updateReminders();
|
||||
updateDefaultSubscriptionId(recipient.getDefaultSubscriptionId());
|
||||
updatePaymentsAvailable();
|
||||
initializeSecurity(isSecureText, isDefaultSms);
|
||||
|
||||
if (searchViewItem == null || !searchViewItem.isActionViewExpanded()) {
|
||||
|
||||
Reference in New Issue
Block a user