From 95a656dc0acde671d2ba99927e339ff30bd1085a Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Wed, 28 Nov 2018 12:46:10 -0600 Subject: [PATCH] Add visibility icons to detail statuses (#901) * Add visibility icons to statuses * Remove visibility icons from timeline statuses * Dynamically scale visibility icon according to timestamp font size * Remove visibility icon selection logic from Status model * Migrate visibility icon logic to StatusDetailedViewHolder * Simplify/improve performance of visibility icon layout * Use text size for visibility icon size (instead of view size) * Remove unnecessary LayoutListener * Remove unnecessary visibilityIcon check --- .../tusky/adapter/StatusBaseViewHolder.java | 6 +-- .../adapter/StatusDetailedViewHolder.java | 46 +++++++++++++++++++ .../main/res/layout/item_status_detailed.xml | 1 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 5 files changed, 54 insertions(+), 3 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 4fdc3b2d0..16e7449de 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,7 @@ import at.connyduck.sparkbutton.SparkButton; import at.connyduck.sparkbutton.SparkEventListener; abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { - private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[] { SmartLengthInputFilter.INSTANCE }; + private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE}; private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0]; private TextView displayName; @@ -82,13 +82,13 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { moreButton = itemView.findViewById(R.id.status_more); reblogged = false; favourited = false; - mediaPreviews = new ImageView[] { + mediaPreviews = new ImageView[]{ itemView.findViewById(R.id.status_media_preview_0), itemView.findViewById(R.id.status_media_preview_1), itemView.findViewById(R.id.status_media_preview_2), itemView.findViewById(R.id.status_media_preview_3) }; - mediaOverlays =new ImageView[] { + mediaOverlays = new ImageView[]{ itemView.findViewById(R.id.status_media_overlay_0), itemView.findViewById(R.id.status_media_overlay_1), itemView.findViewById(R.id.status_media_overlay_2), 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 0cc40a7cd..3d817a8e0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java @@ -3,6 +3,7 @@ package com.keylesspalace.tusky.adapter; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.Nullable; import android.text.SpannableStringBuilder; import android.text.Spanned; @@ -154,6 +155,51 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { cardView.setVisibility(View.GONE); } + setStatusVisibility(status.getVisibility()); + } + private void setStatusVisibility(Status.Visibility visibility) { + if (visibility == null || this.timestampInfo == null) { + return; + } + + int visibilityIcon; + switch (visibility) { + case PUBLIC: + visibilityIcon = R.drawable.ic_public_24dp; + break; + case UNLISTED: + visibilityIcon = R.drawable.ic_lock_open_24dp; + break; + case PRIVATE: + visibilityIcon = R.drawable.ic_lock_open_24dp; + break; + case DIRECT: + visibilityIcon = R.drawable.ic_email_24dp; + break; + default: + return; + } + + final Drawable visibilityDrawable = this.timestampInfo.getContext() + .getDrawable(visibilityIcon); + if (visibilityDrawable == null) { + return; + } + + final int size = (int) this.timestampInfo.getTextSize(); + visibilityDrawable.setBounds( + 0, + 0, + size, + size + ); + visibilityDrawable.setTint(this.timestampInfo.getCurrentTextColor()); + this.timestampInfo.setCompoundDrawables( + visibilityDrawable, + null, + null, + null + ); } } diff --git a/app/src/main/res/layout/item_status_detailed.xml b/app/src/main/res/layout/item_status_detailed.xml index d7e4da3b7..f83b905c8 100644 --- a/app/src/main/res/layout/item_status_detailed.xml +++ b/app/src/main/res/layout/item_status_detailed.xml @@ -310,6 +310,7 @@ android:layout_below="@id/status_media_preview_container" android:layout_marginBottom="6dp" android:layout_marginTop="10dp" + android:drawablePadding="4dp" android:textColor="?android:textColorTertiary" android:textSize="?attr/status_text_medium" /> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index edb2d4132..aa4f980b5 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -201,6 +201,8 @@ Público Oculto Privado + Directo + Desconocido Tamaño del texto diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6727633a2..9d8bf0a9f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,6 +210,8 @@ Public Unlisted Followers-only + Direct + Unknown Status text size