From 240fb372ba723c75495b77c579cc2a42f8525c93 Mon Sep 17 00:00:00 2001 From: Ivan Kupalov Date: Fri, 14 Jul 2017 08:06:32 +0300 Subject: [PATCH] Add small avatars to boosted toots and to notifications. --- .../tusky/adapter/NotificationsAdapter.java | 42 +++++++++ .../tusky/adapter/StatusViewHolder.java | 45 +++++++--- .../tusky/util/ViewDataUtils.java | 2 +- app/src/main/res/layout/item_status.xml | 27 ++++-- .../res/layout/item_status_notification.xml | 87 ++++++++++++------- 5 files changed, 153 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index fbc6c673..65706978 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -16,6 +16,8 @@ package com.keylesspalace.tusky.adapter; import android.content.Context; +import android.graphics.Color; +import android.graphics.PorterDuff; import android.graphics.Typeface; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; @@ -32,9 +34,11 @@ import android.widget.TextView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Notification; import com.keylesspalace.tusky.interfaces.StatusActionListener; +import com.keylesspalace.tusky.view.RoundedTransformation; import com.keylesspalace.tusky.viewdata.NotificationViewData; import com.keylesspalace.tusky.viewdata.StatusViewData; import com.squareup.picasso.Picasso; +import com.varunest.sparkbutton.helpers.Utils; import java.util.ArrayList; import java.util.List; @@ -107,6 +111,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter { holder.setMessage(type, notification.getAccount().getDisplayName(), notification.getStatusViewData()); holder.setupButtons(notificationActionListener, notification.getAccount().id); + holder.setAvatars(notification.getStatusViewData().getAvatar(), + notification.getAccount().avatar); break; } case FOLLOW: { @@ -216,6 +222,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter { Picasso.with(context) .load(avatarUrl) + .fit() + .transform(new RoundedTransformation(7, 0)) .placeholder(R.drawable.avatar_default) .error(R.drawable.avatar_error) .into(avatar); @@ -236,6 +244,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter { private ImageView icon; private TextView statusContent; private ViewGroup container; + private ImageView statusAvatar; + private ImageView notificationAvatar; StatusNotificationViewHolder(View itemView) { super(itemView); @@ -243,6 +253,12 @@ public class NotificationsAdapter extends RecyclerView.Adapter { icon = (ImageView) itemView.findViewById(R.id.notification_icon); statusContent = (TextView) itemView.findViewById(R.id.notification_content); container = (ViewGroup) itemView.findViewById(R.id.notification_container); + statusAvatar = (ImageView) itemView.findViewById(R.id.notification_status_avatar); + notificationAvatar = (ImageView) + itemView.findViewById(R.id.notification_notification_avatar); + int darkerFilter = Color.rgb(123, 123, 123); + statusAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY); + notificationAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY); } void setMessage(Notification.Type type, String displayName, StatusViewData status) { @@ -281,5 +297,31 @@ public class NotificationsAdapter extends RecyclerView.Adapter { } }); } + + void setAvatars(@Nullable String statusAvatarUrl, @Nullable String notificationAvatarUrl) { + Context context = statusAvatar.getContext(); + + if (statusAvatarUrl == null || statusAvatarUrl.isEmpty()) { + statusAvatar.setImageResource(R.drawable.avatar_default); + } else { + Picasso.with(context) + .load(statusAvatarUrl) + .placeholder(R.drawable.avatar_default) + .error(R.drawable.avatar_error) + .transform(new RoundedTransformation(7, 0)) + .into(statusAvatar); + } + + if (notificationAvatarUrl == null || notificationAvatarUrl.isEmpty()) { + notificationAvatar.setVisibility(View.GONE); + } else { + notificationAvatar.setVisibility(View.VISIBLE); + Picasso.with(context) + .load(notificationAvatarUrl) + .fit() + .transform(new RoundedTransformation(7, 0)) + .into(notificationAvatar); + } + } } } diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java index d327bf10..12d321ab 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java @@ -32,16 +32,17 @@ import android.widget.TextView; import android.widget.ToggleButton; import com.keylesspalace.tusky.R; -import com.keylesspalace.tusky.view.RoundedTransformation; -import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.entity.Status; +import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.util.DateUtils; import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.ThemeUtils; +import com.keylesspalace.tusky.view.RoundedTransformation; import com.keylesspalace.tusky.viewdata.StatusViewData; import com.squareup.picasso.Picasso; import com.varunest.sparkbutton.SparkButton; import com.varunest.sparkbutton.SparkEventListener; +import com.varunest.sparkbutton.helpers.Utils; import java.util.Date; @@ -52,6 +53,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { private TextView sinceCreated; private TextView content; private ImageView avatar; + private ImageView avatarReblog; private View rebloggedBar; private TextView rebloggedByDisplayName; private ImageButton replyButton; @@ -79,6 +81,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { sinceCreated = (TextView) itemView.findViewById(R.id.status_since_created); content = (TextView) itemView.findViewById(R.id.status_content); avatar = (ImageView) itemView.findViewById(R.id.status_avatar); + avatarReblog = (ImageView) itemView.findViewById(R.id.status_avatar_reblog); rebloggedBar = itemView.findViewById(R.id.status_reblogged_bar); rebloggedByDisplayName = (TextView) itemView.findViewById(R.id.status_reblogged); replyButton = (ImageButton) itemView.findViewById(R.id.status_reply); @@ -122,17 +125,33 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { LinkHelper.setClickableText(this.content, content, mentions, useCustomTabs, listener); } - private void setAvatar(String url) { - if (url.isEmpty()) { - return; - } + private void setAvatar(String url, @Nullable String rebloggedUrl) { Context context = avatar.getContext(); - Picasso.with(context) - .load(url) - .placeholder(R.drawable.avatar_default) - .error(R.drawable.avatar_error) - .transform(new RoundedTransformation(7, 0)) - .into(avatar); + boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty(); + int padding = hasReblog ? Utils.dpToPx(context, 12) : 0; + avatar.setPadding(0, 0, padding, padding); + + if (url.isEmpty()) { + avatar.setImageResource(R.drawable.avatar_default); + } else { + Picasso.with(context) + .load(url) + .placeholder(R.drawable.avatar_default) + .error(R.drawable.avatar_error) + .transform(new RoundedTransformation(7, 0)) + .into(avatar); + } + + if (hasReblog) { + avatarReblog.setVisibility(View.VISIBLE); + Picasso.with(context) + .load(rebloggedUrl) + .fit() + .transform(new RoundedTransformation(7, 0)) + .into(avatarReblog); + } else { + avatarReblog.setVisibility(View.GONE); + } } private void setCreatedAt(@Nullable Date createdAt) { @@ -460,7 +479,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { setUsername(status.getNickname()); setCreatedAt(status.getCreatedAt()); setContent(status.getContent(), status.getMentions(), listener); - setAvatar(status.getAvatar()); + setAvatar(status.getAvatar(), status.getRebloggedAvatar()); setReblogged(status.isReblogged()); setFavourited(status.isFavourited()); String rebloggedByDisplayName = status.getRebloggedByUsername(); diff --git a/app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java index 91c09073..cd6c74eb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java @@ -32,7 +32,7 @@ public final class ViewDataUtils { .setIsShowingSensitiveContent(false) .setMentions(visibleStatus.mentions) .setNickname(visibleStatus.account.username) - .setRebloggedAvatar(visibleStatus.account.avatar) + .setRebloggedAvatar(status.reblog == null ? null : status.account.avatar) .setSensitive(visibleStatus.sensitive) .setSpoilerText(visibleStatus.spoilerText) .setRebloggedByUsername(status.reblog == null ? null : status.account.username) diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index 58353e91..5ff9b46b 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -1,11 +1,12 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + xmlns:tools="http://schemas.android.com/tools" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:id="@+id/status_container"> + android:contentDescription="@string/action_view_profile" + tools:src="@drawable/avatar_default"/> + + - + + android:layout_marginTop="8dp"> + android:paddingStart="24dp" + app:srcCompat="@drawable/ic_repeat_24dp"/> + android:layout_toRightOf="@id/notification_icon" + android:ellipsize="end" + android:maxLines="1" + android:text="Someone favourited your status" + android:textColor="?android:textColorSecondary"/> + android:paddingEnd="0dp" + android:paddingLeft="58dp" + android:paddingRight="0dp" + android:paddingStart="58dp" + android:textColor="?android:textColorTertiary" + tools:text="Example status here"/> - \ No newline at end of file + + + + + \ No newline at end of file