mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 13:39:24 +00:00
Update attachment keyboard based on payment availability in CFv2.
This commit is contained in:
@@ -12,9 +12,6 @@ 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;
|
||||
@@ -23,6 +20,8 @@ import org.thoughtcrime.securesms.util.StorageUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AttachmentKeyboard extends FrameLayout implements InputAwareLayout.InputView {
|
||||
|
||||
@@ -94,7 +93,7 @@ public class AttachmentKeyboard extends FrameLayout implements InputAwareLayout.
|
||||
if (buttonPredicate == null) {
|
||||
buttonAdapter.setButtons(DEFAULT_BUTTONS);
|
||||
} else {
|
||||
buttonAdapter.setButtons(Stream.of(DEFAULT_BUTTONS).filter(buttonPredicate).toList());
|
||||
buttonAdapter.setButtons(DEFAULT_BUTTONS.stream().filter(buttonPredicate).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@ import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.conversation.AttachmentKeyboard
|
||||
import org.thoughtcrime.securesms.conversation.AttachmentKeyboardButton
|
||||
import org.thoughtcrime.securesms.conversation.v2.ConversationViewModel
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.mediasend.Media
|
||||
import org.thoughtcrime.securesms.permissions.Permissions
|
||||
import org.thoughtcrime.securesms.util.ViewModelFactory
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
||||
/**
|
||||
* Fragment wrapped version of [AttachmentKeyboard] to help encapsulate logic the view
|
||||
@@ -37,11 +38,10 @@ class AttachmentKeyboardFragment : LoggingFragment(R.layout.attachment_keyboard_
|
||||
const val BUTTON_RESULT = "Button"
|
||||
}
|
||||
|
||||
private val viewModel: AttachmentKeyboardViewModel by viewModels(
|
||||
factoryProducer = ViewModelFactory.factoryProducer { AttachmentKeyboardViewModel() }
|
||||
)
|
||||
private val viewModel: AttachmentKeyboardViewModel by viewModels()
|
||||
|
||||
private lateinit var conversationViewModel: ConversationViewModel
|
||||
private lateinit var attachmentKeyboardView: AttachmentKeyboard
|
||||
|
||||
private val lifecycleDisposable = LifecycleDisposable()
|
||||
|
||||
@@ -50,7 +50,7 @@ class AttachmentKeyboardFragment : LoggingFragment(R.layout.attachment_keyboard_
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
lifecycleDisposable.bindTo(viewLifecycleOwner)
|
||||
|
||||
val attachmentKeyboardView = view.findViewById<AttachmentKeyboard>(R.id.attachment_keyboard)
|
||||
attachmentKeyboardView = view.findViewById(R.id.attachment_keyboard)
|
||||
|
||||
attachmentKeyboardView.setCallback(this)
|
||||
|
||||
@@ -66,6 +66,7 @@ class AttachmentKeyboardFragment : LoggingFragment(R.layout.attachment_keyboard_
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeBy {
|
||||
attachmentKeyboardView.setWallpaperEnabled(it.hasWallpaper())
|
||||
updatePaymentsAvailable(it)
|
||||
}
|
||||
.addTo(lifecycleDisposable)
|
||||
}
|
||||
@@ -85,4 +86,18 @@ class AttachmentKeyboardFragment : LoggingFragment(R.layout.attachment_keyboard_
|
||||
.withPermanentDenialDialog(getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio))
|
||||
.execute()
|
||||
}
|
||||
|
||||
private fun updatePaymentsAvailable(recipient: Recipient) {
|
||||
val paymentsValues = SignalStore.paymentsValues()
|
||||
if (paymentsValues.paymentsAvailability.isSendAllowed &&
|
||||
!recipient.isSelf &&
|
||||
!recipient.isGroup &&
|
||||
recipient.isRegistered &&
|
||||
!recipient.isForceSmsSelection
|
||||
) {
|
||||
attachmentKeyboardView.filterAttachmentKeyboardButtons(null)
|
||||
} else {
|
||||
attachmentKeyboardView.filterAttachmentKeyboardButtons { button -> button != AttachmentKeyboardButton.PAYMENT }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user