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

236 lines
11 KiB
Java
Raw Normal View History

2015-04-09 20:00:14 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x
2015-04-09 20:00:14 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-04-09 20:00:14 +02:00
*/
package org.telegram.ui.Cells;
import android.content.Context;
import android.graphics.Canvas;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.LocaleController;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.MessagesController;
2015-04-09 20:00:14 +02:00
import org.telegram.messenger.R;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.UserObject;
import org.telegram.tgnet.TLObject;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.TLRPC;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.LayoutHelper;
2015-04-09 20:00:14 +02:00
import java.util.Locale;
public class SessionCell extends FrameLayout {
private TextView nameTextView;
private TextView onlineTextView;
private TextView detailTextView;
private TextView detailExTextView;
2018-07-30 04:07:02 +02:00
private BackupImageView imageView;
private AvatarDrawable avatarDrawable;
private boolean needDivider;
2015-04-09 20:00:14 +02:00
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
public SessionCell(Context context, int type) {
2015-04-09 20:00:14 +02:00
super(context);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setWeightSum(1);
2018-07-30 04:07:02 +02:00
if (type == 1) {
2019-01-23 18:03:33 +01:00
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 15 : 49), 11, (LocaleController.isRTL ? 49 : 15), 0));
2018-07-30 04:07:02 +02:00
avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(10));
imageView = new BackupImageView(context);
imageView.setRoundRadius(AndroidUtilities.dp(10));
2019-01-23 18:03:33 +01:00
addView(imageView, LayoutHelper.createFrame(20, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 0 : 21), 13, (LocaleController.isRTL ? 21 : 0), 0));
2018-07-30 04:07:02 +02:00
} else {
2019-01-23 18:03:33 +01:00
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 15 : 21), 11, (LocaleController.isRTL ? 21 : 15), 0));
2018-07-30 04:07:02 +02:00
}
2015-04-09 20:00:14 +02:00
nameTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2015-04-09 20:00:14 +02:00
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setLines(1);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
onlineTextView = new TextView(context);
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
if (LocaleController.isRTL) {
2015-05-21 23:27:27 +02:00
linearLayout.addView(onlineTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 2, 0, 0));
linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, Gravity.RIGHT | Gravity.TOP, 10, 0, 0, 0));
2015-04-09 20:00:14 +02:00
} else {
2015-05-21 23:27:27 +02:00
linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, Gravity.LEFT | Gravity.TOP, 0, 0, 10, 0));
linearLayout.addView(onlineTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 2, 0, 0));
2015-04-09 20:00:14 +02:00
}
detailTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
detailTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2015-04-09 20:00:14 +02:00
detailTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
detailTextView.setLines(1);
detailTextView.setMaxLines(1);
detailTextView.setSingleLine(true);
detailTextView.setEllipsize(TextUtils.TruncateAt.END);
detailTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2019-01-23 18:03:33 +01:00
addView(detailTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 36, 21, 0));
2015-04-09 20:00:14 +02:00
detailExTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
detailExTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
2015-04-09 20:00:14 +02:00
detailExTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
detailExTextView.setLines(1);
detailExTextView.setMaxLines(1);
detailExTextView.setSingleLine(true);
detailExTextView.setEllipsize(TextUtils.TruncateAt.END);
detailExTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2019-01-23 18:03:33 +01:00
addView(detailExTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 59, 21, 0));
2015-04-09 20:00:14 +02:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2017-03-31 01:58:05 +02:00
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(90) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
public void setSession(TLObject object, boolean divider) {
2015-04-09 20:00:14 +02:00
needDivider = divider;
2018-07-30 04:07:02 +02:00
if (object instanceof TLRPC.TL_authorization) {
TLRPC.TL_authorization session = (TLRPC.TL_authorization) object;
nameTextView.setText(String.format(Locale.US, "%s %s", session.app_name, session.app_version));
if ((session.flags & 1) != 0) {
setTag(Theme.key_windowBackgroundWhiteValueText);
onlineTextView.setText(LocaleController.getString("Online", R.string.Online));
onlineTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteValueText));
} else {
setTag(Theme.key_windowBackgroundWhiteGrayText3);
onlineTextView.setText(LocaleController.stringForMessageListDate(session.date_active));
onlineTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
}
StringBuilder stringBuilder = new StringBuilder();
if (session.ip.length() != 0) {
stringBuilder.append(session.ip);
}
if (session.country.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(" ");
}
stringBuilder.append("");
stringBuilder.append(session.country);
}
detailExTextView.setText(stringBuilder);
stringBuilder = new StringBuilder();
if (session.device_model.length() != 0) {
2019-01-23 18:03:33 +01:00
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
2018-07-30 04:07:02 +02:00
stringBuilder.append(session.device_model);
}
if (session.system_version.length() != 0 || session.platform.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
if (session.platform.length() != 0) {
stringBuilder.append(session.platform);
}
if (session.system_version.length() != 0) {
if (session.platform.length() != 0) {
stringBuilder.append(" ");
}
stringBuilder.append(session.system_version);
}
}
2019-01-23 18:03:33 +01:00
if (!session.official_app) {
2018-07-30 04:07:02 +02:00
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
stringBuilder.append(LocaleController.getString("UnofficialApp", R.string.UnofficialApp));
stringBuilder.append(" (ID: ");
stringBuilder.append(session.api_id);
stringBuilder.append(")");
}
detailTextView.setText(stringBuilder);
} else if (object instanceof TLRPC.TL_webAuthorization) {
TLRPC.TL_webAuthorization session = (TLRPC.TL_webAuthorization) object;
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(session.bot_id);
nameTextView.setText(session.domain);
String name;
if (user != null) {
avatarDrawable.setInfo(user);
name = UserObject.getFirstName(user);
2021-04-14 03:44:46 +02:00
imageView.setImage(ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, user);
2018-07-30 04:07:02 +02:00
} else {
name = "";
}
2017-03-31 01:58:05 +02:00
setTag(Theme.key_windowBackgroundWhiteGrayText3);
2015-04-09 20:00:14 +02:00
onlineTextView.setText(LocaleController.stringForMessageListDate(session.date_active));
2017-03-31 01:58:05 +02:00
onlineTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
2015-04-09 20:00:14 +02:00
2018-07-30 04:07:02 +02:00
StringBuilder stringBuilder = new StringBuilder();
if (session.ip.length() != 0) {
stringBuilder.append(session.ip);
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
if (session.region.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(" ");
}
stringBuilder.append("");
stringBuilder.append(session.region);
}
detailExTextView.setText(stringBuilder);
2015-04-09 20:00:14 +02:00
2018-07-30 04:07:02 +02:00
stringBuilder = new StringBuilder();
if (!TextUtils.isEmpty(name)) {
stringBuilder.append(name);
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
if (session.browser.length() != 0 ) {
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
stringBuilder.append(session.browser);
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
if (session.platform.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
stringBuilder.append(session.platform);
2015-04-09 20:00:14 +02:00
}
2018-07-30 04:07:02 +02:00
detailTextView.setText(stringBuilder);
2015-04-09 20:00:14 +02:00
}
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
2019-01-23 18:03:33 +01:00
canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(20), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
2015-04-09 20:00:14 +02:00
}
}
}