diff --git a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListAdapter.java b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListAdapter.java
index d70a51a2c..3aac28084 100644
--- a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListAdapter.java
+++ b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListAdapter.java
@@ -53,11 +53,6 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
clickListener.onItemClick(getView());
}
});
- getView().getDeleteBtn().setOnClickListener(view -> {
- if (clickListener != null) {
- clickListener.onDeleteButtonClick(getView().getAccountId());
- }
- });
}
public AccountSelectionListItem getView() {
@@ -121,7 +116,6 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
public interface ItemClickListener {
void onItemClick(AccountSelectionListItem item);
- void onDeleteButtonClick(int accountId);
}
public void changeData(int[] ids, int selectedAccountId) {
diff --git a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListFragment.java b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListFragment.java
index a1085d39d..8bc2c940f 100644
--- a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListFragment.java
+++ b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListFragment.java
@@ -4,8 +4,11 @@ import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
+import android.view.ContextMenu;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
+import android.widget.AdapterView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
@@ -35,6 +38,7 @@ public class AccountSelectionListFragment extends DialogFragment
GlideApp.with(getActivity()),
new ListClickListener());
recyclerView.setAdapter(adapter);
+ registerForContextMenu(recyclerView);
DcAccounts accounts = DcHelper.getAccounts(getActivity());
int[] accountIds = accounts.getAll();
@@ -66,6 +70,40 @@ public class AccountSelectionListFragment extends DialogFragment
return builder.setView(view).create();
}
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ requireActivity().getMenuInflater().inflate(R.menu.account_item_context, menu);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
+ switch (item.getItemId()) {
+ case R.id.delete:
+ onDeleteAccount(((AccountSelectionListItem) info.targetView).getAccountId());
+ return true;
+ default:
+ return super.onContextItemSelected(item);
+ }
+ }
+
+ private void onDeleteAccount(int accountId) {
+ Activity activity = getActivity();
+ AccountSelectionListFragment.this.dismiss();
+ if (activity == null) return;
+ DcAccounts accounts = DcHelper.getAccounts(activity);
+ new AlertDialog.Builder(activity)
+ .setTitle(accounts.getAccount(accountId).getNameNAddr())
+ .setMessage(R.string.forget_login_confirmation_desktop)
+ .setNegativeButton(R.string.cancel, (dialog, which) -> AccountManager.getInstance().showSwitchAccountMenu(activity))
+ .setPositiveButton(R.string.ok, (dialog2, which2) -> {
+ DcHelper.getNotificationCenter(activity).removeAllNotifiations(accountId);
+ accounts.removeAccount(accountId);
+ AccountManager.getInstance().showSwitchAccountMenu(activity);
+ })
+ .show();
+ }
private class ListClickListener implements AccountSelectionListAdapter.ItemClickListener {
@@ -80,24 +118,6 @@ public class AccountSelectionListFragment extends DialogFragment
AccountManager.getInstance().switchAccountAndStartActivity(activity, accountId);
}
}
-
- @Override
- public void onDeleteButtonClick(int accountId) {
- Activity activity = getActivity();
- AccountSelectionListFragment.this.dismiss();
- if (activity == null) return;
- DcAccounts accounts = DcHelper.getAccounts(activity);
- new AlertDialog.Builder(activity)
- .setTitle(accounts.getAccount(accountId).getNameNAddr())
- .setMessage(R.string.forget_login_confirmation_desktop)
- .setNegativeButton(R.string.cancel, (dialog, which) -> AccountManager.getInstance().showSwitchAccountMenu(activity))
- .setPositiveButton(R.string.ok, (dialog2, which2) -> {
- DcHelper.getNotificationCenter(activity).removeAllNotifiations(accountId);
- accounts.removeAccount(accountId);
- AccountManager.getInstance().showSwitchAccountMenu(activity);
- })
- .show();
- }
}
}
diff --git a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListItem.java b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListItem.java
index a2daa5cde..d0a58be4f 100644
--- a/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListItem.java
+++ b/src/main/java/org/thoughtcrime/securesms/accounts/AccountSelectionListItem.java
@@ -31,7 +31,6 @@ public class AccountSelectionListItem extends LinearLayout {
private TextView nameView;
private ImageView unreadIndicator;
private ImageView checkbox;
- private ImageButton deleteBtn;
private int accountId;
@@ -52,9 +51,7 @@ public class AccountSelectionListItem extends LinearLayout {
this.nameView = findViewById(R.id.name);
this.unreadIndicator = findViewById(R.id.unread_indicator);
this.checkbox = findViewById(R.id.checkbox);
- this.deleteBtn = findViewById(R.id.delete);
- deleteBtn.setColorFilter(DynamicTheme.isDarkTheme(getContext())? Color.WHITE : Color.BLACK);
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
}
@@ -63,10 +60,8 @@ public class AccountSelectionListItem extends LinearLayout {
Recipient recipient;
if (accountId != DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
- deleteBtn.setVisibility(selected? View.INVISIBLE : View.VISIBLE);
recipient = new Recipient(getContext(), self, name);
} else {
- deleteBtn.setVisibility(View.GONE);
recipient = null;
}
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
@@ -119,10 +114,6 @@ public class AccountSelectionListItem extends LinearLayout {
}
}
- public ImageButton getDeleteBtn() {
- return deleteBtn;
- }
-
public int getAccountId() {
return accountId;
}
diff --git a/src/main/res/layout/account_selection_list_item.xml b/src/main/res/layout/account_selection_list_item.xml
index e7cbc2062..2e7d61630 100644
--- a/src/main/res/layout/account_selection_list_item.xml
+++ b/src/main/res/layout/account_selection_list_item.xml
@@ -90,15 +90,4 @@
android:layout_width="24dp"
android:layout_height="24dp"/>
-