Fix issue where you could have multiple context menus.

Fixes #12149
This commit is contained in:
Greyson Parrelli
2022-04-12 16:59:34 -04:00
parent e143c47c25
commit fae3004512
2 changed files with 14 additions and 5 deletions

View File

@@ -55,10 +55,10 @@ class SignalContextMenu private constructor(
contextMenuList.setItems(items)
}
private fun show() {
private fun show(): SignalContextMenu {
if (anchor.width == 0 || anchor.height == 0) {
anchor.post(this::show)
return
return this
}
contentView.measure(
@@ -107,6 +107,8 @@ class SignalContextMenu private constructor(
}
showAsDropDown(anchor, offsetX, offsetY)
return this
}
enum class HorizontalPosition {
@@ -147,8 +149,8 @@ class SignalContextMenu private constructor(
return this
}
fun show(items: List<ActionItem>) {
SignalContextMenu(
fun show(items: List<ActionItem>): SignalContextMenu {
return SignalContextMenu(
anchor = anchor,
container = container,
items = items,

View File

@@ -212,6 +212,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
private Stub<FrameLayout> voiceNotePlayerViewStub;
private VoiceNotePlayerView voiceNotePlayerView;
private SignalBottomActionBar bottomActionBar;
private SignalContextMenu activeContextMenu;
protected ConversationListArchiveItemDecoration archiveDecoration;
protected ConversationListItemAnimator itemAnimator;
@@ -1140,6 +1141,11 @@ public class ConversationListFragment extends MainFragment implements ActionMode
return true;
}
if (activeContextMenu != null) {
Log.w(TAG, "Already showing a context menu.");
return true;
}
view.setSelected(true);
Collection<Long> id = Collections.singleton(conversation.getThreadRecord().getThreadId());
@@ -1179,10 +1185,11 @@ public class ConversationListFragment extends MainFragment implements ActionMode
items.add(new ActionItem(R.drawable.ic_delete_24, getResources().getQuantityString(R.plurals.ConversationListFragment_delete_plural, 1), () -> handleDelete(id)));
new SignalContextMenu.Builder(view, list)
activeContextMenu = new SignalContextMenu.Builder(view, list)
.offsetX(ViewUtil.dpToPx(12))
.offsetY(ViewUtil.dpToPx(12))
.onDismiss(() -> {
activeContextMenu = null;
view.setSelected(false);
list.suppressLayout(false);
})