Skip to content

Commit

Permalink
Add ability to copy a number via long-press.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jun 7, 2020
1 parent f6637b7 commit 6932340
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Expand Up @@ -22,6 +22,7 @@
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -77,8 +78,10 @@
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
Expand Down Expand Up @@ -728,6 +731,15 @@ public void onSecureVideoClicked() {
public void onInSecureCallClicked() {
CommunicationActions.startInsecureCall(requireActivity(), recipient.get());
}

@Override
public void onLongClick() {
if (recipient.get().hasE164()) {
Util.copyToClipboard(requireContext(), recipient.get().requireE164());
ServiceUtil.getVibrator(requireContext()).vibrate(250);
Toast.makeText(requireContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}
}

private class CustomNotificationsChangedListener implements Preference.OnPreferenceChangeListener {
Expand Down
Expand Up @@ -17,6 +17,7 @@ public class ContactPreference extends Preference {
private ImageView callButton;
private ImageView secureCallButton;
private ImageView secureVideoButton;
private View itemView;

private Listener listener;
private boolean secure;
Expand Down Expand Up @@ -50,6 +51,7 @@ private void initialize() {
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);

this.itemView = view.itemView;
this.messageButton = (ImageView) view.findViewById(R.id.message);
this.callButton = (ImageView) view.findViewById(R.id.call);
this.secureCallButton = (ImageView) view.findViewById(R.id.secure_call);
Expand Down Expand Up @@ -88,13 +90,21 @@ public void setListener(Listener listener) {
if (this.secureCallButton != null) this.secureCallButton.setOnClickListener(v -> listener.onSecureCallClicked());
if (this.secureVideoButton != null) this.secureVideoButton.setOnClickListener(v -> listener.onSecureVideoClicked());
if (this.callButton != null) this.callButton.setOnClickListener(v -> listener.onInSecureCallClicked());

if (this.itemView != null) {
itemView.setOnLongClickListener(v -> {
listener.onLongClick();
return true;
});
}
}

public interface Listener {
public void onMessageClicked();
public void onSecureCallClicked();
public void onSecureVideoClicked();
public void onInSecureCallClicked();
void onMessageClicked();
void onSecureCallClicked();
void onSecureVideoClicked();
void onInSecureCallClicked();
void onLongClick();
}

}
Expand Up @@ -8,6 +8,7 @@
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -20,7 +21,9 @@
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.groups.GroupId;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;

import java.util.Objects;

Expand Down Expand Up @@ -110,6 +113,12 @@ public void onViewCreated(@NonNull View fragmentView, @Nullable Bundle savedInst
.trim();
usernameNumber.setText(usernameNumberString);
usernameNumber.setVisibility(TextUtils.isEmpty(usernameNumberString) ? View.GONE : View.VISIBLE);
usernameNumber.setOnLongClickListener(v -> {
Util.copyToClipboard(v.getContext(), usernameNumber.getText().toString());
ServiceUtil.getVibrator(v.getContext()).vibrate(250);
Toast.makeText(v.getContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
return true;
});

boolean blocked = recipient.isBlocked();
blockButton.setVisibility(blocked ? View.GONE : View.VISIBLE);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -2312,6 +2312,7 @@

<string name="RecipientBottomSheet_remove_s_from_s">Remove %1$s from "%2$s"?</string>
<string name="RecipientBottomSheet_remove">Remove</string>
<string name="RecipientBottomSheet_copied_to_clipboard">Copied to clipboard</string>

<string name="GroupRecipientListItem_admin">Admin</string>

Expand Down

0 comments on commit 6932340

Please sign in to comment.