2017-01-23 06:19:30 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 02:12:31 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2017-12-02 12:22:52 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-07-15 00:18:29 +02:00
|
|
|
import android.os.Build;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.view.View;
|
2017-03-07 01:31:05 +01:00
|
|
|
import android.widget.ImageView;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.R;
|
2017-07-14 07:06:32 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2017-12-02 12:22:52 +01:00
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
2017-07-14 07:06:32 +02:00
|
|
|
import com.keylesspalace.tusky.view.RoundedTransformation;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2017-03-07 01:31:05 +01:00
|
|
|
import com.squareup.picasso.Picasso;
|
2017-07-14 07:06:32 +02:00
|
|
|
import com.varunest.sparkbutton.helpers.Utils;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
public class StatusViewHolder extends StatusBaseViewHolder {
|
2017-07-14 07:06:32 +02:00
|
|
|
private ImageView avatarReblog;
|
2017-11-30 20:12:09 +01:00
|
|
|
private TextView rebloggedBar;
|
2017-08-03 06:29:31 +02:00
|
|
|
|
2017-02-22 20:13:51 +01:00
|
|
|
StatusViewHolder(View itemView) {
|
2017-01-23 06:19:30 +01:00
|
|
|
super(itemView);
|
2017-10-18 00:20:26 +02:00
|
|
|
avatarReblog = itemView.findViewById(R.id.status_avatar_reblog);
|
2017-11-30 20:12:09 +01:00
|
|
|
rebloggedBar = itemView.findViewById(R.id.status_reblogged);
|
2017-12-02 12:22:52 +01:00
|
|
|
//workaround because Android < API 21 does not support setting drawableLeft from xml when it is a vector image
|
|
|
|
Drawable rebloggedIcon = ThemeUtils.getDrawable(rebloggedBar.getContext(),
|
|
|
|
R.attr.status_reblog_small_drawable, R.drawable.ic_reblog_dark_18dp);
|
|
|
|
rebloggedBar.setCompoundDrawablesWithIntrinsicBounds(rebloggedIcon, null, null, null);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
@Override
|
|
|
|
void setAvatar(String url, @Nullable String rebloggedUrl) {
|
|
|
|
super.setAvatar(url, rebloggedUrl);
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-07-14 07:06:32 +02:00
|
|
|
Context context = avatar.getContext();
|
|
|
|
boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty();
|
|
|
|
int padding = hasReblog ? Utils.dpToPx(context, 12) : 0;
|
2017-07-15 05:23:14 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
avatar.setPaddingRelative(0, 0, padding, padding);
|
2017-07-15 00:18:29 +02:00
|
|
|
} else {
|
|
|
|
avatar.setPadding(0, 0, padding, padding);
|
|
|
|
}
|
2017-07-14 07:06:32 +02:00
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
if (hasReblog) {
|
|
|
|
avatarReblog.setVisibility(View.VISIBLE);
|
2017-07-14 07:06:32 +02:00
|
|
|
Picasso.with(context)
|
2017-08-03 23:26:26 +02:00
|
|
|
.load(rebloggedUrl)
|
|
|
|
.fit()
|
2017-07-14 07:06:32 +02:00
|
|
|
.transform(new RoundedTransformation(7, 0))
|
2017-08-03 23:26:26 +02:00
|
|
|
.into(avatarReblog);
|
|
|
|
} else {
|
|
|
|
avatarReblog.setVisibility(View.GONE);
|
2017-01-31 05:51:02 +01:00
|
|
|
}
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 20:12:09 +01:00
|
|
|
@Override
|
|
|
|
protected int getMediaPreviewHeight(Context context) {
|
|
|
|
return context.getResources().getDimensionPixelSize(R.dimen.status_media_preview_height);
|
|
|
|
}
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
@Override
|
2017-11-06 16:19:15 +01:00
|
|
|
void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener,
|
2017-08-03 23:26:26 +02:00
|
|
|
boolean mediaPreviewEnabled) {
|
2018-03-01 21:10:10 +01:00
|
|
|
if(status == null) {
|
|
|
|
showContent(false);
|
2017-01-23 06:19:30 +01:00
|
|
|
} else {
|
2018-03-01 21:10:10 +01:00
|
|
|
showContent(true);
|
|
|
|
super.setupWithStatus(status, listener, mediaPreviewEnabled);
|
2017-08-03 23:26:26 +02:00
|
|
|
|
2018-03-01 21:10:10 +01:00
|
|
|
String rebloggedByDisplayName = status.getRebloggedByUsername();
|
|
|
|
if (rebloggedByDisplayName == null) {
|
|
|
|
hideRebloggedByDisplayName();
|
|
|
|
} else {
|
|
|
|
setRebloggedByDisplayName(rebloggedByDisplayName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// I think it's not efficient to create new object every time we bind a holder.
|
|
|
|
// More efficient approach would be creating View.OnClickListener during holder creation
|
|
|
|
// and storing StatusActionListener in a variable after binding.
|
|
|
|
rebloggedBar.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition()));
|
|
|
|
}
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 20:13:51 +01:00
|
|
|
private void setRebloggedByDisplayName(String name) {
|
2017-11-30 20:12:09 +01:00
|
|
|
Context context = rebloggedBar.getContext();
|
2017-01-23 06:19:30 +01:00
|
|
|
String format = context.getString(R.string.status_boosted_format);
|
|
|
|
String boostedText = String.format(format, name);
|
2017-11-30 20:12:09 +01:00
|
|
|
rebloggedBar.setText(boostedText);
|
2017-02-13 06:18:17 +01:00
|
|
|
rebloggedBar.setVisibility(View.VISIBLE);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 20:13:51 +01:00
|
|
|
private void hideRebloggedByDisplayName() {
|
2017-08-03 06:29:31 +02:00
|
|
|
if (rebloggedBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-13 06:18:17 +01:00
|
|
|
rebloggedBar.setVisibility(View.GONE);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
}
|