offer copy-to-clipboard on long-tap address

This commit is contained in:
B. Petersen 2025-07-05 11:47:20 +02:00
parent 1f1859a823
commit 92570b8e1e
3 changed files with 38 additions and 0 deletions

View file

@ -211,6 +211,9 @@ public class ProfileAdapter extends RecyclerView.Adapter
if (data.viewType == ITEM_LAST_SEEN || data.viewType == ITEM_ADDRESS) {
int padding = (int)((float)context.getResources().getDimensionPixelSize(R.dimen.contact_list_normal_padding) * 1.2);
item.setPadding(item.getPaddingLeft(), item.getPaddingTop(), item.getPaddingRight(), padding);
if (data.viewType == ITEM_ADDRESS) {
item.setOnLongClickListener(view -> {clickListener.onAddressLongClicked(); return true;});
}
} else if (data.viewType == ITEM_INTRODUCED_BY) {
int padding = context.getResources().getDimensionPixelSize(R.dimen.contact_list_normal_padding);
item.setPadding(item.getPaddingLeft(), padding, item.getPaddingRight(), item.getPaddingBottom());
@ -235,6 +238,7 @@ public class ProfileAdapter extends RecyclerView.Adapter
void onMemberClicked(int contactId);
void onMemberLongClicked(int contactId);
void onAvatarClicked();
void onAddressLongClicked();
}
public void toggleMemberSelection(int contactId) {

View file

@ -153,6 +153,23 @@ public class ProfileFragment extends Fragment
.show();
}
@Override
public void onAddressLongClicked() {
Context context = requireContext();
String address = dcContext.getContact(contactId).getAddr();
new AlertDialog.Builder(context)
.setTitle(address)
.setItems(new CharSequence[]{
context.getString(R.string.menu_copy_to_clipboard)
},
(dialogInterface, i) -> {
Util.writeTextToClipboard(context, address);
Toast.makeText(context, context.getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
})
.setNegativeButton(R.string.cancel, null)
.show();
}
@Override
public void onMemberLongClicked(int contactId) {
if (contactId>DcContact.DC_CONTACT_ID_LAST_SPECIAL || contactId==DcContact.DC_CONTACT_ID_SELF) {

View file

@ -18,6 +18,7 @@ public class ProfileTextItem extends LinearLayout {
private TextView labelView;
private @Nullable TextView valueView;
private final ProfileTextItem.PassthroughClickListener passthroughClickListener = new ProfileTextItem.PassthroughClickListener();
public ProfileTextItem(Context context) {
super(context);
@ -31,6 +32,8 @@ public class ProfileTextItem extends LinearLayout {
protected void onFinishInflate() {
super.onFinishInflate();
labelView = findViewById(R.id.label);
labelView.setOnLongClickListener(passthroughClickListener);
labelView.setOnClickListener(passthroughClickListener);
valueView = findViewById(R.id.value);
}
@ -54,4 +57,18 @@ public class ProfileTextItem extends LinearLayout {
valueView.setVisibility(View.VISIBLE);
}
}
private class PassthroughClickListener implements View.OnLongClickListener, View.OnClickListener {
@Override
public boolean onLongClick(View v) {
performLongClick();
return true;
}
@Override
public void onClick(View v) {
performClick();
}
}
}