NekoX/TMessagesProj/src/main/java/org/telegram/ui/Cells/StatisticPostInfoCell.java

125 lines
6.2 KiB
Java
Raw Normal View History

2020-03-30 14:00:09 +02:00
package org.telegram.ui.Cells;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
2020-12-23 08:48:30 +01:00
import android.util.TypedValue;
2020-03-30 14:00:09 +02:00
import android.view.Gravity;
2020-07-26 10:03:38 +02:00
import android.view.View;
2020-03-30 14:00:09 +02:00
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.ImageLocation;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessageObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;
2020-07-26 10:03:38 +02:00
import org.telegram.ui.Components.AvatarDrawable;
2020-03-30 14:00:09 +02:00
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.StatisticActivity;
public class StatisticPostInfoCell extends FrameLayout {
private TextView message;
private TextView views;
private TextView shares;
private TextView date;
private BackupImageView imageView;
2020-07-26 10:03:38 +02:00
private AvatarDrawable avatarDrawable = new AvatarDrawable();
2020-03-30 14:00:09 +02:00
private final TLRPC.ChatFull chat;
public StatisticPostInfoCell(Context context, TLRPC.ChatFull chat) {
super(context);
this.chat = chat;
imageView = new BackupImageView(context);
addView(imageView, LayoutHelper.createFrame(46, 46, Gravity.START | Gravity.CENTER_VERTICAL, 12, 0, 16, 0));
LinearLayout contentLayout = new LinearLayout(context);
contentLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
message = new TextView(context);
message.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2020-12-23 08:48:30 +01:00
message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
2020-03-30 14:00:09 +02:00
message.setTextColor(Color.BLACK);
message.setLines(1);
message.setEllipsize(TextUtils.TruncateAt.END);
views = new TextView(context);
2020-12-23 08:48:30 +01:00
views.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
2020-03-30 14:00:09 +02:00
views.setTextColor(Color.BLACK);
linearLayout.addView(message, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f, Gravity.NO_GRAVITY, 0, 0, 16, 0));
linearLayout.addView(views, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
contentLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.TOP, 0, 8, 0, 0));
date = new TextView(context);
2020-12-23 08:48:30 +01:00
date.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
2020-03-30 14:00:09 +02:00
date.setTextColor(Color.BLACK);
date.setLines(1);
date.setEllipsize(TextUtils.TruncateAt.END);
shares = new TextView(context);
2020-12-23 08:48:30 +01:00
shares.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
2020-03-30 14:00:09 +02:00
shares.setTextColor(Color.BLACK);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(date, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f, Gravity.NO_GRAVITY, 0, 0, 8, 0));
linearLayout.addView(shares, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
2020-07-26 23:11:01 +02:00
contentLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.TOP, 0, 2, 0, 8));
2020-03-30 14:00:09 +02:00
addView(contentLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.NO_GRAVITY, 72, 0, 12, 0));
message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
views.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
2020-07-26 10:03:38 +02:00
date.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
shares.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
2020-03-30 14:00:09 +02:00
}
public void setData(StatisticActivity.RecentPostInfo postInfo) {
MessageObject messageObject = postInfo.message;
if (messageObject.photoThumbs != null) {
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize thumbSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs,50);
imageView.setImage(
ImageLocation.getForObject(size, messageObject.photoThumbsObject), "50_50",
ImageLocation.getForObject(thumbSize, messageObject.photoThumbsObject), "b1", 0, messageObject);
imageView.setRoundRadius(AndroidUtilities.dp(4));
} else if (chat.chat_photo.sizes.size() > 0) {
imageView.setImage(ImageLocation.getForPhoto(chat.chat_photo.sizes.get(0), chat.chat_photo), "50_50", null, null, chat);
imageView.setRoundRadius(AndroidUtilities.dp(46) >> 1);
}
String text;
if (messageObject.isMusic()) {
text = String.format("%s, %s", messageObject.getMusicTitle().trim(), messageObject.getMusicAuthor().trim());
} else {
text = messageObject.caption != null ? messageObject.caption.toString() : messageObject.messageText.toString();
}
message.setText(text.replace("\n", " ").trim());
2020-04-24 11:21:58 +02:00
views.setText(String.format(LocaleController.getPluralString("Views", postInfo.counters.views), AndroidUtilities.formatCount(postInfo.counters.views)));
2020-03-30 14:00:09 +02:00
date.setText(LocaleController.formatDateAudio(postInfo.message.messageOwner.date, false));
2020-04-24 11:21:58 +02:00
shares.setText(String.format(LocaleController.getPluralString("Shares", postInfo.counters.forwards), AndroidUtilities.formatCount(postInfo.counters.forwards)));
2020-03-30 14:00:09 +02:00
}
2020-07-26 10:03:38 +02:00
public void setData(StatisticActivity.MemberData memberData) {
avatarDrawable.setInfo(memberData.user);
2021-04-14 03:44:46 +02:00
imageView.setImage(ImageLocation.getForUserOrChat(memberData.user, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(memberData.user, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, memberData.user);
2020-07-26 10:03:38 +02:00
imageView.setRoundRadius(AndroidUtilities.dp(46) >> 1);
message.setText(memberData.user.first_name);
date.setText(memberData.description);
views.setVisibility(View.GONE);
shares.setVisibility(View.GONE);
}
2020-03-30 14:00:09 +02:00
}