Skip to content

Commit

Permalink
Fix sticker manager text wrapping issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Dec 18, 2019
1 parent a352168 commit b6d59f1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 64 deletions.
23 changes: 14 additions & 9 deletions res/layout/sticker_management_empty_item.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/sticker_management_horizontal_margin"
android:layout_marginEnd="@dimen/sticker_management_horizontal_margin">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:src="@drawable/sticker_management_empty_background"
android:tint="?sticker_management_empty_background_color"/>
android:tint="?sticker_management_empty_background_color"
app:layout_constraintTop_toTopOf="@id/sticker_management_empty_text"
app:layout_constraintBottom_toBottomOf="@id/sticker_management_empty_text"/>

<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/sticker_management_empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="13sp"
android:padding="12dp"
style="@style/Signal.Text.Caption"
tools:text="@string/StickerManagementAdapter_no_stickers_installed"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="With great power there must also come -- great responsibility!"/>

<!-- TODO: THEME!! -->

</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
76 changes: 32 additions & 44 deletions res/layout/sticker_management_sticker_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,62 @@
android:layout_width="64dp"
android:layout_height="64dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/sticker_management_divider"
tools:src="@drawable/ic_person_white_24dp"
tools:tint="@color/core_blue"/>

<LinearLayout
android:id="@+id/sticker_management_text_container"
android:id="@+id/sticker_management_title_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="@id/sticker_management_cover"
app:layout_constraintBottom_toBottomOf="@id/sticker_management_cover"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/sticker_management_divider"
app:layout_constraintStart_toEndOf="@id/sticker_management_cover"
app:layout_constraintEnd_toStartOf="@id/sticker_management_share_button">

app:layout_constraintEnd_toStartOf="@id/sticker_management_button_barrier">

<LinearLayout
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/sticker_management_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">

<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/sticker_management_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Signal.Text.Body"
android:maxLines="2"
android:ellipsize="end"
tools:text="Spider-Man"/>

<ImageView
android:id="@+id/sticker_management_blessed_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginTop="1dp"
android:src="@drawable/ic_check_circle_white_18dp"
android:tint="@color/core_blue"/>

<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>

</LinearLayout>
style="@style/Signal.Text.Body"
android:ellipsize="end"
app:emoji_maxLength="45"
tools:text="Spider-Man"/>

<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/sticker_management_author"
style="@style/Signal.Text.Body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Signal.Text.Body"
android:maxLines="2"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/core_grey_60"
tools:text="Peter Parker"/>
tools:text="Peter Parker" />

</LinearLayout>

<androidx.constraintlayout.widget.Barrier
android:id="@+id/sticker_management_button_barrier"
android:layout_width="0dp"
android:layout_height="match_parent"
app:barrierDirection="start"
app:constraint_referenced_ids="sticker_management_action_button,sticker_management_share_button"/>

<View
android:id="@+id/sticker_management_share_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="4dp"
android:background="?sticker_management_icon"
app:layout_constraintEnd_toStartOf="@id/sticker_management_action_button"
app:layout_constraintTop_toTopOf="@id/sticker_management_text_container"
app:layout_constraintBottom_toBottomOf="@id/sticker_management_text_container" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<ImageView
android:id="@+id/sticker_management_share_button_image"
Expand All @@ -100,8 +89,8 @@
android:layout_height="40dp"
android:background="?sticker_management_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/sticker_management_text_container"
app:layout_constraintBottom_toBottomOf="@id/sticker_management_text_container" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<ImageView
android:id="@+id/sticker_management_action_button_image"
Expand All @@ -119,9 +108,8 @@
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?sticker_management_divider_color"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="@id/sticker_management_text_container"
app:layout_constraintTop_toBottomOf="@id/sticker_management_cover"
app:layout_constraintStart_toStartOf="@id/sticker_management_title_container"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,7 +19,9 @@
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
import org.thoughtcrime.securesms.database.model.StickerPackRecord;
import org.thoughtcrime.securesms.jobmanager.Constraint;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.util.FeatureFlags;
Expand Down Expand Up @@ -181,28 +189,28 @@ void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder,

static class StickerViewHolder extends RecyclerView.ViewHolder {

private final ImageView cover;
private final TextView title;
private final TextView author;
private final View badge;
private final View divider;
private final View actionButton;
private final ImageView actionButtonImage;
private final View shareButton;
private final ImageView shareButtonImage;
private final ImageView cover;
private final EmojiTextView title;
private final TextView author;
private final View divider;
private final View actionButton;
private final ImageView actionButtonImage;
private final View shareButton;
private final ImageView shareButtonImage;
private final CharSequence blessedBadge;

StickerViewHolder(@NonNull View itemView) {
super(itemView);

this.cover = itemView.findViewById(R.id.sticker_management_cover);
this.title = itemView.findViewById(R.id.sticker_management_title);
this.author = itemView.findViewById(R.id.sticker_management_author);
this.badge = itemView.findViewById(R.id.sticker_management_blessed_badge);
this.divider = itemView.findViewById(R.id.sticker_management_divider);
this.actionButton = itemView.findViewById(R.id.sticker_management_action_button);
this.actionButtonImage = itemView.findViewById(R.id.sticker_management_action_button_image);
this.shareButton = itemView.findViewById(R.id.sticker_management_share_button);
this.shareButtonImage = itemView.findViewById(R.id.sticker_management_share_button_image);
this.blessedBadge = buildBlessedBadge(itemView.getContext());
}

void bind(@NonNull GlideRequests glideRequests,
Expand All @@ -213,7 +221,12 @@ void bind(@NonNull GlideRequests glideRequests,
title.setText(stickerPack.getTitle().or(itemView.getResources().getString(R.string.StickerManagementAdapter_untitled)));
author.setText(stickerPack.getAuthor().or(itemView.getResources().getString(R.string.StickerManagementAdapter_unknown)));
divider.setVisibility(lastInList ? View.GONE : View.VISIBLE);
badge.setVisibility(BlessedPacks.contains(stickerPack.getPackId()) ? View.VISIBLE : View.GONE);

if (BlessedPacks.contains(stickerPack.getPackId())) {
title.setOverflowText(blessedBadge);
} else {
title.setOverflowText(null);
}

glideRequests.load(new DecryptableUri(stickerPack.getCover().getUri()))
.transition(DrawableTransitionOptions.withCrossFade())
Expand Down Expand Up @@ -243,6 +256,17 @@ void recycle() {
shareButton.setOnClickListener(null);
itemView.setOnClickListener(null);
}

private static @NonNull CharSequence buildBlessedBadge(@NonNull Context context) {
SpannableString badgeSpan = new SpannableString(" ");
Drawable badge = ContextCompat.getDrawable(context, R.drawable.ic_check_circle_white_18dp);

badge.setBounds(0, 0, badge.getIntrinsicWidth(), badge.getIntrinsicHeight());
badge.setColorFilter(ContextCompat.getColor(context, R.color.core_blue), PorterDuff.Mode.MULTIPLY);
badgeSpan.setSpan(new ImageSpan(badge), 1, badgeSpan.length(), 0);

return badgeSpan;
}
}

static class HeaderViewHolder extends RecyclerView.ViewHolder {
Expand Down

0 comments on commit b6d59f1

Please sign in to comment.