Merge branch 'charlag-boost-avatars'

This commit is contained in:
Vavassor 2017-07-14 17:10:41 -04:00
commit 68e3ec67c5
5 changed files with 153 additions and 50 deletions

View File

@ -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);
}
}
}
}

View File

@ -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();

View File

@ -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)

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:id="@+id/status_container">
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">
<RelativeLayout
android:layout_width="match_parent"
@ -50,7 +51,19 @@
android:layout_marginTop="11dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:contentDescription="@string/action_view_profile" />
android:contentDescription="@string/action_view_profile"
tools:src="@drawable/avatar_default"/>
<ImageView
android:id="@+id/status_avatar_reblog"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignBottom="@+id/status_avatar"
android:layout_alignEnd="@id/status_avatar"
android:layout_alignRight="@id/status_avatar"
android:visibility="gone"
tools:src="@color/accent"
tools:visibility="visible"/>
<RelativeLayout
android:layout_height="wrap_content"

View File

@ -1,55 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<!--This applies only to favourite and reblog notifications.-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/notification_container"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/notification_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<RelativeLayout
android:id="@+id/notification_top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="@+id/notification_top_bar">
android:layout_marginTop="8dp">
<ImageView
android:id="@+id/notification_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/notification_icon"
android:paddingStart="24dp"
android:paddingLeft="24dp"
android:contentDescription="@null"
android:paddingEnd="10dp"
android:paddingLeft="24dp"
android:paddingRight="10dp"
app:srcCompat="@drawable/ic_repeat_24dp"
android:contentDescription="@null" />
android:paddingStart="24dp"
app:srcCompat="@drawable/ic_repeat_24dp"/>
<TextView
android:id="@+id/notification_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/notification_text"
android:textColor="?android:textColorSecondary"
android:layout_centerVertical="true"
android:maxLines="1"
android:ellipsize="end"
android:text="Someone favourited your status"
android:layout_toEndOf="@id/notification_icon"
android:layout_toRightOf="@id/notification_icon" />
android:layout_toRightOf="@id/notification_icon"
android:ellipsize="end"
android:maxLines="1"
android:text="Someone favourited your status"
android:textColor="?android:textColorSecondary"/>
</RelativeLayout>
<TextView
android:id="@+id/notification_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/notification_content"
android:paddingStart="58dp"
android:paddingLeft="58dp"
android:paddingEnd="0dp"
android:paddingRight="0dp"
android:layout_below="@id/notification_top_bar"
android:paddingBottom="10dp"
android:text="Example status here"
android:textColor="?android:textColorTertiary" />
android:paddingEnd="0dp"
android:paddingLeft="58dp"
android:paddingRight="0dp"
android:paddingStart="58dp"
android:textColor="?android:textColorTertiary"
tools:text="Example status here"/>
</LinearLayout>
<ImageView
android:id="@+id/notification_status_avatar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignTop="@id/notification_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="11dp"
android:contentDescription="@string/action_view_profile"
android:paddingBottom="12dp"
android:paddingRight="12dp"
android:scaleType="fitCenter"
tools:ignore="RtlHardcoded,RtlSymmetry"
tools:src="@drawable/avatar_default"/>
<ImageView
android:id="@+id/notification_notification_avatar"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignBottom="@+id/notification_status_avatar"
android:layout_alignEnd="@id/notification_status_avatar"
android:layout_alignRight="@id/notification_status_avatar"
android:visibility="gone"
tools:src="@color/accent"
tools:visibility="visible"/>
</RelativeLayout>