Skip to content

Commit

Permalink
Prevent overlay from opening for unopened gifts.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and cody-signal committed Jul 21, 2022
1 parent e03b54a commit 02ea5ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -53,6 +53,10 @@ class OpenableGiftItemDecoration(context: Context) : RecyclerView.ItemDecoration
private val bowHeight = DimensionUnit.DP.toPixels(60f)
private val bowDrawable: Drawable = AppCompatResources.getDrawable(context, R.drawable.ic_gift_bow)!!

fun hasOpenedGiftThisSession(messageRecordId: Long): Boolean {
return messageIdsOpenedThisSession.contains(messageRecordId)
}

override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
animationState.clear()
Expand Down
Expand Up @@ -78,6 +78,7 @@
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.LoggingFragment;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.badges.gifts.OpenableGift;
import org.thoughtcrime.securesms.badges.gifts.OpenableGiftItemDecoration;
import org.thoughtcrime.securesms.badges.gifts.viewgift.received.ViewReceivedGiftBottomSheet;
import org.thoughtcrime.securesms.badges.gifts.viewgift.sent.ViewSentGiftBottomSheet;
Expand Down Expand Up @@ -171,6 +172,7 @@
import org.thoughtcrime.securesms.util.HtmlUtil;
import org.thoughtcrime.securesms.util.LifecycleDisposable;
import org.thoughtcrime.securesms.util.MessageRecordUtil;
import org.thoughtcrime.securesms.util.Projection;
import org.thoughtcrime.securesms.util.RemoteDeleteUtil;
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
import org.thoughtcrime.securesms.util.SignalLocalMetrics;
Expand Down Expand Up @@ -250,6 +252,7 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
private TransitionListener transitionListener;
private View reactionsShade;
private SignalBottomActionBar bottomActionBar;
private OpenableGiftItemDecoration openableGiftItemDecoration;

private GiphyMp4ProjectionRecycler giphyMp4ProjectionRecycler;
private Colorizer colorizer;
Expand Down Expand Up @@ -318,7 +321,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

RecyclerViewColorizer recyclerViewColorizer = new RecyclerViewColorizer(list);

OpenableGiftItemDecoration openableGiftItemDecoration = new OpenableGiftItemDecoration(requireContext());
openableGiftItemDecoration = new OpenableGiftItemDecoration(requireContext());
getViewLifecycleOwner().getLifecycle().addObserver(openableGiftItemDecoration);

list.addItemDecoration(openableGiftItemDecoration);
Expand Down Expand Up @@ -1560,6 +1563,10 @@ public void onItemLongClick(View itemView, MultiselectPart item) {

MessageRecord messageRecord = item.getConversationMessage().getMessageRecord();

if (isUnopenedGift(itemView, messageRecord)) {
return;
}

if (messageRecord.isSecure() &&
!messageRecord.isRemoteDelete() &&
!messageRecord.isUpdate() &&
Expand Down Expand Up @@ -2078,6 +2085,18 @@ public void onGiftBadgeRevealed(@NonNull MessageRecord messageRecord) {
}
}

private boolean isUnopenedGift(View itemView, MessageRecord messageRecord) {
if (itemView instanceof OpenableGift) {
Projection projection = ((OpenableGift) itemView).getOpenableGiftProjection(false);
if (projection != null) {
projection.release();
return !openableGiftItemDecoration.hasOpenedGiftThisSession(messageRecord.getId());
}
}

return false;
}

public void refreshList() {
ConversationAdapter listAdapter = getListAdapter();
if (listAdapter != null) {
Expand Down

0 comments on commit 02ea5ac

Please sign in to comment.