mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
repace trash icon in profile switcher with context menu
This commit is contained in:
@@ -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) {
|
||||
|
||||
+38
-18
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user