small improvements for viewholders (#860)
This commit is contained in:
parent
c37dbd15af
commit
7bdc22aa28
|
@ -14,7 +14,6 @@ import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
class AccountViewHolder extends RecyclerView.ViewHolder {
|
class AccountViewHolder extends RecyclerView.ViewHolder {
|
||||||
private View container;
|
|
||||||
private TextView username;
|
private TextView username;
|
||||||
private TextView displayName;
|
private TextView displayName;
|
||||||
private ImageView avatar;
|
private ImageView avatar;
|
||||||
|
@ -22,7 +21,6 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
AccountViewHolder(View itemView) {
|
AccountViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
container = itemView.findViewById(R.id.account_container);
|
|
||||||
username = itemView.findViewById(R.id.account_username);
|
username = itemView.findViewById(R.id.account_username);
|
||||||
displayName = itemView.findViewById(R.id.account_display_name);
|
displayName = itemView.findViewById(R.id.account_display_name);
|
||||||
avatar = itemView.findViewById(R.id.account_avatar);
|
avatar = itemView.findViewById(R.id.account_avatar);
|
||||||
|
@ -43,10 +41,10 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupActionListener(final AccountActionListener listener) {
|
void setupActionListener(final AccountActionListener listener) {
|
||||||
container.setOnClickListener(v -> listener.onViewAccount(accountId));
|
itemView.setOnClickListener(v -> listener.onViewAccount(accountId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupLinkListener(final LinkListener listener) {
|
void setupLinkListener(final LinkListener listener) {
|
||||||
container.setOnClickListener(v -> listener.onViewAccount(accountId));
|
itemView.setOnClickListener(v -> listener.onViewAccount(accountId));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -281,8 +281,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
CharSequence emojifiedMessage = CustomEmojiHelper.emojifyString(wholeMessage, account.getEmojis(), message);
|
CharSequence emojifiedMessage = CustomEmojiHelper.emojifyString(wholeMessage, account.getEmojis(), message);
|
||||||
message.setText(emojifiedMessage);
|
message.setText(emojifiedMessage);
|
||||||
|
|
||||||
format = context.getString(R.string.status_username_format);
|
String username = context.getString(R.string.status_username_format, account.getUsername());
|
||||||
String username = String.format(format, account.getUsername());
|
|
||||||
usernameView.setText(username);
|
usernameView.setText(username);
|
||||||
|
|
||||||
CharSequence emojifiedDisplayName = CustomEmojiHelper.emojifyString(wrappedDisplayName, account.getEmojis(), usernameView);
|
CharSequence emojifiedDisplayName = CustomEmojiHelper.emojifyString(wrappedDisplayName, account.getEmojis(), usernameView);
|
||||||
|
@ -313,7 +312,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
private final TextView username;
|
private final TextView username;
|
||||||
private final TextView timestampInfo;
|
private final TextView timestampInfo;
|
||||||
private final TextView statusContent;
|
private final TextView statusContent;
|
||||||
private final ViewGroup container;
|
|
||||||
private final ImageView statusAvatar;
|
private final ImageView statusAvatar;
|
||||||
private final ImageView notificationAvatar;
|
private final ImageView notificationAvatar;
|
||||||
private final TextView contentWarningDescriptionTextView;
|
private final TextView contentWarningDescriptionTextView;
|
||||||
|
@ -337,7 +335,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
username = itemView.findViewById(R.id.status_username);
|
username = itemView.findViewById(R.id.status_username);
|
||||||
timestampInfo = itemView.findViewById(R.id.status_timestamp_info);
|
timestampInfo = itemView.findViewById(R.id.status_timestamp_info);
|
||||||
statusContent = itemView.findViewById(R.id.notification_content);
|
statusContent = itemView.findViewById(R.id.notification_content);
|
||||||
container = itemView.findViewById(R.id.notification_container);
|
|
||||||
statusAvatar = itemView.findViewById(R.id.notification_status_avatar);
|
statusAvatar = itemView.findViewById(R.id.notification_status_avatar);
|
||||||
notificationAvatar = itemView.findViewById(R.id.notification_notification_avatar);
|
notificationAvatar = itemView.findViewById(R.id.notification_notification_avatar);
|
||||||
contentWarningDescriptionTextView = itemView.findViewById(R.id.notification_content_warning_description);
|
contentWarningDescriptionTextView = itemView.findViewById(R.id.notification_content_warning_description);
|
||||||
|
@ -348,7 +345,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
statusAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY);
|
statusAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY);
|
||||||
notificationAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY);
|
notificationAvatar.setColorFilter(darkerFilter, PorterDuff.Mode.MULTIPLY);
|
||||||
|
|
||||||
container.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
message.setOnClickListener(this);
|
message.setOnClickListener(this);
|
||||||
statusContent.setOnClickListener(this);
|
statusContent.setOnClickListener(this);
|
||||||
contentWarningButton.setOnCheckedChangeListener(this);
|
contentWarningButton.setOnCheckedChangeListener(this);
|
||||||
|
@ -556,11 +553,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||||
notificationActionListener.onExpandedChange(isChecked, getAdapterPosition());
|
notificationActionListener.onExpandedChange(isChecked, getAdapterPosition());
|
||||||
}
|
}
|
||||||
if (isChecked) {
|
statusContent.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
statusContent.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
statusContent.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ 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 View container;
|
|
||||||
private TextView displayName;
|
private TextView displayName;
|
||||||
private TextView username;
|
private TextView username;
|
||||||
private ImageButton replyButton;
|
private ImageButton replyButton;
|
||||||
|
@ -53,14 +52,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
private ImageButton moreButton;
|
private ImageButton moreButton;
|
||||||
private boolean favourited;
|
private boolean favourited;
|
||||||
private boolean reblogged;
|
private boolean reblogged;
|
||||||
private ImageView mediaPreview0;
|
private ImageView[] mediaPreviews;
|
||||||
private ImageView mediaPreview1;
|
private ImageView[] mediaOverlays;
|
||||||
private ImageView mediaPreview2;
|
|
||||||
private ImageView mediaPreview3;
|
|
||||||
private ImageView mediaOverlay0;
|
|
||||||
private ImageView mediaOverlay1;
|
|
||||||
private ImageView mediaOverlay2;
|
|
||||||
private ImageView mediaOverlay3;
|
|
||||||
private TextView sensitiveMediaWarning;
|
private TextView sensitiveMediaWarning;
|
||||||
private View sensitiveMediaShow;
|
private View sensitiveMediaShow;
|
||||||
private TextView mediaLabel;
|
private TextView mediaLabel;
|
||||||
|
@ -78,7 +71,6 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
|
StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
container = itemView.findViewById(R.id.status_container);
|
|
||||||
displayName = itemView.findViewById(R.id.status_display_name);
|
displayName = itemView.findViewById(R.id.status_display_name);
|
||||||
username = itemView.findViewById(R.id.status_username);
|
username = itemView.findViewById(R.id.status_username);
|
||||||
timestampInfo = itemView.findViewById(R.id.status_timestamp_info);
|
timestampInfo = itemView.findViewById(R.id.status_timestamp_info);
|
||||||
|
@ -90,14 +82,18 @@ 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;
|
||||||
mediaPreview0 = itemView.findViewById(R.id.status_media_preview_0);
|
mediaPreviews = new ImageView[] {
|
||||||
mediaPreview1 = itemView.findViewById(R.id.status_media_preview_1);
|
itemView.findViewById(R.id.status_media_preview_0),
|
||||||
mediaPreview2 = itemView.findViewById(R.id.status_media_preview_2);
|
itemView.findViewById(R.id.status_media_preview_1),
|
||||||
mediaPreview3 = itemView.findViewById(R.id.status_media_preview_3);
|
itemView.findViewById(R.id.status_media_preview_2),
|
||||||
mediaOverlay0 = itemView.findViewById(R.id.status_media_overlay_0);
|
itemView.findViewById(R.id.status_media_preview_3)
|
||||||
mediaOverlay1 = itemView.findViewById(R.id.status_media_overlay_1);
|
};
|
||||||
mediaOverlay2 = itemView.findViewById(R.id.status_media_overlay_2);
|
mediaOverlays =new ImageView[] {
|
||||||
mediaOverlay3 = itemView.findViewById(R.id.status_media_overlay_3);
|
itemView.findViewById(R.id.status_media_overlay_0),
|
||||||
|
itemView.findViewById(R.id.status_media_overlay_1),
|
||||||
|
itemView.findViewById(R.id.status_media_overlay_2),
|
||||||
|
itemView.findViewById(R.id.status_media_overlay_3)
|
||||||
|
};
|
||||||
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
|
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
|
||||||
sensitiveMediaShow = itemView.findViewById(R.id.status_sensitive_media_button);
|
sensitiveMediaShow = itemView.findViewById(R.id.status_sensitive_media_button);
|
||||||
mediaLabel = itemView.findViewById(R.id.status_media_label);
|
mediaLabel = itemView.findViewById(R.id.status_media_label);
|
||||||
|
@ -180,11 +176,11 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
protected void showContent(boolean show) {
|
protected void showContent(boolean show) {
|
||||||
if (show) {
|
if (show) {
|
||||||
container.setVisibility(View.VISIBLE);
|
itemView.setVisibility(View.VISIBLE);
|
||||||
container.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
itemView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
} else {
|
} else {
|
||||||
container.setVisibility(View.INVISIBLE);
|
itemView.setVisibility(View.INVISIBLE);
|
||||||
container.getLayoutParams().height = Utils.convertDpToPx(container.getContext(), 24);
|
itemView.getLayoutParams().height = Utils.convertDpToPx(itemView.getContext(), 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,13 +237,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private void setMediaPreviews(final List<Attachment> attachments, boolean sensitive,
|
private void setMediaPreviews(final List<Attachment> attachments, boolean sensitive,
|
||||||
final StatusActionListener listener, boolean showingContent) {
|
final StatusActionListener listener, boolean showingContent) {
|
||||||
final ImageView[] previews = {
|
|
||||||
mediaPreview0, mediaPreview1, mediaPreview2, mediaPreview3
|
Context context = itemView.getContext();
|
||||||
};
|
|
||||||
final ImageView[] overlays = {
|
|
||||||
mediaOverlay0, mediaOverlay1, mediaOverlay2, mediaOverlay3
|
|
||||||
};
|
|
||||||
Context context = mediaPreview0.getContext();
|
|
||||||
|
|
||||||
int mediaPreviewUnloadedId =
|
int mediaPreviewUnloadedId =
|
||||||
ThemeUtils.getDrawableId(itemView.getContext(), R.attr.media_preview_unloaded_drawable,
|
ThemeUtils.getDrawableId(itemView.getContext(), R.attr.media_preview_unloaded_drawable,
|
||||||
|
@ -260,46 +251,46 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
String description = attachments.get(i).getDescription();
|
String description = attachments.get(i).getDescription();
|
||||||
|
|
||||||
if (TextUtils.isEmpty(description)) {
|
if (TextUtils.isEmpty(description)) {
|
||||||
previews[i].setContentDescription(context.getString(R.string.action_view_media));
|
mediaPreviews[i].setContentDescription(context.getString(R.string.action_view_media));
|
||||||
} else {
|
} else {
|
||||||
previews[i].setContentDescription(description);
|
mediaPreviews[i].setContentDescription(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
previews[i].setVisibility(View.VISIBLE);
|
mediaPreviews[i].setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (TextUtils.isEmpty(previewUrl)) {
|
if (TextUtils.isEmpty(previewUrl)) {
|
||||||
Picasso.with(context)
|
Picasso.with(context)
|
||||||
.load(mediaPreviewUnloadedId)
|
.load(mediaPreviewUnloadedId)
|
||||||
.into(previews[i]);
|
.into(mediaPreviews[i]);
|
||||||
} else {
|
} else {
|
||||||
Picasso.with(context)
|
Picasso.with(context)
|
||||||
.load(previewUrl)
|
.load(previewUrl)
|
||||||
.placeholder(mediaPreviewUnloadedId)
|
.placeholder(mediaPreviewUnloadedId)
|
||||||
.into(previews[i]);
|
.into(mediaPreviews[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Attachment.Type type = attachments.get(i).getType();
|
final Attachment.Type type = attachments.get(i).getType();
|
||||||
if (type == Attachment.Type.VIDEO | type == Attachment.Type.GIFV) {
|
if (type == Attachment.Type.VIDEO | type == Attachment.Type.GIFV) {
|
||||||
overlays[i].setVisibility(View.VISIBLE);
|
mediaOverlays[i].setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
overlays[i].setVisibility(View.GONE);
|
mediaOverlays[i].setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int urlIndex = i;
|
final int urlIndex = i;
|
||||||
previews[i].setOnClickListener(v -> {
|
mediaPreviews[i].setOnClickListener(v -> {
|
||||||
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||||
listener.onViewMedia(getAdapterPosition(), urlIndex, v);
|
listener.onViewMedia(getAdapterPosition(), urlIndex, v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (n <= 2) {
|
if (n <= 2) {
|
||||||
previews[0].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
|
mediaPreviews[0].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
|
||||||
previews[1].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
|
mediaPreviews[1].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
|
||||||
} else {
|
} else {
|
||||||
previews[0].getLayoutParams().height = getMediaPreviewHeight(context);
|
mediaPreviews[0].getLayoutParams().height = getMediaPreviewHeight(context);
|
||||||
previews[1].getLayoutParams().height = getMediaPreviewHeight(context);
|
mediaPreviews[1].getLayoutParams().height = getMediaPreviewHeight(context);
|
||||||
previews[2].getLayoutParams().height = getMediaPreviewHeight(context);
|
mediaPreviews[2].getLayoutParams().height = getMediaPreviewHeight(context);
|
||||||
previews[3].getLayoutParams().height = getMediaPreviewHeight(context);
|
mediaPreviews[3].getLayoutParams().height = getMediaPreviewHeight(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +327,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
// Hide any of the placeholder previews beyond the ones set.
|
// Hide any of the placeholder previews beyond the ones set.
|
||||||
for (int i = n; i < Status.MAX_MEDIA_ATTACHMENTS; i++) {
|
for (int i = n; i < Status.MAX_MEDIA_ATTACHMENTS; i++) {
|
||||||
previews[i].setVisibility(View.GONE);
|
mediaPreviews[i].setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,17 +399,11 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||||
listener.onExpandedChange(isChecked, getAdapterPosition());
|
listener.onExpandedChange(isChecked, getAdapterPosition());
|
||||||
}
|
}
|
||||||
if (isChecked) {
|
content.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
content.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
content.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (expanded) {
|
content.setVisibility(expanded ? View.VISIBLE : View.GONE);
|
||||||
content.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
content.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideSpoilerText() {
|
private void hideSpoilerText() {
|
||||||
|
@ -490,7 +475,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
content.setOnClickListener(viewThreadListener);
|
content.setOnClickListener(viewThreadListener);
|
||||||
container.setOnClickListener(viewThreadListener);
|
itemView.setOnClickListener(viewThreadListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener,
|
void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener,
|
||||||
|
@ -515,10 +500,10 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
} else {
|
} else {
|
||||||
setMediaLabel(attachments, sensitive, listener);
|
setMediaLabel(attachments, sensitive, listener);
|
||||||
// Hide all unused views.
|
// Hide all unused views.
|
||||||
mediaPreview0.setVisibility(View.GONE);
|
mediaPreviews[0].setVisibility(View.GONE);
|
||||||
mediaPreview1.setVisibility(View.GONE);
|
mediaPreviews[1].setVisibility(View.GONE);
|
||||||
mediaPreview2.setVisibility(View.GONE);
|
mediaPreviews[2].setVisibility(View.GONE);
|
||||||
mediaPreview3.setVisibility(View.GONE);
|
mediaPreviews[3].setVisibility(View.GONE);
|
||||||
hideSensitiveMediaWarning();
|
hideSensitiveMediaWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
||||||
|
|
||||||
private void setRebloggedByDisplayName(String name) {
|
private void setRebloggedByDisplayName(String name) {
|
||||||
Context context = rebloggedBar.getContext();
|
Context context = rebloggedBar.getContext();
|
||||||
String format = context.getString(R.string.status_boosted_format);
|
String boostedText = context.getString(R.string.status_boosted_format, name);
|
||||||
String boostedText = String.format(format, name);
|
|
||||||
rebloggedBar.setText(boostedText);
|
rebloggedBar.setText(boostedText);
|
||||||
rebloggedBar.setVisibility(View.VISIBLE);
|
rebloggedBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue