From 8894908a9d159e9c07a7133ef2924acaeaf179d4 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 22 Apr 2018 16:34:02 +0200 Subject: [PATCH] fix problems with selectable text in detailed status --- .../tusky/adapter/StatusBaseViewHolder.java | 4 +-- .../adapter/StatusDetailedViewHolder.java | 27 ++++++++++++------- .../main/res/layout/item_status_detailed.xml | 2 -- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 4f2bedbf..eea1cc2d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -41,7 +41,6 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { private View container; private TextView displayName; private TextView username; - private TextView content; private ImageButton replyButton; private SparkButton reblogButton; private SparkButton favouriteButton; @@ -59,11 +58,12 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { private TextView sensitiveMediaWarning; private View sensitiveMediaShow; private TextView mediaLabel; - private TextView contentWarningDescription; private ToggleButton contentWarningButton; ImageView avatar; TextView timestampInfo; + TextView content; + TextView contentWarningDescription; StatusBaseViewHolder(View itemView) { super(itemView); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java index 0f504c27..17dcdecb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java @@ -1,5 +1,7 @@ package com.keylesspalace.tusky.adapter; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.os.Build; import android.support.annotation.Nullable; @@ -13,6 +15,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Card; @@ -93,6 +96,20 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { favourites.setText(numberFormat.format(status.getFavouritesCount())); setApplication(status.getApplication()); + View.OnLongClickListener longClickListener = view -> { + TextView textView = (TextView)view; + ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("toot", textView.getText()); + clipboard.setPrimaryClip(clip); + + Toast.makeText(view.getContext(), R.string.copy_to_clipboard_success, Toast.LENGTH_SHORT).show(); + + return true; + }; + + content.setOnLongClickListener(longClickListener); + contentWarningDescription.setOnLongClickListener(longClickListener); + if(status.getAttachments().length == 0 && status.getCard() != null && !TextUtils.isEmpty(status.getCard().getUrl())) { final Card card = status.getCard(); cardView.setVisibility(View.VISIBLE); @@ -134,15 +151,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { cardImage.setVisibility(View.GONE); } - cardView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - LinkHelper.openLink(card.getUrl(), v.getContext()); - - } - - }); + cardView.setOnClickListener(v -> LinkHelper.openLink(card.getUrl(), v.getContext())); } else { cardView.setVisibility(View.GONE); diff --git a/app/src/main/res/layout/item_status_detailed.xml b/app/src/main/res/layout/item_status_detailed.xml index 3dbcb29c..c00b89e9 100644 --- a/app/src/main/res/layout/item_status_detailed.xml +++ b/app/src/main/res/layout/item_status_detailed.xml @@ -59,7 +59,6 @@ android:layout_below="@id/status_name_bar" android:lineSpacingMultiplier="1.1" android:textColor="?android:textColorPrimary" - android:textIsSelectable="true" android:textSize="?attr/status_text_large" tools:text="CW this is a long long long long long long long long content warning" /> @@ -91,7 +90,6 @@ android:focusable="true" android:lineSpacingMultiplier="1.1" android:textColor="?android:textColorPrimary" - android:textIsSelectable="true" android:textSize="?attr/status_text_large" /> Beiträge senden Deine Instanz %s hat keine Emojis definiert - + In die Zwischenablage kopiert diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1a755b72..2b7213a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -302,5 +302,6 @@ A copy of the toot has been saved to your drafts Your instance %s does not have any custom emojis + Copied to clipboard