NekoX/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java

2582 lines
131 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
2013-10-25 17:19:00 +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).
*
* Copyright Nikolai Kudashov, 2013-2016.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.ui;
import android.animation.Animator;
import android.animation.AnimatorSet;
2015-02-01 19:51:02 +01:00
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
2015-05-21 23:27:27 +02:00
import android.annotation.SuppressLint;
2015-11-26 22:04:02 +01:00
import android.app.Activity;
2013-10-25 17:19:00 +02:00
import android.app.AlertDialog;
2015-09-24 22:52:02 +02:00
import android.app.Dialog;
2013-10-25 17:19:00 +02:00
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
2015-11-26 22:04:02 +01:00
import android.content.SharedPreferences;
2014-11-11 23:16:17 +01:00
import android.content.res.Configuration;
2015-01-02 23:15:07 +01:00
import android.graphics.Bitmap;
2016-04-22 15:49:00 +02:00
import android.graphics.Canvas;
2015-10-29 18:10:07 +01:00
import android.graphics.Color;
2015-02-01 19:51:02 +01:00
import android.graphics.Outline;
2016-04-22 15:49:00 +02:00
import android.graphics.Paint;
2013-10-25 17:19:00 +02:00
import android.net.Uri;
2014-11-10 12:05:22 +01:00
import android.os.Build;
2013-10-25 17:19:00 +02:00
import android.os.Bundle;
2014-11-10 12:05:22 +01:00
import android.view.Gravity;
2015-10-29 18:10:07 +01:00
import android.view.MotionEvent;
2013-10-25 17:19:00 +02:00
import android.view.View;
import android.view.ViewGroup;
2015-02-01 19:51:02 +01:00
import android.view.ViewOutlineProvider;
2014-11-11 23:16:17 +01:00
import android.view.ViewTreeObserver;
2015-06-29 19:12:11 +02:00
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
2014-11-10 12:05:22 +01:00
import android.widget.FrameLayout;
import android.widget.ImageView;
2013-10-25 17:19:00 +02:00
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2013-10-25 17:19:00 +02:00
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.AnimatorListenerAdapterProxy;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.SecretChatHelper;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.query.BotQuery;
import org.telegram.messenger.query.SharedMediaQuery;
import org.telegram.messenger.ApplicationLoader;
2015-10-29 18:10:07 +01:00
import org.telegram.messenger.support.widget.LinearLayoutManager;
import org.telegram.messenger.support.widget.RecyclerView;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.ConnectionsManager;
2015-11-26 22:04:02 +01:00
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.ContactsController;
2013-12-20 20:25:49 +01:00
import org.telegram.messenger.FileLog;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
2013-10-25 17:19:00 +02:00
import org.telegram.messenger.R;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.MessageObject;
2014-11-12 23:16:59 +01:00
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.ActionBar.BackDrawable;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.SimpleTextView;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Cells.AboutLinkCell;
2014-11-10 12:05:22 +01:00
import org.telegram.ui.Cells.DividerCell;
import org.telegram.ui.Cells.EmptyCell;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Cells.LoadingCell;
2014-11-12 23:16:59 +01:00
import org.telegram.ui.Cells.ShadowSectionCell;
2014-11-10 12:05:22 +01:00
import org.telegram.ui.Cells.TextCell;
import org.telegram.ui.Cells.TextDetailCell;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Cells.TextInfoPrivacyCell;
2014-11-12 23:16:59 +01:00
import org.telegram.ui.Cells.UserCell;
2014-11-13 21:10:14 +01:00
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.AvatarUpdater;
import org.telegram.ui.Components.BackupImageView;
2014-11-13 21:10:14 +01:00
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.IdenticonDrawable;
import org.telegram.ui.Components.LayoutHelper;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.Components.RecyclerListView;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.Theme;
2013-10-25 17:19:00 +02:00
import java.util.ArrayList;
2014-11-12 23:16:59 +01:00
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.concurrent.Semaphore;
2016-04-22 15:49:00 +02:00
public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, PhotoViewer.PhotoViewerProvider {
2014-11-12 23:16:59 +01:00
2015-10-29 18:10:07 +01:00
private RecyclerListView listView;
private LinearLayoutManager layoutManager;
2013-10-25 17:19:00 +02:00
private ListAdapter listAdapter;
2014-11-10 12:05:22 +01:00
private BackupImageView avatarImage;
2016-04-22 15:49:00 +02:00
private SimpleTextView nameTextView[] = new SimpleTextView[2];
private SimpleTextView onlineTextView[] = new SimpleTextView[2];
2014-11-11 23:16:17 +01:00
private ImageView writeButton;
private AnimatorSet writeButtonAnimation;
2015-11-26 22:04:02 +01:00
private AvatarDrawable avatarDrawable;
private ActionBarMenuItem animatingItem;
2016-04-22 15:49:00 +02:00
private TopView topView;
2013-10-25 17:19:00 +02:00
private int user_id;
2014-11-12 23:16:59 +01:00
private int chat_id;
2013-10-25 17:19:00 +02:00
private long dialog_id;
2014-11-12 23:16:59 +01:00
private boolean creatingChat;
private boolean userBlocked;
2015-11-26 22:04:02 +01:00
private long mergeDialogId;
private boolean loadingUsers;
2016-03-16 13:26:32 +01:00
private HashMap<Integer, TLRPC.ChatParticipant> participantsMap = new HashMap<>();
2015-11-26 22:04:02 +01:00
private boolean usersEndReached;
2014-11-12 23:16:59 +01:00
2015-10-29 18:10:07 +01:00
private boolean openAnimationInProgress;
private boolean playProfileAnimation;
2016-05-25 23:49:47 +02:00
private boolean allowProfileAnimation = true;
2015-10-29 18:10:07 +01:00
private int extraHeight;
private int initialAnimationExtraHeight;
private float animationProgress;
2014-11-12 23:16:59 +01:00
private AvatarUpdater avatarUpdater;
2015-09-24 22:52:02 +02:00
private TLRPC.ChatFull info;
2015-11-26 22:04:02 +01:00
private int selectedUser;
2014-11-12 23:16:59 +01:00
private int onlineCount = -1;
private ArrayList<Integer> sortedUsers;
2013-10-25 17:19:00 +02:00
private TLRPC.EncryptedChat currentEncryptedChat;
2014-11-12 23:16:59 +01:00
private TLRPC.Chat currentChat;
2015-06-29 19:12:11 +02:00
private TLRPC.BotInfo botInfo;
2014-11-12 23:16:59 +01:00
private int totalMediaCount = -1;
2015-11-26 22:04:02 +01:00
private int totalMediaCountMerge = -1;
2013-10-25 17:19:00 +02:00
private final static int add_contact = 1;
private final static int block_contact = 2;
private final static int share_contact = 3;
private final static int edit_contact = 4;
private final static int delete_contact = 5;
2014-11-12 23:16:59 +01:00
private final static int leave_group = 7;
private final static int edit_name = 8;
2015-06-29 19:12:11 +02:00
private final static int invite_to_group = 9;
private final static int share = 10;
2015-11-26 22:04:02 +01:00
private final static int set_admins = 11;
private final static int edit_channel = 12;
2016-03-16 13:26:32 +01:00
private final static int convert_to_supergroup = 13;
2016-05-25 23:49:47 +02:00
private final static int add_shortcut = 14;
2014-11-10 12:05:22 +01:00
private int emptyRow;
2014-11-12 23:16:59 +01:00
private int emptyRowChat;
private int emptyRowChat2;
private int phoneRow;
private int usernameRow;
2015-09-24 22:52:02 +02:00
private int channelInfoRow;
private int channelNameRow;
private int settingsTimerRow;
private int settingsKeyRow;
2015-11-26 22:04:02 +01:00
private int convertRow;
private int convertHelpRow;
private int settingsNotificationsRow;
private int sharedMediaRow;
2015-09-24 22:52:02 +02:00
private int membersRow;
private int managementRow;
2015-11-26 22:04:02 +01:00
private int blockedUsersRow;
2015-09-24 22:52:02 +02:00
private int leaveChannelRow;
2014-11-10 12:05:22 +01:00
private int startSecretChatRow;
private int sectionRow;
2016-03-16 13:26:32 +01:00
private int userSectionRow;
private int userInfoRow;
2014-11-12 23:16:59 +01:00
private int membersSectionRow;
private int membersEndRow;
2015-11-26 22:04:02 +01:00
private int loadMoreMembersRow;
private int addMemberRow;
private int rowCount = 0;
2016-04-22 15:49:00 +02:00
private class TopView extends View {
private int currentColor;
private Paint paint = new Paint();
public TopView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2016-05-25 23:49:47 +02:00
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + AndroidUtilities.dp(91));
2016-04-22 15:49:00 +02:00
}
@Override
public void setBackgroundColor(int color) {
if (color != currentColor) {
paint.setColor(color);
invalidate();
}
}
@Override
protected void onDraw(Canvas canvas) {
int height = getMeasuredHeight() - AndroidUtilities.dp(91);
canvas.drawRect(0, 0, getMeasuredWidth(), height + extraHeight, paint);
if (parentLayout != null) {
parentLayout.drawHeaderShadow(canvas, height + extraHeight);
}
}
}
2014-11-10 12:05:22 +01:00
public ProfileActivity(Bundle args) {
super(args);
}
2013-10-25 17:19:00 +02:00
@Override
public boolean onFragmentCreate() {
user_id = arguments.getInt("user_id", 0);
2014-11-12 23:16:59 +01:00
chat_id = getArguments().getInt("chat_id", 0);
if (user_id != 0) {
dialog_id = arguments.getLong("dialog_id", 0);
if (dialog_id != 0) {
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
}
2015-06-29 19:12:11 +02:00
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
2014-11-12 23:16:59 +01:00
return false;
}
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatCreated);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
2015-06-29 19:12:11 +02:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.botInfoDidLoaded);
2016-03-16 13:26:32 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.userInfoDidLoaded);
2015-10-29 18:10:07 +01:00
if (currentEncryptedChat != null) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedNewMessages);
}
2014-11-12 23:16:59 +01:00
userBlocked = MessagesController.getInstance().blockedUsers.contains(user_id);
2015-11-26 22:04:02 +01:00
if (user.bot) {
2015-06-29 19:12:11 +02:00
BotQuery.loadBotInfo(user.id, true, classGuid);
}
2016-03-16 13:26:32 +01:00
MessagesController.getInstance().loadFullUser(MessagesController.getInstance().getUser(user_id), classGuid, true);
2015-11-26 22:04:02 +01:00
participantsMap = null;
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
currentChat = MessagesController.getInstance().getChat(chat_id);
if (currentChat == null) {
final Semaphore semaphore = new Semaphore(0);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentChat = MessagesStorage.getInstance().getChat(chat_id);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentChat != null) {
MessagesController.getInstance().putChat(currentChat, true);
} else {
return false;
}
}
2015-11-26 22:04:02 +01:00
if (currentChat.megagroup) {
getChannelParticipants(true);
} else {
participantsMap = null;
}
2014-11-12 23:16:59 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
2015-01-02 23:15:07 +01:00
sortedUsers = new ArrayList<>();
2014-11-12 23:16:59 +01:00
updateOnlineCount();
avatarUpdater = new AvatarUpdater();
avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() {
@Override
public void didUploadedPhoto(TLRPC.InputFile file, TLRPC.PhotoSize small, TLRPC.PhotoSize big) {
if (chat_id != 0) {
MessagesController.getInstance().changeChatAvatar(chat_id, file);
}
}
};
avatarUpdater.parentFragment = this;
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat)) {
MessagesController.getInstance().loadFullChat(chat_id, classGuid, true);
}
2014-11-12 23:16:59 +01:00
} else {
return false;
}
2015-11-26 22:04:02 +01:00
if (dialog_id != 0) {
SharedMediaQuery.getMediaCount(dialog_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else if (user_id != 0) {
SharedMediaQuery.getMediaCount(user_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else if (chat_id > 0) {
SharedMediaQuery.getMediaCount(-chat_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
if (mergeDialogId != 0) {
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
}
2014-11-12 23:16:59 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
2015-02-01 19:51:02 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
2014-11-12 23:16:59 +01:00
updateRowsIds();
return true;
2013-10-25 17:19:00 +02:00
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
2014-11-12 23:16:59 +01:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
2015-02-01 19:51:02 +01:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
2014-11-12 23:16:59 +01:00
if (user_id != 0) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatCreated);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded);
2015-06-29 19:12:11 +02:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botInfoDidLoaded);
2016-03-16 13:26:32 +01:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.userInfoDidLoaded);
2014-11-12 23:16:59 +01:00
MessagesController.getInstance().cancelLoadFullUser(user_id);
2015-10-29 18:10:07 +01:00
if (currentEncryptedChat != null) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedNewMessages);
}
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
avatarUpdater.clear();
}
2013-10-25 17:19:00 +02:00
}
@Override
2016-04-22 15:49:00 +02:00
protected ActionBar createActionBar(Context context) {
ActionBar actionBar = new ActionBar(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
2016-05-25 23:49:47 +02:00
return super.onTouchEvent(event);
2016-04-22 15:49:00 +02:00
}
};
actionBar.setItemsBackgroundColor(AvatarDrawable.getButtonColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id));
2015-10-29 18:10:07 +01:00
actionBar.setBackButtonDrawable(new BackDrawable(false));
actionBar.setCastShadows(false);
actionBar.setAddToContainer(false);
2016-05-25 23:49:47 +02:00
actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
2016-04-22 15:49:00 +02:00
return actionBar;
}
@Override
public View createView(Context context) {
2015-10-29 18:10:07 +01:00
hasOwnBackground = true;
2016-05-25 23:49:47 +02:00
extraHeight = AndroidUtilities.dp(88);
2015-04-09 20:00:14 +02:00
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
if (getParentActivity() == null) {
return;
}
if (id == -1) {
finishFragment();
} else if (id == block_contact) {
2015-09-02 00:14:21 +02:00
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
return;
2015-04-09 20:00:14 +02:00
}
2015-11-26 22:04:02 +01:00
if (!user.bot) {
2015-09-02 00:14:21 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (!userBlocked) {
builder.setMessage(LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact));
} else {
builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact));
}
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (!userBlocked) {
MessagesController.getInstance().blockUser(user_id);
} else {
MessagesController.getInstance().unblockUser(user_id);
}
2015-04-09 20:00:14 +02:00
}
2015-09-02 00:14:21 +02:00
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
if (!userBlocked) {
MessagesController.getInstance().blockUser(user_id);
} else {
MessagesController.getInstance().unblockUser(user_id);
SendMessagesHelper.getInstance().sendMessage("/start", user_id, null, null, false, null, null, null);
2015-09-02 00:14:21 +02:00
finishFragment();
2015-04-09 20:00:14 +02:00
}
2015-09-02 00:14:21 +02:00
}
2015-04-09 20:00:14 +02:00
} else if (id == add_contact) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
Bundle args = new Bundle();
args.putInt("user_id", user.id);
2015-10-29 18:10:07 +01:00
args.putBoolean("addContact", true);
2015-04-09 20:00:14 +02:00
presentFragment(new ContactAddActivity(args));
} else if (id == share_contact) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
2015-06-29 19:12:11 +02:00
args.putInt("dialogsType", 1);
2015-11-26 22:04:02 +01:00
args.putString("selectAlertString", LocaleController.getString("SendContactTo", R.string.SendContactTo));
args.putString("selectAlertStringGroup", LocaleController.getString("SendContactToGroup", R.string.SendContactToGroup));
2015-07-22 20:56:37 +02:00
DialogsActivity fragment = new DialogsActivity(args);
2015-04-09 20:00:14 +02:00
fragment.setDelegate(ProfileActivity.this);
presentFragment(fragment);
} else if (id == edit_contact) {
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ContactAddActivity(args));
} else if (id == delete_contact) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteContact", R.string.AreYouSureDeleteContact));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ArrayList<TLRPC.User> arrayList = new ArrayList<>();
arrayList.add(user);
ContactsController.getInstance().deleteContact(arrayList);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
2015-05-21 23:27:27 +02:00
showDialog(builder.create());
2015-04-09 20:00:14 +02:00
} else if (id == leave_group) {
2015-11-26 22:04:02 +01:00
leaveChatPressed();
2015-04-09 20:00:14 +02:00
} else if (id == edit_name) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
2015-11-26 22:04:02 +01:00
presentFragment(new ChangeChatNameActivity(args));
} else if (id == edit_channel) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
ChannelEditActivity fragment = new ChannelEditActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
2015-06-29 19:12:11 +02:00
} else if (id == invite_to_group) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
return;
}
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 2);
args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupTitle", R.string.AddToTheGroupTitle, UserObject.getUserName(user), "%1$s"));
2015-07-22 20:56:37 +02:00
DialogsActivity fragment = new DialogsActivity(args);
2016-04-22 15:49:00 +02:00
fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
2015-06-29 19:12:11 +02:00
@Override
2015-07-22 20:56:37 +02:00
public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
2015-06-29 19:12:11 +02:00
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
args.putInt("chat_id", -(int) did);
2016-03-16 13:26:32 +01:00
if (!MessagesController.checkCanOpenChat(args, fragment)) {
return;
}
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
MessagesController.getInstance().addUserToChat(-(int) did, user, null, 0, null, ProfileActivity.this);
2015-06-29 19:12:11 +02:00
presentFragment(new ChatActivity(args), true);
removeSelfFromStack();
}
});
presentFragment(fragment);
} else if (id == share) {
try {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
return;
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
2016-03-16 13:26:32 +01:00
String about = MessagesController.getInstance().getUserAbout(botInfo.user_id);
if (botInfo != null && about != null) {
intent.putExtra(Intent.EXTRA_TEXT, String.format("%s https://telegram.me/%s", about, user.username));
2015-06-29 19:12:11 +02:00
} else {
intent.putExtra(Intent.EXTRA_TEXT, String.format("https://telegram.me/%s", user.username));
}
startActivityForResult(Intent.createChooser(intent, LocaleController.getString("BotShare", R.string.BotShare)), 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-11-26 22:04:02 +01:00
} else if (id == set_admins) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
SetAdminsActivity fragment = new SetAdminsActivity(args);
fragment.setChatInfo(info);
presentFragment(fragment);
2016-03-16 13:26:32 +01:00
} else if (id == convert_to_supergroup) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
presentFragment(new ConvertGroupActivity(args));
2016-05-25 23:49:47 +02:00
} else if (id == add_shortcut) {
try {
long did;
if (currentEncryptedChat != null) {
did = ((long) currentEncryptedChat.id) << 32;
} else if (user_id != 0) {
did = user_id;
} else if (chat_id != 0) {
did = -chat_id;
} else {
return;
}
AndroidUtilities.installShortcut(did);
/*try {
Toast.makeText(getParentActivity(), LocaleController.getString("ShortcutAdded", R.string.ShortcutAdded), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e("tmessages", e);
}*/
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-04-09 20:00:14 +02:00
}
2014-11-17 03:44:57 +01:00
}
2015-04-09 20:00:14 +02:00
});
createActionBarMenu();
listAdapter = new ListAdapter(context);
2015-11-26 22:04:02 +01:00
avatarDrawable = new AvatarDrawable();
avatarDrawable.setProfile(true);
2015-04-09 20:00:14 +02:00
2015-11-26 22:04:02 +01:00
fragmentView = new FrameLayout(context) {
@Override
public boolean hasOverlappingRendering() {
return false;
}
2016-04-22 15:49:00 +02:00
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
checkListViewScroll();
}
2015-11-26 22:04:02 +01:00
};
2015-04-09 20:00:14 +02:00
FrameLayout frameLayout = (FrameLayout) fragmentView;
2015-10-29 18:10:07 +01:00
listView = new RecyclerListView(context) {
2015-04-09 20:00:14 +02:00
@Override
2015-10-29 18:10:07 +01:00
public boolean hasOverlappingRendering() {
return false;
2015-04-09 20:00:14 +02:00
}
2015-10-29 18:10:07 +01:00
};
listView.setTag(6);
2016-04-22 15:49:00 +02:00
listView.setPadding(0, AndroidUtilities.dp(88), 0, 0);
2015-10-29 18:10:07 +01:00
listView.setBackgroundColor(0xffffffff);
2015-04-09 20:00:14 +02:00
listView.setVerticalScrollBarEnabled(false);
2015-10-29 18:10:07 +01:00
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
2016-04-22 15:49:00 +02:00
listView.setClipToPadding(false);
2015-10-29 18:10:07 +01:00
layoutManager = new LinearLayoutManager(context) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
};
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
listView.setLayoutManager(layoutManager);
2015-11-26 22:04:02 +01:00
listView.setGlowColor(AvatarDrawable.getProfileBackColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id));
2015-10-29 18:10:07 +01:00
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
2015-04-09 20:00:14 +02:00
listView.setAdapter(listAdapter);
2015-10-29 18:10:07 +01:00
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
2015-04-09 20:00:14 +02:00
@Override
2015-10-29 18:10:07 +01:00
public void onItemClick(View view, final int position) {
2015-04-09 20:00:14 +02:00
if (getParentActivity() == null) {
return;
}
2015-10-29 18:10:07 +01:00
if (position == sharedMediaRow) {
2015-04-09 20:00:14 +02:00
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id != 0 ? dialog_id : user_id);
} else {
args.putLong("dialog_id", -chat_id);
}
2015-11-26 22:04:02 +01:00
MediaActivity fragment = new MediaActivity(args);
fragment.setChatInfo(info);
presentFragment(fragment);
2015-10-29 18:10:07 +01:00
} else if (position == settingsKeyRow) {
2015-04-09 20:00:14 +02:00
Bundle args = new Bundle();
args.putInt("chat_id", (int) (dialog_id >> 32));
presentFragment(new IdenticonActivity(args));
2015-10-29 18:10:07 +01:00
} else if (position == settingsTimerRow) {
2015-05-21 23:27:27 +02:00
showDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat).create());
2015-10-29 18:10:07 +01:00
} else if (position == settingsNotificationsRow) {
2015-04-09 20:00:14 +02:00
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id);
} else if (chat_id != 0) {
args.putLong("dialog_id", -chat_id);
}
presentFragment(new ProfileNotificationsActivity(args));
2015-10-29 18:10:07 +01:00
} else if (position == startSecretChatRow) {
2015-04-09 20:00:14 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id));
}
2015-04-09 20:00:14 +02:00
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
2015-05-21 23:27:27 +02:00
showDialog(builder.create());
2015-10-29 18:10:07 +01:00
} else if (position > emptyRowChat2 && position < membersEndRow) {
2015-11-26 22:04:02 +01:00
int user_id;
2016-03-16 13:26:32 +01:00
if (!sortedUsers.isEmpty()) {
2015-11-26 22:04:02 +01:00
user_id = info.participants.participants.get(sortedUsers.get(position - emptyRowChat2 - 1)).user_id;
2016-03-16 13:26:32 +01:00
} else {
user_id = info.participants.participants.get(position - emptyRowChat2 - 1).user_id;
2015-11-26 22:04:02 +01:00
}
2015-04-09 20:00:14 +02:00
if (user_id == UserConfig.getClientUserId()) {
return;
}
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ProfileActivity(args));
2015-10-29 18:10:07 +01:00
} else if (position == addMemberRow) {
openAddMember();
2015-10-29 18:10:07 +01:00
} else if (position == channelNameRow) {
2015-09-24 22:52:02 +02:00
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
2015-11-26 22:04:02 +01:00
if (info.about != null && info.about.length() > 0) {
intent.putExtra(Intent.EXTRA_TEXT, currentChat.title + "\n" + info.about + "\nhttps://telegram.me/" + currentChat.username);
} else {
intent.putExtra(Intent.EXTRA_TEXT, currentChat.title + "\nhttps://telegram.me/" + currentChat.username);
}
2015-09-24 22:52:02 +02:00
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("BotShare", R.string.BotShare)), 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-10-29 18:10:07 +01:00
} else if (position == leaveChannelRow) {
2015-11-26 22:04:02 +01:00
leaveChatPressed();
2015-10-29 18:10:07 +01:00
} else if (position == membersRow || position == blockedUsersRow || position == managementRow) {
2015-09-24 22:52:02 +02:00
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
2015-10-29 18:10:07 +01:00
if (position == blockedUsersRow) {
2015-09-24 22:52:02 +02:00
args.putInt("type", 0);
2015-10-29 18:10:07 +01:00
} else if (position == managementRow) {
2015-09-24 22:52:02 +02:00
args.putInt("type", 1);
2015-10-29 18:10:07 +01:00
} else if (position == membersRow) {
2015-09-24 22:52:02 +02:00
args.putInt("type", 2);
}
presentFragment(new ChannelUsersActivity(args));
2015-11-26 22:04:02 +01:00
} else if (position == convertRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("ConvertGroupAlert", R.string.ConvertGroupAlert));
2016-03-16 13:26:32 +01:00
builder.setTitle(LocaleController.getString("ConvertGroupAlertWarning", R.string.ConvertGroupAlertWarning));
2015-11-26 22:04:02 +01:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MessagesController.getInstance().convertToMegaGroup(getParentActivity(), chat_id);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
2016-04-22 15:49:00 +02:00
} else {
processOnClickOrPress(position);
2015-04-09 20:00:14 +02:00
}
}
});
2015-10-29 18:10:07 +01:00
2016-04-22 15:49:00 +02:00
listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
@Override
public boolean onItemClick(View view, int position) {
if (position > emptyRowChat2 && position < membersEndRow) {
if (getParentActivity() == null) {
return false;
}
boolean allowKick = false;
boolean allowSetAdmin = false;
2016-03-16 13:26:32 +01:00
2016-04-22 15:49:00 +02:00
final TLRPC.ChatParticipant user;
if (!sortedUsers.isEmpty()) {
user = info.participants.participants.get(sortedUsers.get(position - emptyRowChat2 - 1));
} else {
user = info.participants.participants.get(position - emptyRowChat2 - 1);
}
selectedUser = user.user_id;
2016-03-16 13:26:32 +01:00
2016-04-22 15:49:00 +02:00
if (ChatObject.isChannel(currentChat)) {
TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) user).channelParticipant;
if (user.user_id != UserConfig.getClientUserId()) {
if (currentChat.creator) {
allowKick = true;
} else if (channelParticipant instanceof TLRPC.TL_channelParticipant) {
if (currentChat.editor || channelParticipant.inviter_id == UserConfig.getClientUserId()) {
2015-11-26 22:04:02 +01:00
allowKick = true;
}
}
2016-04-22 15:49:00 +02:00
}
TLRPC.User u = MessagesController.getInstance().getUser(user.user_id);
allowSetAdmin = channelParticipant instanceof TLRPC.TL_channelParticipant && !u.bot;
} else {
if (user.user_id != UserConfig.getClientUserId()) {
if (currentChat.creator) {
allowKick = true;
} else if (user instanceof TLRPC.TL_chatParticipant) {
if (currentChat.admin && currentChat.admins_enabled || user.inviter_id == UserConfig.getClientUserId()) {
2015-11-26 22:04:02 +01:00
allowKick = true;
}
}
2014-11-12 23:16:59 +01:00
}
2016-04-22 15:49:00 +02:00
}
if (!allowKick) {
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (currentChat.megagroup && currentChat.creator && allowSetAdmin) {
CharSequence[] items = new CharSequence[]{LocaleController.getString("SetAsAdmin", R.string.SetAsAdmin), LocaleController.getString("KickFromGroup", R.string.KickFromGroup)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
TLRPC.TL_chatChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) user);
channelParticipant.channelParticipant = new TLRPC.TL_channelParticipantEditor();
channelParticipant.channelParticipant.inviter_id = UserConfig.getClientUserId();
channelParticipant.channelParticipant.user_id = user.user_id;
channelParticipant.channelParticipant.date = user.date;
TLRPC.TL_channels_editAdmin req = new TLRPC.TL_channels_editAdmin();
req.channel = MessagesController.getInputChannel(chat_id);
req.user_id = MessagesController.getInputUser(selectedUser);
req.role = new TLRPC.TL_channelRoleEditor();
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, final TLRPC.TL_error error) {
if (error == null) {
MessagesController.getInstance().processUpdates((TLRPC.Updates) response, false);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().loadFullChat(chat_id, 0, true);
}
}, 1000);
} else {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
AlertsCreator.showAddUserAlert(error.text, ProfileActivity.this, false);
}
});
2015-11-26 22:04:02 +01:00
}
2016-04-22 15:49:00 +02:00
}
});
} else if (i == 1) {
kickUser(selectedUser);
2015-04-09 20:00:14 +02:00
}
2016-04-22 15:49:00 +02:00
}
});
} else {
CharSequence[] items = new CharSequence[]{chat_id > 0 ? LocaleController.getString("KickFromGroup", R.string.KickFromGroup) : LocaleController.getString("KickFromBroadcast", R.string.KickFromBroadcast)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
kickUser(selectedUser);
2015-11-26 22:04:02 +01:00
}
2016-04-22 15:49:00 +02:00
}
});
}
2016-04-22 15:49:00 +02:00
showDialog(builder.create());
return true;
} else {
return processOnClickOrPress(position);
2013-12-20 20:25:49 +01:00
}
2016-04-22 15:49:00 +02:00
}
});
2014-11-10 12:05:22 +01:00
2016-04-22 15:49:00 +02:00
topView = new TopView(context);
topView.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id));
frameLayout.addView(topView);
2015-10-29 18:10:07 +01:00
2016-04-22 15:49:00 +02:00
frameLayout.addView(actionBar);
2015-10-29 18:10:07 +01:00
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(21));
avatarImage.setPivotX(0);
avatarImage.setPivotY(0);
2015-10-29 18:10:07 +01:00
frameLayout.addView(avatarImage, LayoutHelper.createFrame(42, 42, Gravity.TOP | Gravity.LEFT, 64, 0, 0, 0));
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user.photo != null && user.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this);
}
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo != null && chat.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, ProfileActivity.this);
}
}
}
});
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
if (!playProfileAnimation && a == 0) {
continue;
}
2016-04-22 15:49:00 +02:00
nameTextView[a] = new SimpleTextView(context);
2015-11-26 22:04:02 +01:00
nameTextView[a].setTextColor(0xffffffff);
2016-04-22 15:49:00 +02:00
nameTextView[a].setTextSize(18);
2015-11-26 22:04:02 +01:00
nameTextView[a].setGravity(Gravity.LEFT);
nameTextView[a].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2016-04-22 15:49:00 +02:00
nameTextView[a].setLeftDrawableTopPadding(-AndroidUtilities.dp(1.3f));
nameTextView[a].setRightDrawableTopPadding(-AndroidUtilities.dp(1.3f));
nameTextView[a].setPivotX(0);
nameTextView[a].setPivotY(0);
2015-11-26 22:04:02 +01:00
frameLayout.addView(nameTextView[a], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, a == 0 ? 48 : 0, 0));
2016-04-22 15:49:00 +02:00
onlineTextView[a] = new SimpleTextView(context);
2015-11-26 22:04:02 +01:00
onlineTextView[a].setTextColor(AvatarDrawable.getProfileTextColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id));
2016-04-22 15:49:00 +02:00
onlineTextView[a].setTextSize(14);
2015-11-26 22:04:02 +01:00
onlineTextView[a].setGravity(Gravity.LEFT);
frameLayout.addView(onlineTextView[a], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, a == 0 ? 48 : 8, 0));
}
2015-10-29 18:10:07 +01:00
2015-09-24 22:52:02 +02:00
if (user_id != 0 || chat_id >= 0 && !ChatObject.isLeftFromChat(currentChat)) {
2015-04-09 20:00:14 +02:00
writeButton = new ImageView(context);
2015-11-26 22:04:02 +01:00
try {
writeButton.setBackgroundResource(R.drawable.floating_user_states);
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
2015-04-09 20:00:14 +02:00
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (user_id != 0) {
writeButton.setImageResource(R.drawable.floating_message);
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
} else if (chat_id != 0) {
2015-11-26 22:04:02 +01:00
boolean isChannel = ChatObject.isChannel(currentChat);
if (isChannel && !currentChat.creator && (!currentChat.megagroup || !currentChat.editor) || !isChannel && !currentChat.admin && !currentChat.creator && currentChat.admins_enabled) {
2015-09-24 22:52:02 +02:00
writeButton.setImageResource(R.drawable.floating_message);
2015-11-26 22:04:02 +01:00
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
2015-09-24 22:52:02 +02:00
} else {
writeButton.setImageResource(R.drawable.floating_camera);
}
2015-04-09 20:00:14 +02:00
}
2015-10-29 18:10:07 +01:00
frameLayout.addView(writeButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 16, 0));
2015-04-09 20:00:14 +02:00
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[]{}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
2015-05-21 23:27:27 +02:00
@SuppressLint("NewApi")
2015-04-09 20:00:14 +02:00
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
writeButton.setOnClickListener(new View.OnClickListener() {
2013-10-25 17:19:00 +02:00
@Override
2015-04-09 20:00:14 +02:00
public void onClick(View v) {
2014-11-10 12:05:22 +01:00
if (getParentActivity() == null) {
return;
}
2015-04-09 20:00:14 +02:00
if (user_id != 0) {
2015-10-29 18:10:07 +01:00
if (playProfileAnimation && parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2) instanceof ChatActivity) {
finishFragment();
} else {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user instanceof TLRPC.TL_userEmpty) {
return;
}
Bundle args = new Bundle();
args.putInt("user_id", user_id);
2016-03-16 13:26:32 +01:00
if (!MessagesController.checkCanOpenChat(args, ProfileActivity.this)) {
return;
}
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
2015-10-29 18:10:07 +01:00
presentFragment(new ChatActivity(args), true);
}
2015-04-09 20:00:14 +02:00
} else if (chat_id != 0) {
2015-11-26 22:04:02 +01:00
boolean isChannel = ChatObject.isChannel(currentChat);
if (isChannel && !currentChat.creator && (!currentChat.megagroup || !currentChat.editor) || !isChannel && !currentChat.admin && !currentChat.creator && currentChat.admins_enabled) {
if (playProfileAnimation && parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2) instanceof ChatActivity) {
finishFragment();
} else {
Bundle args = new Bundle();
args.putInt("chat_id", currentChat.id);
2016-03-16 13:26:32 +01:00
if (!MessagesController.checkCanOpenChat(args, ProfileActivity.this)) {
return;
}
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
2015-11-26 22:04:02 +01:00
presentFragment(new ChatActivity(args), true);
}
2015-04-09 20:00:14 +02:00
} else {
2015-09-24 22:52:02 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo == null || chat.photo.photo_big == null || chat.photo instanceof TLRPC.TL_chatPhotoEmpty) {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
}
2014-11-10 12:05:22 +01:00
2015-09-24 22:52:02 +02:00
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
MessagesController.getInstance().changeChatAvatar(chat_id, null);
}
2014-11-10 12:05:22 +01:00
}
2015-09-24 22:52:02 +02:00
});
showDialog(builder.create());
}
2013-10-25 17:19:00 +02:00
}
}
});
2015-04-09 20:00:14 +02:00
}
2015-10-29 18:10:07 +01:00
needLayout();
2014-11-12 23:16:59 +01:00
2015-10-29 18:10:07 +01:00
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
2015-04-09 20:00:14 +02:00
@Override
2015-10-29 18:10:07 +01:00
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
2015-04-09 20:00:14 +02:00
checkListViewScroll();
2016-03-16 13:26:32 +01:00
if (participantsMap != null && loadMoreMembersRow != -1 && layoutManager.findLastVisibleItemPosition() > loadMoreMembersRow - 8) {
2015-11-26 22:04:02 +01:00
getChannelParticipants(false);
}
2014-11-12 23:16:59 +01:00
}
2015-04-09 20:00:14 +02:00
});
2014-11-12 23:16:59 +01:00
2013-10-25 17:19:00 +02:00
return fragmentView;
}
2016-04-22 15:49:00 +02:00
private boolean processOnClickOrPress(final int position) {
if (position == usernameRow) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user.username == null) {
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
try {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("label", "@" + user.username);
clipboard.setPrimaryClip(clip);
2016-04-22 15:49:00 +02:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
});
showDialog(builder.create());
return true;
} else if (position == phoneRow) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user.phone == null || user.phone.length() == 0 || getParentActivity() == null) {
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setItems(new CharSequence[]{LocaleController.getString("Call", R.string.Call), LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == 1) {
try {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("label", "+" + user.phone);
clipboard.setPrimaryClip(clip);
2016-04-22 15:49:00 +02:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
});
showDialog(builder.create());
return true;
} else if (position == channelInfoRow || position == userInfoRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
String about;
if (position == channelInfoRow) {
about = info.about;
} else {
about = MessagesController.getInstance().getUserAbout(botInfo.user_id);
}
if (about == null) {
return;
}
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("label", about);
clipboard.setPrimaryClip(clip);
2016-04-22 15:49:00 +02:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
showDialog(builder.create());
return true;
}
return false;
}
2015-11-26 22:04:02 +01:00
private void leaveChatPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (ChatObject.isChannel(chat_id) && !currentChat.megagroup) {
builder.setMessage(ChatObject.isChannel(chat_id) ? LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert) : LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
}
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
kickUser(0);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
2014-11-12 23:16:59 +01:00
@Override
public void saveSelfArgs(Bundle args) {
if (chat_id != 0) {
if (avatarUpdater != null && avatarUpdater.currentPicturePath != null) {
args.putString("path", avatarUpdater.currentPicturePath);
}
}
}
@Override
public void restoreSelfArgs(Bundle args) {
if (chat_id != 0) {
2015-09-24 22:52:02 +02:00
MessagesController.getInstance().loadChatInfo(chat_id, null, false);
2014-11-12 23:16:59 +01:00
if (avatarUpdater != null) {
avatarUpdater.currentPicturePath = args.getString("path");
}
}
}
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (chat_id != 0) {
avatarUpdater.onActivityResult(requestCode, resultCode, data);
}
}
2015-11-26 22:04:02 +01:00
private void getChannelParticipants(boolean reload) {
2016-03-16 13:26:32 +01:00
if (loadingUsers || participantsMap == null || info == null) {
2015-11-26 22:04:02 +01:00
return;
}
loadingUsers = true;
final int delay = !participantsMap.isEmpty() && reload ? 300 : 0;
2015-11-26 22:04:02 +01:00
final TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
req.channel = MessagesController.getInputChannel(chat_id);
req.filter = new TLRPC.TL_channelParticipantsRecent();
2016-03-16 13:26:32 +01:00
req.offset = reload ? 0 : participantsMap.size();
req.limit = 200;
2015-11-26 22:04:02 +01:00
int reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (error == null) {
TLRPC.TL_channels_channelParticipants res = (TLRPC.TL_channels_channelParticipants) response;
MessagesController.getInstance().putUsers(res.users, false);
2016-03-16 13:26:32 +01:00
if (res.users.size() != 200) {
2015-11-26 22:04:02 +01:00
usersEndReached = true;
}
if (req.offset == 0) {
participantsMap.clear();
2016-03-16 13:26:32 +01:00
info.participants = new TLRPC.TL_chatParticipants();
2015-11-26 22:04:02 +01:00
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
MessagesStorage.getInstance().updateChannelUsers(chat_id, res.participants);
}
for (int a = 0; a < res.participants.size(); a++) {
2016-03-16 13:26:32 +01:00
TLRPC.TL_chatChannelParticipant participant = new TLRPC.TL_chatChannelParticipant();
participant.channelParticipant = res.participants.get(a);
participant.inviter_id = participant.channelParticipant.inviter_id;
participant.user_id = participant.channelParticipant.user_id;
participant.date = participant.channelParticipant.date;
2015-11-26 22:04:02 +01:00
if (!participantsMap.containsKey(participant.user_id)) {
2016-03-16 13:26:32 +01:00
info.participants.participants.add(participant);
2015-11-26 22:04:02 +01:00
participantsMap.put(participant.user_id, participant);
}
}
}
2016-03-16 13:26:32 +01:00
updateOnlineCount();
2015-11-26 22:04:02 +01:00
loadingUsers = false;
updateRowsIds();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}, delay);
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
private void openAddMember() {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
2015-11-26 22:04:02 +01:00
args.putBoolean("needForwardCount", !ChatObject.isChannel(currentChat));
//args.putBoolean("allowUsernameSearch", false);
if (chat_id > 0) {
2015-11-26 22:04:02 +01:00
if (currentChat.creator) {
2015-06-29 19:12:11 +02:00
args.putInt("chat_id", currentChat.id);
}
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
}
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(TLRPC.User user, String param) {
2015-11-26 22:04:02 +01:00
MessagesController.getInstance().addUserToChat(chat_id, user, info, param != null ? Utilities.parseInt(param) : 0, null, ProfileActivity.this);
}
});
2016-03-16 13:26:32 +01:00
if (info != null && info.participants != null) {
HashMap<Integer, TLRPC.User> users = new HashMap<>();
2015-11-26 22:04:02 +01:00
for (int a = 0; a < info.participants.participants.size(); a++) {
users.put(info.participants.participants.get(a).user_id, null);
}
fragment.setIgnoreUsers(users);
}
presentFragment(fragment);
}
2014-11-19 02:23:46 +01:00
private void checkListViewScroll() {
2016-04-22 15:49:00 +02:00
if (listView.getChildCount() <= 0 || openAnimationInProgress) {
2014-11-19 02:23:46 +01:00
return;
}
2016-04-22 15:49:00 +02:00
2014-11-19 02:23:46 +01:00
View child = listView.getChildAt(0);
2016-04-22 15:49:00 +02:00
ListAdapter.Holder holder = (ListAdapter.Holder) listView.findContainingViewHolder(child);
int top = child.getTop();
int newOffset = 0;
if (top >= 0 && holder != null && holder.getAdapterPosition() == 0) {
newOffset = top;
}
if (extraHeight != newOffset) {
extraHeight = newOffset;
topView.invalidate();
2016-05-25 23:49:47 +02:00
if (playProfileAnimation) {
allowProfileAnimation = extraHeight != 0;
}
2016-04-22 15:49:00 +02:00
needLayout();
2014-11-19 02:23:46 +01:00
}
}
2014-11-12 23:16:59 +01:00
private void needLayout() {
FrameLayout.LayoutParams layoutParams;
2015-10-29 18:10:07 +01:00
int newTop = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight();
if (listView != null && !openAnimationInProgress) {
2014-11-12 23:16:59 +01:00
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
2015-10-29 18:10:07 +01:00
if (layoutParams.topMargin != newTop) {
layoutParams.topMargin = newTop;
listView.setLayoutParams(layoutParams);
}
2014-11-12 23:16:59 +01:00
}
if (avatarImage != null) {
2015-10-29 18:10:07 +01:00
float diff = extraHeight / (float) AndroidUtilities.dp(88);
listView.setTopGlowOffset(extraHeight);
2014-11-12 23:16:59 +01:00
if (writeButton != null) {
writeButton.setTranslationY((actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight() + extraHeight - AndroidUtilities.dp(29.5f));
2015-10-29 18:10:07 +01:00
if (!openAnimationInProgress) {
final boolean setVisible = diff > 0.2f;
boolean currentVisible = writeButton.getTag() == null;
if (setVisible != currentVisible) {
if (setVisible) {
writeButton.setTag(null);
} else {
writeButton.setTag(0);
2015-06-29 19:12:11 +02:00
}
2015-10-29 18:10:07 +01:00
if (writeButtonAnimation != null) {
AnimatorSet old = writeButtonAnimation;
2015-10-29 18:10:07 +01:00
writeButtonAnimation = null;
old.cancel();
}
writeButtonAnimation = new AnimatorSet();
2015-10-29 18:10:07 +01:00
if (setVisible) {
writeButtonAnimation.setInterpolator(new DecelerateInterpolator());
writeButtonAnimation.playTogether(
ObjectAnimator.ofFloat(writeButton, "scaleX", 1.0f),
ObjectAnimator.ofFloat(writeButton, "scaleY", 1.0f),
ObjectAnimator.ofFloat(writeButton, "alpha", 1.0f)
2015-10-29 18:10:07 +01:00
);
} else {
writeButtonAnimation.setInterpolator(new AccelerateInterpolator());
writeButtonAnimation.playTogether(
ObjectAnimator.ofFloat(writeButton, "scaleX", 0.2f),
ObjectAnimator.ofFloat(writeButton, "scaleY", 0.2f),
ObjectAnimator.ofFloat(writeButton, "alpha", 0.0f)
2015-10-29 18:10:07 +01:00
);
}
writeButtonAnimation.setDuration(150);
writeButtonAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2015-10-29 18:10:07 +01:00
if (writeButtonAnimation != null && writeButtonAnimation.equals(animation)) {
writeButtonAnimation = null;
}
}
});
writeButtonAnimation.start();
}
2014-11-19 02:23:46 +01:00
}
2014-11-12 23:16:59 +01:00
}
2015-10-29 18:10:07 +01:00
float avatarY = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight() / 2.0f * (1.0f + diff) - 21 * AndroidUtilities.density + 27 * AndroidUtilities.density * diff;
avatarImage.setScaleX((42 + 18 * diff) / 42.0f);
avatarImage.setScaleY((42 + 18 * diff) / 42.0f);
avatarImage.setTranslationX(-AndroidUtilities.dp(47) * diff);
avatarImage.setTranslationY((float) Math.ceil(avatarY));
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
if (nameTextView[a] == null) {
continue;
}
nameTextView[a].setTranslationX(-21 * AndroidUtilities.density * diff);
nameTextView[a].setTranslationY((float) Math.floor(avatarY) + AndroidUtilities.dp(1.3f) + AndroidUtilities.dp(7) * diff);
onlineTextView[a].setTranslationX(-21 * AndroidUtilities.density * diff);
onlineTextView[a].setTranslationY((float) Math.floor(avatarY) + AndroidUtilities.dp(24) + (float) Math.floor(11 * AndroidUtilities.density) * diff);
nameTextView[a].setScaleX(1.0f + 0.12f * diff);
nameTextView[a].setScaleY(1.0f + 0.12f * diff);
2015-11-26 22:04:02 +01:00
if (a == 1 && !openAnimationInProgress) {
int width;
if (AndroidUtilities.isTablet()) {
width = AndroidUtilities.dp(490);
} else {
width = AndroidUtilities.displaySize.x;
}
width = (int) (width - AndroidUtilities.dp(118 + 8 + 40 * (1.0f - diff)) - nameTextView[a].getTranslationX());
float width2 = nameTextView[a].getPaint().measureText(nameTextView[a].getText().toString()) * nameTextView[a].getScaleX() + nameTextView[a].getSideDrawablesSize();
2015-11-26 22:04:02 +01:00
layoutParams = (FrameLayout.LayoutParams) nameTextView[a].getLayoutParams();
if (width < width2) {
layoutParams.width = (int) Math.ceil(width / nameTextView[a].getScaleX());
2015-11-26 22:04:02 +01:00
} else {
layoutParams.width = LayoutHelper.WRAP_CONTENT;
}
nameTextView[a].setLayoutParams(layoutParams);
layoutParams = (FrameLayout.LayoutParams) onlineTextView[a].getLayoutParams();
layoutParams.rightMargin = (int) Math.ceil(onlineTextView[a].getTranslationX() + AndroidUtilities.dp(8) + AndroidUtilities.dp(40) * (1.0f - diff));
2015-11-26 22:04:02 +01:00
onlineTextView[a].setLayoutParams(layoutParams);
}
}
2014-11-12 23:16:59 +01:00
}
}
2014-11-11 23:16:17 +01:00
private void fixLayout() {
if (fragmentView == null) {
return;
}
fragmentView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (fragmentView != null) {
2015-11-26 22:04:02 +01:00
checkListViewScroll();
2014-11-12 23:16:59 +01:00
needLayout();
2014-11-11 23:16:17 +01:00
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
}
2015-06-29 19:12:11 +02:00
return true;
2014-11-11 23:16:17 +01:00
}
});
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
fixLayout();
}
2015-10-29 18:10:07 +01:00
@SuppressWarnings("unchecked")
2014-11-12 23:16:59 +01:00
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.updateInterfaces) {
2015-10-29 18:10:07 +01:00
int mask = (Integer) args[0];
2014-11-12 23:16:59 +01:00
if (user_id != 0) {
2014-11-19 16:17:24 +01:00
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
2014-11-12 23:16:59 +01:00
updateProfileData();
}
if ((mask & MessagesController.UPDATE_MASK_PHONE) != 0) {
if (listView != null) {
2015-10-29 18:10:07 +01:00
ListAdapter.Holder holder = (ListAdapter.Holder) listView.findViewHolderForPosition(phoneRow);
if (holder != null) {
listAdapter.onBindViewHolder(holder, phoneRow);
}
}
}
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
2015-11-26 22:04:02 +01:00
if ((mask & MessagesController.UPDATE_MASK_CHAT_ADMINS) != 0) {
TLRPC.Chat newChat = MessagesController.getInstance().getChat(chat_id);
if (newChat != null) {
currentChat = newChat;
createActionBarMenu();
updateRowsIds();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}
2015-09-24 22:52:02 +02:00
if ((mask & MessagesController.UPDATE_MASK_CHANNEL) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
2014-11-12 23:16:59 +01:00
updateOnlineCount();
updateProfileData();
}
2015-09-24 22:52:02 +02:00
if ((mask & MessagesController.UPDATE_MASK_CHANNEL) != 0) {
updateRowsIds();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
2014-11-12 23:16:59 +01:00
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
2015-02-27 20:57:58 +01:00
if (listView != null) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof UserCell) {
((UserCell) child).update(mask);
}
2014-11-12 23:16:59 +01:00
}
}
}
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.contactsDidLoaded) {
createActionBarMenu();
} else if (id == NotificationCenter.mediaCountDidLoaded) {
2015-10-29 18:10:07 +01:00
long uid = (Long) args[0];
2015-11-26 22:04:02 +01:00
long did = dialog_id;
if (did == 0) {
if (user_id != 0) {
did = user_id;
} else if (chat_id != 0) {
did = -chat_id;
}
}
if (uid == did || uid == mergeDialogId) {
if (uid == did) {
totalMediaCount = (Integer) args[1];
} else {
totalMediaCountMerge = (Integer) args[1];
}
2015-10-29 18:10:07 +01:00
if (listView != null) {
2015-11-26 22:04:02 +01:00
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
ListAdapter.Holder holder = (ListAdapter.Holder) listView.getChildViewHolder(child);
if (holder.getAdapterPosition() == sharedMediaRow) {
listAdapter.onBindViewHolder(holder, sharedMediaRow);
break;
}
2014-11-12 23:16:59 +01:00
}
2013-10-25 17:19:00 +02:00
}
}
} else if (id == NotificationCenter.encryptedChatCreated) {
2013-10-25 17:19:00 +02:00
if (creatingChat) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
2015-02-01 19:51:02 +01:00
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) args[0];
Bundle args2 = new Bundle();
args2.putInt("enc_id", encryptedChat.id);
presentFragment(new ChatActivity(args2), true);
}
});
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.encryptedChatUpdated) {
2015-10-29 18:10:07 +01:00
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) args[0];
2013-10-25 17:19:00 +02:00
if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
currentEncryptedChat = chat;
updateRowsIds();
2013-10-25 17:19:00 +02:00
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
boolean oldValue = userBlocked;
userBlocked = MessagesController.getInstance().blockedUsers.contains(user_id);
if (oldValue != userBlocked) {
createActionBarMenu();
}
2014-11-12 23:16:59 +01:00
} else if (id == NotificationCenter.chatInfoDidLoaded) {
2015-09-24 22:52:02 +02:00
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (chatFull.id == chat_id) {
2015-11-26 22:04:02 +01:00
boolean byChannelUsers = (Boolean) args[2];
if (info instanceof TLRPC.TL_channelFull) {
if (chatFull.participants == null && info != null) {
chatFull.participants = info.participants;
}
}
2016-03-16 13:26:32 +01:00
boolean loadChannelParticipants = info == null && chatFull instanceof TLRPC.TL_channelFull;
2015-09-24 22:52:02 +02:00
info = chatFull;
2015-11-26 22:04:02 +01:00
if (mergeDialogId == 0 && info.migrated_from_chat_id != 0) {
mergeDialogId = -info.migrated_from_chat_id;
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
fetchUsersFromChannelInfo();
2014-11-12 23:16:59 +01:00
updateOnlineCount();
updateRowsIds();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
2015-11-26 22:04:02 +01:00
TLRPC.Chat newChat = MessagesController.getInstance().getChat(chat_id);
if (newChat != null) {
currentChat = newChat;
createActionBarMenu();
}
2016-03-16 13:26:32 +01:00
if (currentChat.megagroup && (loadChannelParticipants || !byChannelUsers)) {
2015-11-26 22:04:02 +01:00
getChannelParticipants(true);
}
2014-11-12 23:16:59 +01:00
}
} else if (id == NotificationCenter.closeChats) {
removeSelfFromStack();
2015-06-29 19:12:11 +02:00
} else if (id == NotificationCenter.botInfoDidLoaded) {
TLRPC.BotInfo info = (TLRPC.BotInfo) args[0];
if (info.user_id == user_id) {
botInfo = info;
updateRowsIds();
2015-11-26 22:04:02 +01:00
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
2015-06-29 19:12:11 +02:00
}
2016-03-16 13:26:32 +01:00
} else if (id == NotificationCenter.userInfoDidLoaded) {
int uid = (Integer) args[0];
if (uid == user_id) {
updateRowsIds();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
2015-11-26 22:04:02 +01:00
} else if (id == NotificationCenter.didReceivedNewMessages) {
2015-10-29 18:10:07 +01:00
long did = (Long) args[0];
if (did == dialog_id) {
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}
}
2013-10-25 17:19:00 +02:00
}
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
2013-10-25 17:19:00 +02:00
listAdapter.notifyDataSetChanged();
}
2015-04-09 20:00:14 +02:00
updateProfileData();
2014-11-11 23:16:17 +01:00
fixLayout();
2013-10-25 17:19:00 +02:00
}
2015-10-29 18:10:07 +01:00
public void setPlayProfileAnimation(boolean value) {
2015-11-26 22:04:02 +01:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (!AndroidUtilities.isTablet() && preferences.getBoolean("view_animations", true)) {
2015-10-29 18:10:07 +01:00
playProfileAnimation = value;
}
}
@Override
protected void onTransitionAnimationStart(boolean isOpen, boolean backward) {
2016-05-25 23:49:47 +02:00
if (!backward && playProfileAnimation && allowProfileAnimation) {
2015-10-29 18:10:07 +01:00
openAnimationInProgress = true;
}
2016-04-22 15:49:00 +02:00
NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded});
2015-10-29 18:10:07 +01:00
NotificationCenter.getInstance().setAnimationInProgress(true);
}
@Override
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
2016-05-25 23:49:47 +02:00
if (!backward && playProfileAnimation && allowProfileAnimation) {
2015-10-29 18:10:07 +01:00
openAnimationInProgress = false;
}
NotificationCenter.getInstance().setAnimationInProgress(false);
}
public float getAnimationProgress() {
return animationProgress;
}
public void setAnimationProgress(float progress) {
animationProgress = progress;
listView.setAlpha(progress);
2016-04-22 15:49:00 +02:00
listView.setTranslationX(AndroidUtilities.dp(48) - AndroidUtilities.dp(48) * progress);
2015-11-26 22:04:02 +01:00
int color = AvatarDrawable.getProfileBackColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id);
2016-04-22 15:49:00 +02:00
int r = Color.red(Theme.ACTION_BAR_COLOR);
int g = Color.green(Theme.ACTION_BAR_COLOR);
int b = Color.blue(Theme.ACTION_BAR_COLOR);
int rD = (int) ((Color.red(color) - r) * progress);
int gD = (int) ((Color.green(color) - g) * progress);
int bD = (int) ((Color.blue(color) - b) * progress);
topView.setBackgroundColor(Color.rgb(r + rD, g + gD, b + bD));
2015-11-26 22:04:02 +01:00
color = AvatarDrawable.getProfileTextColorForId(user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id);
2016-04-22 15:49:00 +02:00
r = Color.red(Theme.ACTION_BAR_SUBTITLE_COLOR);
g = Color.green(Theme.ACTION_BAR_SUBTITLE_COLOR);
b = Color.blue(Theme.ACTION_BAR_SUBTITLE_COLOR);
rD = (int) ((Color.red(color) - r) * progress);
gD = (int) ((Color.green(color) - g) * progress);
bD = (int) ((Color.blue(color) - b) * progress);
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
if (onlineTextView[a] == null) {
continue;
}
2016-04-22 15:49:00 +02:00
onlineTextView[a].setTextColor(Color.rgb(r + rD, g + gD, b + bD));
2015-11-26 22:04:02 +01:00
}
2015-10-29 18:10:07 +01:00
extraHeight = (int) (initialAnimationExtraHeight * progress);
2015-11-26 22:04:02 +01:00
color = AvatarDrawable.getProfileColorForId(user_id != 0 ? user_id : chat_id);
int color2 = AvatarDrawable.getColorForId(user_id != 0 ? user_id : chat_id);
if (color != color2) {
rD = (int) ((Color.red(color) - Color.red(color2)) * progress);
gD = (int) ((Color.green(color) - Color.green(color2)) * progress);
bD = (int) ((Color.blue(color) - Color.blue(color2)) * progress);
avatarDrawable.setColor(Color.rgb(Color.red(color2) + rD, Color.green(color2) + gD, Color.blue(color2) + bD));
avatarImage.invalidate();
}
2015-10-29 18:10:07 +01:00
needLayout();
}
@Override
protected AnimatorSet onCustomTransitionAnimation(final boolean isOpen, final Runnable callback) {
2016-05-25 23:49:47 +02:00
if (playProfileAnimation && allowProfileAnimation) {
final AnimatorSet animatorSet = new AnimatorSet();
2016-04-22 15:49:00 +02:00
animatorSet.setDuration(180);
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT > 15) {
listView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
2015-11-26 22:04:02 +01:00
ActionBarMenu menu = actionBar.createMenu();
if (menu.getItem(10) == null) {
if (animatingItem == null) {
animatingItem = menu.addItem(10, R.drawable.ic_ab_other);
}
}
2015-10-29 18:10:07 +01:00
if (isOpen) {
2015-11-26 22:04:02 +01:00
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) onlineTextView[1].getLayoutParams();
layoutParams.rightMargin = (int) (-21 * AndroidUtilities.density + AndroidUtilities.dp(8));
onlineTextView[1].setLayoutParams(layoutParams);
int width = (int) Math.ceil(AndroidUtilities.displaySize.x - AndroidUtilities.dp(118 + 8) + 21 * AndroidUtilities.density);
2016-04-22 15:49:00 +02:00
float width2 = nameTextView[1].getPaint().measureText(nameTextView[1].getText().toString()) * 1.12f + nameTextView[1].getSideDrawablesSize();
2015-11-26 22:04:02 +01:00
layoutParams = (FrameLayout.LayoutParams) nameTextView[1].getLayoutParams();
if (width < width2) {
layoutParams.width = (int) Math.ceil(width / 1.12f);
} else {
layoutParams.width = LayoutHelper.WRAP_CONTENT;
}
nameTextView[1].setLayoutParams(layoutParams);
2015-10-29 18:10:07 +01:00
initialAnimationExtraHeight = AndroidUtilities.dp(88);
fragmentView.setBackgroundColor(0);
setAnimationProgress(0);
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 0.0f, 1.0f));
2015-10-29 18:10:07 +01:00
if (writeButton != null) {
writeButton.setScaleX(0.2f);
writeButton.setScaleY(0.2f);
writeButton.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 1.0f));
animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 1.0f));
animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 1.0f));
2015-10-29 18:10:07 +01:00
}
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
onlineTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
nameTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
2015-11-26 22:04:02 +01:00
}
if (animatingItem != null) {
animatingItem.setAlpha(1.0f);
animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 0.0f));
2015-11-26 22:04:02 +01:00
}
2015-10-29 18:10:07 +01:00
animatorSet.playTogether(animators);
} else {
initialAnimationExtraHeight = extraHeight;
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 1.0f, 0.0f));
2015-10-29 18:10:07 +01:00
if (writeButton != null) {
animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 0.2f));
animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 0.2f));
animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 0.0f));
2015-10-29 18:10:07 +01:00
}
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
2015-11-26 22:04:02 +01:00
}
if (animatingItem != null) {
animatingItem.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 1.0f));
2015-11-26 22:04:02 +01:00
}
2015-10-29 18:10:07 +01:00
animatorSet.playTogether(animators);
}
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT > 15) {
listView.setLayerType(View.LAYER_TYPE_NONE, null);
}
2015-11-26 22:04:02 +01:00
if (animatingItem != null) {
ActionBarMenu menu = actionBar.createMenu();
menu.clearItems();
animatingItem = null;
}
2015-10-29 18:10:07 +01:00
callback.run();
}
});
animatorSet.setInterpolator(new DecelerateInterpolator());
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
animatorSet.start();
}
2015-11-26 22:04:02 +01:00
}, 50);
2015-10-29 18:10:07 +01:00
return animatorSet;
}
return null;
}
@Override
public void updatePhotoAtIndex(int index) {
}
@Override
2014-06-12 03:13:15 +02:00
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
if (fileLocation == null) {
return null;
}
2014-11-12 23:16:59 +01:00
TLRPC.FileLocation photoBig = null;
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user != null && user.photo != null && user.photo.photo_big != null) {
photoBig = user.photo.photo_big;
}
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat != null && chat.photo != null && chat.photo.photo_big != null) {
photoBig = chat.photo.photo_big;
}
}
if (photoBig != null && photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = avatarImage;
2015-04-09 20:00:14 +02:00
object.imageReceiver = avatarImage.getImageReceiver();
if (user_id != 0) {
object.dialogId = user_id;
} else if (chat_id != 0) {
object.dialogId = -chat_id;
}
2014-11-12 23:16:59 +01:00
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
2015-04-09 20:00:14 +02:00
object.radius = avatarImage.getImageReceiver().getRoundRadius();
object.scale = avatarImage.getScaleX();
2014-11-12 23:16:59 +01:00
return object;
}
return null;
}
2015-01-02 23:15:07 +01:00
@Override
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
return null;
}
2014-06-11 02:22:42 +02:00
@Override
2014-06-12 03:13:15 +02:00
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
2014-06-11 02:22:42 +02:00
2014-06-12 03:13:15 +02:00
@Override
2014-11-17 23:04:31 +01:00
public void willHidePhotoViewer() {
2015-04-09 20:00:14 +02:00
avatarImage.getImageReceiver().setVisible(true, true);
2014-11-17 23:04:31 +01:00
}
2014-06-12 03:13:15 +02:00
@Override
public boolean isPhotoChecked(int index) { return false; }
@Override
public void setPhotoChecked(int index) { }
@Override
2015-10-29 18:10:07 +01:00
public boolean cancelButtonPressed() { return true; }
2014-06-12 03:13:15 +02:00
@Override
public void sendButtonPressed(int index) { }
@Override
public int getSelectedCount() { return 0; }
2014-06-11 02:22:42 +02:00
2014-11-12 23:16:59 +01:00
private void updateOnlineCount() {
2015-10-29 18:10:07 +01:00
onlineCount = 0;
2014-11-12 23:16:59 +01:00
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
sortedUsers.clear();
2016-03-16 13:26:32 +01:00
if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null) {
for (int a = 0; a < info.participants.participants.size(); a++) {
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getClientUserId()) && user.status.expires > 10000) {
onlineCount++;
}
sortedUsers.add(a);
}
2014-11-12 23:16:59 +01:00
2016-03-16 13:26:32 +01:00
try {
Collections.sort(sortedUsers, new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
TLRPC.User user1 = MessagesController.getInstance().getUser(info.participants.participants.get(rhs).user_id);
TLRPC.User user2 = MessagesController.getInstance().getUser(info.participants.participants.get(lhs).user_id);
int status1 = 0;
int status2 = 0;
if (user1 != null && user1.status != null) {
if (user1.id == UserConfig.getClientUserId()) {
status1 = ConnectionsManager.getInstance().getCurrentTime() + 50000;
} else {
status1 = user1.status.expires;
}
2015-01-02 23:15:07 +01:00
}
2016-03-16 13:26:32 +01:00
if (user2 != null && user2.status != null) {
if (user2.id == UserConfig.getClientUserId()) {
status2 = ConnectionsManager.getInstance().getCurrentTime() + 50000;
} else {
status2 = user2.status.expires;
}
2015-01-02 23:15:07 +01:00
}
2016-03-16 13:26:32 +01:00
if (status1 > 0 && status2 > 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 < 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
2015-01-02 23:15:07 +01:00
return -1;
2016-03-16 13:26:32 +01:00
} else if (status2 < 0 && status1 > 0 || status2 == 0 && status1 != 0) {
2015-01-02 23:15:07 +01:00
return 1;
}
return 0;
2014-11-20 15:45:33 +01:00
}
2016-03-16 13:26:32 +01:00
});
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-01-02 23:15:07 +01:00
2016-03-16 13:26:32 +01:00
if (listAdapter != null) {
listAdapter.notifyItemRangeChanged(emptyRowChat2 + 1, sortedUsers.size());
}
2014-11-12 23:16:59 +01:00
}
}
2015-11-26 22:04:02 +01:00
public void setChatInfo(TLRPC.ChatFull chatInfo) {
info = chatInfo;
if (info != null && info.migrated_from_chat_id != 0) {
mergeDialogId = -info.migrated_from_chat_id;
}
fetchUsersFromChannelInfo();
}
private void fetchUsersFromChannelInfo() {
2016-03-16 13:26:32 +01:00
if (info instanceof TLRPC.TL_channelFull && info.participants != null) {
2015-11-26 22:04:02 +01:00
for (int a = 0; a < info.participants.participants.size(); a++) {
TLRPC.ChatParticipant chatParticipant = info.participants.participants.get(a);
2016-03-16 13:26:32 +01:00
participantsMap.put(chatParticipant.user_id, chatParticipant);
2015-11-26 22:04:02 +01:00
}
}
2014-11-12 23:16:59 +01:00
}
2015-11-26 22:04:02 +01:00
private void kickUser(int uid) {
if (uid != 0) {
MessagesController.getInstance().deleteUserFromChat(chat_id, MessagesController.getInstance().getUser(uid), info);
2016-03-16 13:26:32 +01:00
if (currentChat.megagroup && info != null && info.participants != null) {
2015-11-26 22:04:02 +01:00
boolean changed = false;
2016-03-16 13:26:32 +01:00
for (int a = 0; a < info.participants.participants.size(); a++) {
TLRPC.ChannelParticipant p = ((TLRPC.TL_chatChannelParticipant) info.participants.participants.get(a)).channelParticipant;
2015-11-26 22:04:02 +01:00
if (p.user_id == uid) {
if (info != null) {
info.participants_count--;
}
2016-03-16 13:26:32 +01:00
info.participants.participants.remove(a);
2015-11-26 22:04:02 +01:00
changed = true;
break;
}
}
if (info != null && info.participants != null) {
for (int a = 0; a < info.participants.participants.size(); a++) {
TLRPC.ChatParticipant p = info.participants.participants.get(a);
if (p.user_id == uid) {
info.participants.participants.remove(a);
changed = true;
break;
}
}
}
if (changed) {
2016-03-16 13:26:32 +01:00
updateOnlineCount();
2015-11-26 22:04:02 +01:00
updateRowsIds();
listAdapter.notifyDataSetChanged();
}
}
2014-11-10 12:05:22 +01:00
} else {
2014-11-12 23:16:59 +01:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
2015-09-24 22:52:02 +02:00
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, -(long) chat_id);
} else {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
}
2014-11-12 23:16:59 +01:00
MessagesController.getInstance().deleteUserFromChat(chat_id, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), info);
2015-10-29 18:10:07 +01:00
playProfileAnimation = false;
2014-11-12 23:16:59 +01:00
finishFragment();
2014-11-10 12:05:22 +01:00
}
}
2014-11-12 23:16:59 +01:00
public boolean isChat() {
return chat_id != 0;
}
private void updateRowsIds() {
2016-03-16 13:26:32 +01:00
emptyRow = -1;
phoneRow = -1;
userInfoRow = -1;
userSectionRow = -1;
sectionRow = -1;
sharedMediaRow = -1;
settingsNotificationsRow = -1;
usernameRow = -1;
settingsTimerRow = -1;
settingsKeyRow = -1;
startSecretChatRow = -1;
membersEndRow = -1;
emptyRowChat2 = -1;
addMemberRow = -1;
channelInfoRow = -1;
channelNameRow = -1;
convertRow = -1;
convertHelpRow = -1;
emptyRowChat = -1;
membersSectionRow = -1;
membersRow = -1;
managementRow = -1;
leaveChannelRow = -1;
loadMoreMembersRow = -1;
blockedUsersRow = -1;
2014-11-12 23:16:59 +01:00
rowCount = 0;
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
2015-06-29 19:12:11 +02:00
emptyRow = rowCount++;
2015-11-26 22:04:02 +01:00
if (user == null || !user.bot) {
2015-06-29 19:12:11 +02:00
phoneRow = rowCount++;
}
2014-11-12 23:16:59 +01:00
if (user != null && user.username != null && user.username.length() > 0) {
usernameRow = rowCount++;
}
2016-03-16 13:26:32 +01:00
String about = MessagesController.getInstance().getUserAbout(user.id);
if (about != null) {
userSectionRow = rowCount++;
userInfoRow = rowCount++;
} else {
userSectionRow = -1;
userInfoRow = -1;
2015-06-29 19:12:11 +02:00
}
2014-11-12 23:16:59 +01:00
sectionRow = rowCount++;
settingsNotificationsRow = rowCount++;
sharedMediaRow = rowCount++;
if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
settingsTimerRow = rowCount++;
settingsKeyRow = rowCount++;
}
2016-03-16 13:26:32 +01:00
if (user != null && !user.bot && currentEncryptedChat == null && user.id != UserConfig.getClientUserId()) {
2014-11-12 23:16:59 +01:00
startSecretChatRow = rowCount++;
}
} else if (chat_id != 0) {
if (chat_id > 0) {
emptyRow = rowCount++;
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat) && (info != null && info.about != null && info.about.length() > 0 || currentChat.username != null && currentChat.username.length() > 0)) {
if (info != null && info.about != null && info.about.length() > 0) {
channelInfoRow = rowCount++;
}
if (currentChat.username != null && currentChat.username.length() > 0) {
channelNameRow = rowCount++;
}
sectionRow = rowCount++;
}
2014-11-12 23:16:59 +01:00
settingsNotificationsRow = rowCount++;
sharedMediaRow = rowCount++;
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
2015-11-26 22:04:02 +01:00
if (!currentChat.megagroup && info != null && (currentChat.creator || info.can_view_participants)) {
2015-09-24 22:52:02 +02:00
membersRow = rowCount++;
}
2016-03-16 13:26:32 +01:00
if (!ChatObject.isNotInChat(currentChat) && !currentChat.megagroup && (currentChat.creator || currentChat.editor || currentChat.moderator)) {
2015-09-24 22:52:02 +02:00
managementRow = rowCount++;
}
2015-11-26 22:04:02 +01:00
if (!ChatObject.isNotInChat(currentChat) && currentChat.megagroup && (currentChat.editor || currentChat.creator)) {
blockedUsersRow = rowCount++;
}
if (!currentChat.creator && !currentChat.left && !currentChat.kicked && !currentChat.megagroup) {
leaveChannelRow = rowCount++;
}
2016-03-06 02:49:31 +01:00
if (currentChat.megagroup && (currentChat.editor || currentChat.creator || currentChat.democracy)) {
2015-11-26 22:04:02 +01:00
if (info == null || info.participants_count < MessagesController.getInstance().maxMegagroupCount) {
addMemberRow = rowCount++;
}
}
2016-03-16 13:26:32 +01:00
if (info != null && info.participants != null && !info.participants.participants.isEmpty()) {
2015-11-26 22:04:02 +01:00
emptyRowChat = rowCount++;
membersSectionRow = rowCount++;
emptyRowChat2 = rowCount++;
2016-03-16 13:26:32 +01:00
rowCount += info.participants.participants.size();
2015-11-26 22:04:02 +01:00
membersEndRow = rowCount;
if (!usersEndReached) {
loadMoreMembersRow = rowCount++;
2015-09-24 22:52:02 +02:00
}
}
} else {
2015-11-26 22:04:02 +01:00
if (info != null) {
if (!(info.participants instanceof TLRPC.TL_chatParticipantsForbidden) &&
info.participants.participants.size() < MessagesController.getInstance().maxGroupCount &&
(currentChat.admin || currentChat.creator || !currentChat.admins_enabled)) {
addMemberRow = rowCount++;
}
if (currentChat.creator && info.participants.participants.size() >= MessagesController.getInstance().minGroupConvertSize) {
convertRow = rowCount++;
}
}
emptyRowChat = rowCount++;
if (convertRow != -1) {
convertHelpRow = rowCount++;
} else {
membersSectionRow = rowCount++;
}
if (info != null && !(info.participants instanceof TLRPC.TL_chatParticipantsForbidden)) {
emptyRowChat2 = rowCount++;
rowCount += info.participants.participants.size();
membersEndRow = rowCount;
}
2015-09-24 22:52:02 +02:00
}
2014-11-12 23:16:59 +01:00
} else {
2015-11-26 22:04:02 +01:00
if (!ChatObject.isChannel(currentChat) && info != null && !(info.participants instanceof TLRPC.TL_chatParticipantsForbidden)) {
addMemberRow = rowCount++;
emptyRowChat2 = rowCount++;
rowCount += info.participants.participants.size();
membersEndRow = rowCount;
}
2014-11-12 23:16:59 +01:00
}
2014-11-10 12:05:22 +01:00
}
2014-11-12 23:16:59 +01:00
}
2014-11-10 12:05:22 +01:00
2014-11-12 23:16:59 +01:00
private void updateProfileData() {
if (avatarImage == null || nameTextView == null) {
2014-11-17 03:44:57 +01:00
return;
}
2014-11-12 23:16:59 +01:00
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (user.photo != null) {
photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
}
2015-11-26 22:04:02 +01:00
avatarDrawable.setInfo(user);
2014-11-19 04:46:45 +01:00
avatarImage.setImage(photo, "50_50", avatarDrawable);
2014-11-10 12:05:22 +01:00
2015-11-26 22:04:02 +01:00
String newString = UserObject.getUserName(user);
String newString2;
2015-10-29 18:10:07 +01:00
if (user.id == 333000 || user.id == 777000) {
2015-11-26 22:04:02 +01:00
newString2 = LocaleController.getString("ServiceNotifications", R.string.ServiceNotifications);
} else if (user.bot) {
newString2 = LocaleController.getString("Bot", R.string.Bot);
2015-02-01 19:51:02 +01:00
} else {
2015-11-26 22:04:02 +01:00
newString2 = LocaleController.formatUserStatus(user);
2015-02-01 19:51:02 +01:00
}
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
if (nameTextView[a] == null) {
continue;
}
2016-04-22 15:49:00 +02:00
if (a == 0 && user.phone != null && user.phone.length() != 0 && user.id / 1000 != 777 && user.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(user.id) == null &&
(ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
String phoneString = PhoneFormat.getInstance().format("+" + user.phone);
if (!nameTextView[a].getText().equals(phoneString)) {
nameTextView[a].setText(phoneString);
2015-11-26 22:04:02 +01:00
}
} else {
if (!nameTextView[a].getText().equals(newString)) {
nameTextView[a].setText(newString);
}
}
if (!onlineTextView[a].getText().equals(newString2)) {
onlineTextView[a].setText(newString2);
}
int leftIcon = currentEncryptedChat != null ? R.drawable.ic_lock_header : 0;
2016-04-22 15:49:00 +02:00
int rightIcon = 0;
if (a == 0) {
rightIcon = MessagesController.getInstance().isDialogMuted(dialog_id != 0 ? dialog_id : (long) user_id) ? R.drawable.mute_fixed : 0;
} else if (user.verified) {
rightIcon = R.drawable.check_profile_fixed;
2015-11-26 22:04:02 +01:00
}
2016-04-22 15:49:00 +02:00
nameTextView[a].setLeftDrawable(leftIcon);
nameTextView[a].setRightDrawable(rightIcon);
2015-10-29 18:10:07 +01:00
}
2015-04-09 20:00:14 +02:00
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat != null) {
currentChat = chat;
} else {
chat = currentChat;
2014-11-12 23:16:59 +01:00
}
2015-10-29 18:10:07 +01:00
String newString;
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(chat)) {
2015-11-26 22:04:02 +01:00
if (info == null || !currentChat.megagroup && (info.participants_count == 0 || (currentChat.admin || info.can_view_participants))) {
2016-03-16 13:26:32 +01:00
if (currentChat.megagroup) {
newString = LocaleController.getString("Loading", R.string.Loading).toLowerCase();
2015-09-24 22:52:02 +02:00
} else {
2016-03-16 13:26:32 +01:00
if ((chat.flags & TLRPC.CHAT_FLAG_IS_PUBLIC) != 0) {
newString = LocaleController.getString("ChannelPublic", R.string.ChannelPublic).toLowerCase();
} else {
newString = LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate).toLowerCase();
}
2015-09-24 22:52:02 +02:00
}
} else {
2016-03-16 13:26:32 +01:00
if (currentChat.megagroup && info.participants_count <= 200) {
if (onlineCount > 1 && info.participants_count != 0) {
newString = String.format("%s, %s", LocaleController.formatPluralString("Members", info.participants_count), LocaleController.formatPluralString("Online", onlineCount));
} else {
newString = LocaleController.formatPluralString("Members", info.participants_count);
}
} else {
int result[] = new int[1];
String shortNumber = LocaleController.formatShortNumber(info.participants_count, result);
newString = LocaleController.formatPluralString("Members", result[0]).replace(String.format("%d", result[0]), shortNumber);
}
2015-09-24 22:52:02 +02:00
}
2014-11-12 23:16:59 +01:00
} else {
2015-09-24 22:52:02 +02:00
int count = chat.participants_count;
if (info != null) {
count = info.participants.participants.size();
}
if (count != 0 && onlineCount > 1) {
2015-10-29 18:10:07 +01:00
newString = String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount));
2015-09-24 22:52:02 +02:00
} else {
2015-10-29 18:10:07 +01:00
newString = LocaleController.formatPluralString("Members", count);
2015-09-24 22:52:02 +02:00
}
2014-11-12 23:16:59 +01:00
}
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
if (nameTextView[a] == null) {
continue;
}
if (chat.title != null && !nameTextView[a].getText().equals(chat.title)) {
nameTextView[a].setText(chat.title);
}
2016-04-22 15:49:00 +02:00
nameTextView[a].setLeftDrawable(null);
2015-11-26 22:04:02 +01:00
if (a != 0) {
if (chat.verified) {
2016-04-22 15:49:00 +02:00
nameTextView[a].setRightDrawable(R.drawable.check_profile_fixed);
2015-11-26 22:04:02 +01:00
} else {
2016-04-22 15:49:00 +02:00
nameTextView[a].setRightDrawable(null);
2015-11-26 22:04:02 +01:00
}
} else {
2016-04-22 15:49:00 +02:00
nameTextView[a].setRightDrawable(MessagesController.getInstance().isDialogMuted((long) -chat_id) ? R.drawable.mute_fixed : 0);
2015-11-26 22:04:02 +01:00
}
2016-03-16 13:26:32 +01:00
if (currentChat.megagroup && info != null && info.participants_count <= 200 && onlineCount > 0) {
if (!onlineTextView[a].getText().equals(newString)) {
onlineTextView[a].setText(newString);
}
} else if (a == 0 && ChatObject.isChannel(currentChat) && info != null && info.participants_count != 0 && (currentChat.megagroup || currentChat.broadcast)) {
2015-11-26 22:04:02 +01:00
int result[] = new int[1];
String shortNumber = LocaleController.formatShortNumber(info.participants_count, result);
2016-03-16 13:26:32 +01:00
onlineTextView[a].setText(LocaleController.formatPluralString("Members", result[0]).replace(String.format("%d", result[0]), shortNumber));
2015-11-26 22:04:02 +01:00
} else {
if (!onlineTextView[a].getText().equals(newString)) {
onlineTextView[a].setText(newString);
}
}
2015-10-29 18:10:07 +01:00
}
2014-11-12 23:16:59 +01:00
TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (chat.photo != null) {
photo = chat.photo.photo_small;
photoBig = chat.photo.photo_big;
}
2015-11-26 22:04:02 +01:00
avatarDrawable.setInfo(chat);
avatarImage.setImage(photo, "50_50", avatarDrawable);
2015-04-09 20:00:14 +02:00
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
2014-11-12 23:16:59 +01:00
}
2014-11-10 12:05:22 +01:00
}
private void createActionBarMenu() {
2014-11-11 23:16:17 +01:00
ActionBarMenu menu = actionBar.createMenu();
menu.clearItems();
2015-11-26 22:04:02 +01:00
animatingItem = null;
2013-10-25 17:19:00 +02:00
2016-05-25 23:49:47 +02:00
ActionBarMenuItem item = null;
2014-11-12 23:16:59 +01:00
if (user_id != 0) {
if (ContactsController.getInstance().contactsDict.get(user_id) == null) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
return;
}
2016-05-25 23:49:47 +02:00
item = menu.addItem(10, R.drawable.ic_ab_other);
2015-11-26 22:04:02 +01:00
if (user.bot) {
if (!user.bot_nochats) {
2015-06-29 19:12:11 +02:00
item.addSubItem(invite_to_group, LocaleController.getString("BotInvite", R.string.BotInvite), 0);
}
item.addSubItem(share, LocaleController.getString("BotShare", R.string.BotShare), 0);
}
2014-11-12 23:16:59 +01:00
if (user.phone != null && user.phone.length() != 0) {
item.addSubItem(add_contact, LocaleController.getString("AddContact", R.string.AddContact), 0);
item.addSubItem(share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0);
item.addSubItem(block_contact, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock), 0);
} else {
2015-11-26 22:04:02 +01:00
if (user.bot) {
2015-09-02 00:14:21 +02:00
item.addSubItem(block_contact, !userBlocked ? LocaleController.getString("BotStop", R.string.BotStop) : LocaleController.getString("BotRestart", R.string.BotRestart), 0);
} else {
item.addSubItem(block_contact, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock), 0);
}
2014-11-12 23:16:59 +01:00
}
2013-10-25 17:19:00 +02:00
} else {
2016-05-25 23:49:47 +02:00
item = menu.addItem(10, R.drawable.ic_ab_other);
2014-11-12 23:16:59 +01:00
item.addSubItem(share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0);
item.addSubItem(block_contact, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock), 0);
2014-11-12 23:16:59 +01:00
item.addSubItem(edit_contact, LocaleController.getString("EditContact", R.string.EditContact), 0);
item.addSubItem(delete_contact, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0);
2013-10-25 17:19:00 +02:00
}
2014-11-12 23:16:59 +01:00
} else if (chat_id != 0) {
if (chat_id > 0) {
2015-09-24 22:52:02 +02:00
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
2015-11-26 22:04:02 +01:00
if (writeButton != null) {
boolean isChannel = ChatObject.isChannel(currentChat);
if (isChannel && !currentChat.creator && (!currentChat.megagroup || !currentChat.editor) || !isChannel && !currentChat.admin && !currentChat.creator && currentChat.admins_enabled) {
writeButton.setImageResource(R.drawable.floating_message);
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
} else {
writeButton.setImageResource(R.drawable.floating_camera);
writeButton.setPadding(0, 0, 0, 0);
}
}
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(chat)) {
2016-03-06 02:49:31 +01:00
if (chat.creator || chat.megagroup && chat.editor) {
2015-11-26 22:04:02 +01:00
item = menu.addItem(10, R.drawable.ic_ab_other);
item.addSubItem(edit_channel, LocaleController.getString("ChannelEdit", R.string.ChannelEdit), 0);
}
if (!chat.creator && !chat.left && !chat.kicked && chat.megagroup) {
if (item == null) {
item = menu.addItem(10, R.drawable.ic_ab_other);
}
item.addSubItem(leave_group, LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu), 0);
2015-09-24 22:52:02 +02:00
}
} else {
2016-05-25 23:49:47 +02:00
item = menu.addItem(10, R.drawable.ic_ab_other);
2015-11-26 22:04:02 +01:00
if (chat.creator && chat_id > 0) {
item.addSubItem(set_admins, LocaleController.getString("SetAdmins", R.string.SetAdmins), 0);
}
2015-12-09 19:27:52 +01:00
if (!chat.admins_enabled || chat.creator || chat.admin) {
2015-11-26 22:04:02 +01:00
item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName), 0);
}
2016-03-16 13:26:32 +01:00
if (chat.creator && (info == null || info.participants.participants.size() > 1)) {
item.addSubItem(convert_to_supergroup, LocaleController.getString("ConvertGroupMenu", R.string.ConvertGroupMenu), 0);
}
2015-09-24 22:52:02 +02:00
item.addSubItem(leave_group, LocaleController.getString("DeleteAndExit", R.string.DeleteAndExit), 0);
}
2014-11-12 23:16:59 +01:00
} else {
2016-05-25 23:49:47 +02:00
item = menu.addItem(10, R.drawable.ic_ab_other);
2014-11-21 01:14:44 +01:00
item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName), 0);
2014-11-12 23:16:59 +01:00
}
2013-10-25 17:19:00 +02:00
}
2016-05-25 23:49:47 +02:00
if (item == null) {
item = menu.addItem(10, R.drawable.ic_ab_other);
}
item.addSubItem(add_shortcut, LocaleController.getString("AddShortcut", R.string.AddShortcut), 0);
2013-10-25 17:19:00 +02:00
}
2014-10-14 22:36:15 +02:00
@Override
2015-09-24 22:52:02 +02:00
protected void onDialogDismiss(Dialog dialog) {
2014-10-14 22:36:15 +02:00
if (listView != null) {
listView.invalidateViews();
}
}
2013-10-25 17:19:00 +02:00
@Override
2016-03-16 13:26:32 +01:00
public void didSelectDialog(DialogsActivity fragment, long dialog_id, boolean param) {
2013-10-25 17:19:00 +02:00
if (dialog_id != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
2015-09-02 00:14:21 +02:00
int lower_part = (int) dialog_id;
2013-10-25 17:19:00 +02:00
if (lower_part != 0) {
if (lower_part > 0) {
args.putInt("user_id", lower_part);
2013-10-25 17:19:00 +02:00
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
2013-10-25 17:19:00 +02:00
}
} else {
2015-09-02 00:14:21 +02:00
args.putInt("enc_id", (int) (dialog_id >> 32));
2013-10-25 17:19:00 +02:00
}
2016-03-16 13:26:32 +01:00
if (!MessagesController.checkCanOpenChat(args, fragment)) {
return;
}
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args), true);
removeSelfFromStack();
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
SendMessagesHelper.getInstance().sendMessage(user, dialog_id, null, null, null);
2013-10-25 17:19:00 +02:00
}
}
2015-10-29 18:10:07 +01:00
private class ListAdapter extends RecyclerListView.Adapter {
2013-10-25 17:19:00 +02:00
private Context mContext;
2015-10-29 18:10:07 +01:00
private class Holder extends RecyclerView.ViewHolder {
2013-10-25 17:19:00 +02:00
2015-10-29 18:10:07 +01:00
public Holder(View itemView) {
super(itemView);
2014-11-12 23:16:59 +01:00
}
2013-10-25 17:19:00 +02:00
}
2015-10-29 18:10:07 +01:00
public ListAdapter(Context context) {
mContext = context;
2013-10-25 17:19:00 +02:00
}
@Override
2015-10-29 18:10:07 +01:00
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
switch (viewType) {
case 0:
2014-11-12 23:16:59 +01:00
view = new EmptyCell(mContext);
2015-10-29 18:10:07 +01:00
break;
case 1:
2014-11-10 12:05:22 +01:00
view = new DividerCell(mContext);
view.setPadding(AndroidUtilities.dp(72), 0, 0, 0);
2015-10-29 18:10:07 +01:00
break;
case 2:
view = new TextDetailCell(mContext) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
getBackground().setHotspot(event.getX(), event.getY());
}
}
return super.onTouchEvent(event);
}
};
break;
case 3:
view = new TextCell(mContext) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
getBackground().setHotspot(event.getX(), event.getY());
}
}
return super.onTouchEvent(event);
}
};
break;
case 4:
2016-03-16 13:26:32 +01:00
view = new UserCell(mContext, 61, 0, true) {
2015-10-29 18:10:07 +01:00
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
getBackground().setHotspot(event.getX(), event.getY());
}
}
return super.onTouchEvent(event);
}
};
break;
case 5:
view = new ShadowSectionCell(mContext);
break;
case 6:
2015-11-26 22:04:02 +01:00
view = new TextInfoPrivacyCell(mContext);
TextInfoPrivacyCell cell = (TextInfoPrivacyCell) view;
cell.setBackgroundResource(R.drawable.greydivider);
cell.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ConvertGroupInfo", R.string.ConvertGroupInfo, LocaleController.formatPluralString("Members", MessagesController.getInstance().maxMegagroupCount))));
break;
case 7:
view = new LoadingCell(mContext);
break;
case 8:
view = new AboutLinkCell(mContext);
((AboutLinkCell) view).setDelegate(new AboutLinkCell.AboutLinkCellDelegate() {
@Override
public void didPressUrl(String url) {
if (url.startsWith("@")) {
MessagesController.openByUserName(url.substring(1), ProfileActivity.this, 0);
} else if (url.startsWith("#")) {
DialogsActivity fragment = new DialogsActivity(null);
fragment.setSearchString(url);
presentFragment(fragment);
} else if (url.startsWith("/")) {
if (parentLayout.fragmentsStack.size() > 1) {
BaseFragment previousFragment = parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2);
if (previousFragment instanceof ChatActivity) {
finishFragment();
((ChatActivity) previousFragment).chatActivityEnterView.setCommand(null, url, false, false);
}
}
}
}
});
2015-10-29 18:10:07 +01:00
break;
}
2016-03-16 13:26:32 +01:00
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
2015-10-29 18:10:07 +01:00
return new Holder(view);
}
2013-12-20 20:25:49 +01:00
2015-10-29 18:10:07 +01:00
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
boolean checkBackground = true;
switch (holder.getItemViewType()) {
case 0:
2016-04-22 15:49:00 +02:00
if (i == emptyRowChat || i == emptyRowChat2) {
2015-10-29 18:10:07 +01:00
((EmptyCell) holder.itemView).setHeight(AndroidUtilities.dp(8));
2015-09-24 22:52:02 +02:00
} else {
2015-10-29 18:10:07 +01:00
((EmptyCell) holder.itemView).setHeight(AndroidUtilities.dp(36));
2015-09-24 22:52:02 +02:00
}
2015-10-29 18:10:07 +01:00
break;
case 2:
TextDetailCell textDetailCell = (TextDetailCell) holder.itemView;
if (i == phoneRow) {
String text;
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user.phone != null && user.phone.length() != 0) {
text = PhoneFormat.getInstance().format("+" + user.phone);
} else {
text = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
textDetailCell.setTextAndValueAndIcon(text, LocaleController.getString("PhoneMobile", R.string.PhoneMobile), R.drawable.phone_grey);
} else if (i == usernameRow) {
String text;
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user != null && user.username != null && user.username.length() != 0) {
text = "@" + user.username;
} else {
text = "-";
}
textDetailCell.setTextAndValue(text, LocaleController.getString("Username", R.string.Username));
} else if (i == channelNameRow) {
String text;
if (currentChat != null && currentChat.username != null && currentChat.username.length() != 0) {
text = "@" + currentChat.username;
} else {
text = "-";
}
textDetailCell.setTextAndValue(text, "telegram.me/" + currentChat.username);
2015-09-24 22:52:02 +02:00
}
2015-10-29 18:10:07 +01:00
break;
case 3:
TextCell textCell = (TextCell) holder.itemView;
textCell.setTextColor(0xff212121);
if (i == sharedMediaRow) {
String value;
if (totalMediaCount == -1) {
value = LocaleController.getString("Loading", R.string.Loading);
} else {
2015-11-26 22:04:02 +01:00
value = String.format("%d", totalMediaCount + (totalMediaCountMerge != -1 ? totalMediaCountMerge : 0));
2015-10-29 18:10:07 +01:00
}
textCell.setTextAndValue(LocaleController.getString("SharedMedia", R.string.SharedMedia), value);
} else if (i == settingsTimerRow) {
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32));
String value;
if (encryptedChat.ttl == 0) {
value = LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever);
} else {
value = AndroidUtilities.formatTTLString(encryptedChat.ttl);
}
textCell.setTextAndValue(LocaleController.getString("MessageLifetime", R.string.MessageLifetime), value);
} else if (i == settingsNotificationsRow) {
textCell.setTextAndIcon(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds), R.drawable.profile_list);
} else if (i == startSecretChatRow) {
textCell.setText(LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat));
textCell.setTextColor(0xff37a919);
} else if (i == settingsKeyRow) {
IdenticonDrawable identiconDrawable = new IdenticonDrawable();
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32));
identiconDrawable.setEncryptedChat(encryptedChat);
textCell.setTextAndValueDrawable(LocaleController.getString("EncryptionKey", R.string.EncryptionKey), identiconDrawable);
} else if (i == leaveChannelRow) {
textCell.setTextColor(0xffed3d39);
textCell.setText(LocaleController.getString("LeaveChannel", R.string.LeaveChannel));
2015-11-26 22:04:02 +01:00
} else if (i == convertRow) {
2016-03-16 13:26:32 +01:00
textCell.setText(LocaleController.getString("UpgradeGroup", R.string.UpgradeGroup));
2015-11-26 22:04:02 +01:00
textCell.setTextColor(0xff37a919);
2015-10-29 18:10:07 +01:00
} else if (i == membersRow) {
if (info != null) {
textCell.setTextAndValue(LocaleController.getString("ChannelMembers", R.string.ChannelMembers), String.format("%d", info.participants_count));
} else {
textCell.setText(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
}
} else if (i == managementRow) {
if (info != null) {
textCell.setTextAndValue(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), String.format("%d", info.admins_count));
} else {
textCell.setText(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
}
} else if (i == blockedUsersRow) {
if (info != null) {
textCell.setTextAndValue(LocaleController.getString("ChannelBlockedUsers", R.string.ChannelBlockedUsers), String.format("%d", info.kicked_count));
} else {
textCell.setText(LocaleController.getString("ChannelBlockedUsers", R.string.ChannelBlockedUsers));
}
2015-11-26 22:04:02 +01:00
} else if (i == addMemberRow) {
if (chat_id > 0) {
textCell.setText(LocaleController.getString("AddMember", R.string.AddMember));
} else {
textCell.setText(LocaleController.getString("AddRecipient", R.string.AddRecipient));
}
2015-09-24 22:52:02 +02:00
}
2015-10-29 18:10:07 +01:00
break;
case 4:
2016-03-16 13:26:32 +01:00
UserCell userCell = ((UserCell) holder.itemView);
TLRPC.ChatParticipant part;
if (!sortedUsers.isEmpty()) {
part = info.participants.participants.get(sortedUsers.get(i - emptyRowChat2 - 1));
2015-11-26 22:04:02 +01:00
} else {
2016-03-16 13:26:32 +01:00
part = info.participants.participants.get(i - emptyRowChat2 - 1);
}
if (part != null) {
if (part instanceof TLRPC.TL_chatChannelParticipant) {
TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) part).channelParticipant;
2016-04-22 15:49:00 +02:00
if (channelParticipant instanceof TLRPC.TL_channelParticipantCreator) {
userCell.setIsAdmin(1);
} else if (channelParticipant instanceof TLRPC.TL_channelParticipantEditor || channelParticipant instanceof TLRPC.TL_channelParticipantModerator) {
userCell.setIsAdmin(2);
} else {
userCell.setIsAdmin(0);
}
2016-03-16 13:26:32 +01:00
} else {
2016-04-22 15:49:00 +02:00
if (part instanceof TLRPC.TL_chatParticipantCreator) {
userCell.setIsAdmin(1);
} else if (currentChat.admins_enabled && part instanceof TLRPC.TL_chatParticipantAdmin) {
userCell.setIsAdmin(2);
} else {
userCell.setIsAdmin(0);
}
2016-03-16 13:26:32 +01:00
}
userCell.setData(MessagesController.getInstance().getUser(part.user_id), null, null, i == emptyRowChat2 + 1 ? R.drawable.menu_newgroup : 0);
2015-11-26 22:04:02 +01:00
}
break;
case 8:
AboutLinkCell aboutLinkCell = (AboutLinkCell) holder.itemView;
2016-03-16 13:26:32 +01:00
if (i == userInfoRow) {
String about = MessagesController.getInstance().getUserAbout(user_id);
aboutLinkCell.setTextAndIcon(about, R.drawable.bot_info);
2015-11-26 22:04:02 +01:00
} else if (i == channelInfoRow) {
String text = info.about;
while (text.contains("\n\n\n")) {
text = text.replace("\n\n\n", "\n\n");
}
aboutLinkCell.setTextAndIcon(text, R.drawable.bot_info);
}
2015-10-29 18:10:07 +01:00
break;
default:
checkBackground = false;
}
if (checkBackground) {
boolean enabled = false;
if (user_id != 0) {
2016-04-22 15:49:00 +02:00
enabled = i == phoneRow || i == settingsTimerRow || i == settingsKeyRow || i == settingsNotificationsRow ||
i == sharedMediaRow || i == startSecretChatRow || i == usernameRow || i == userInfoRow;
2015-10-29 18:10:07 +01:00
} else if (chat_id != 0) {
2016-04-22 15:49:00 +02:00
enabled = i == convertRow || i == settingsNotificationsRow || i == sharedMediaRow || i > emptyRowChat2 && i < membersEndRow ||
i == addMemberRow || i == channelNameRow || i == leaveChannelRow || i == membersRow || i == managementRow ||
i == blockedUsersRow || i == channelInfoRow;
}
2015-10-29 18:10:07 +01:00
if (enabled) {
if (holder.itemView.getBackground() == null) {
holder.itemView.setBackgroundResource(R.drawable.list_selector);
}
} else {
if (holder.itemView.getBackground() != null) {
holder.itemView.setBackgroundDrawable(null);
2015-06-29 19:12:11 +02:00
}
}
}
2015-10-29 18:10:07 +01:00
}
@Override
public int getItemCount() {
return rowCount;
2013-10-25 17:19:00 +02:00
}
@Override
public int getItemViewType(int i) {
2016-04-22 15:49:00 +02:00
if (i == emptyRow || i == emptyRowChat || i == emptyRowChat2) {
return 0;
2016-03-16 13:26:32 +01:00
} else if (i == sectionRow || i == userSectionRow) {
return 1;
2015-09-24 22:52:02 +02:00
} else if (i == phoneRow || i == usernameRow || i == channelNameRow) {
return 2;
2015-11-26 22:04:02 +01:00
} else if (i == leaveChannelRow || i == sharedMediaRow || i == settingsTimerRow || i == settingsNotificationsRow || i == startSecretChatRow || i == settingsKeyRow || i == membersRow || i == managementRow || i == blockedUsersRow || i == convertRow || i == addMemberRow) {
return 3;
2014-11-12 23:16:59 +01:00
} else if (i > emptyRowChat2 && i < membersEndRow) {
return 4;
} else if (i == membersSectionRow) {
return 5;
2015-11-26 22:04:02 +01:00
} else if (i == convertHelpRow) {
return 6;
2015-11-26 22:04:02 +01:00
} else if (i == loadMoreMembersRow) {
return 7;
2016-03-16 13:26:32 +01:00
} else if (i == userInfoRow || i == channelInfoRow) {
2015-11-26 22:04:02 +01:00
return 8;
2013-10-25 17:19:00 +02:00
}
return 0;
}
}
}