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
This commit is contained in:
Billy Brawner 2018-11-28 12:46:10 -06:00 committed by Konrad Pozniak
parent 9627d73f68
commit 95a656dc0a
5 changed files with 54 additions and 3 deletions

View file

@ -41,7 +41,7 @@ import at.connyduck.sparkbutton.SparkButton;
import at.connyduck.sparkbutton.SparkEventListener; import at.connyduck.sparkbutton.SparkEventListener;
abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { 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 static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
private TextView displayName; private TextView displayName;
@ -82,13 +82,13 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
moreButton = itemView.findViewById(R.id.status_more); moreButton = itemView.findViewById(R.id.status_more);
reblogged = false; reblogged = false;
favourited = false; favourited = false;
mediaPreviews = new ImageView[] { mediaPreviews = new ImageView[]{
itemView.findViewById(R.id.status_media_preview_0), itemView.findViewById(R.id.status_media_preview_0),
itemView.findViewById(R.id.status_media_preview_1), itemView.findViewById(R.id.status_media_preview_1),
itemView.findViewById(R.id.status_media_preview_2), itemView.findViewById(R.id.status_media_preview_2),
itemView.findViewById(R.id.status_media_preview_3) 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_0),
itemView.findViewById(R.id.status_media_overlay_1), itemView.findViewById(R.id.status_media_overlay_1),
itemView.findViewById(R.id.status_media_overlay_2), itemView.findViewById(R.id.status_media_overlay_2),

View file

@ -3,6 +3,7 @@ package com.keylesspalace.tusky.adapter;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
@ -154,6 +155,51 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
cardView.setVisibility(View.GONE); 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
);
} }
} }

View file

@ -310,6 +310,7 @@
android:layout_below="@id/status_media_preview_container" android:layout_below="@id/status_media_preview_container"
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:drawablePadding="4dp"
android:textColor="?android:textColorTertiary" android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_medium" /> android:textSize="?attr/status_text_medium" />

View file

@ -201,6 +201,8 @@
<item>Público</item> <item>Público</item>
<item>Oculto</item> <item>Oculto</item>
<item>Privado</item> <item>Privado</item>
<item>Directo</item>
<item>Desconocido</item>
</string-array> </string-array>
<string name="pref_status_text_size">Tamaño del texto</string> <string name="pref_status_text_size">Tamaño del texto</string>

View file

@ -210,6 +210,8 @@
<item>Public</item> <item>Public</item>
<item>Unlisted</item> <item>Unlisted</item>
<item>Followers-only</item> <item>Followers-only</item>
<item>Direct</item>
<item>Unknown</item>
</string-array> </string-array>
<string name="pref_status_text_size">Status text size</string> <string name="pref_status_text_size">Status text size</string>