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).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.app.AlertDialog;
|
2014-03-22 23:31:55 +01:00
|
|
|
import android.app.ProgressDialog;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.text.Editable;
|
2015-09-24 22:52:02 +02:00
|
|
|
import android.text.InputFilter;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.EditText;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.LinearLayout;
|
2014-11-13 21:10:14 +01:00
|
|
|
import android.widget.ListView;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.ChatObject;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
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;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-11-14 16:40:15 +01:00
|
|
|
import org.telegram.ui.Cells.GreySectionCell;
|
2014-11-10 12:05:22 +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;
|
2014-12-01 18:56:31 +01:00
|
|
|
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;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2014-03-26 21:16:28 +01:00
|
|
|
import java.util.concurrent.Semaphore;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
public class GroupCreateFinalActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, AvatarUpdater.AvatarUpdaterDelegate {
|
2014-11-17 23:04:31 +01:00
|
|
|
|
|
|
|
private ListAdapter listAdapter;
|
2014-11-13 21:10:14 +01:00
|
|
|
private ListView listView;
|
2014-03-26 21:16:28 +01:00
|
|
|
private EditText nameTextView;
|
2013-10-25 17:19:00 +02:00
|
|
|
private TLRPC.FileLocation avatar;
|
2013-12-20 20:25:49 +01:00
|
|
|
private TLRPC.InputFile uploadedAvatar;
|
2013-10-25 17:19:00 +02:00
|
|
|
private ArrayList<Integer> selectedContacts;
|
|
|
|
private BackupImageView avatarImage;
|
2014-11-06 22:34:47 +01:00
|
|
|
private AvatarDrawable avatarDrawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
private boolean createAfterUpload;
|
|
|
|
private boolean donePressed;
|
|
|
|
private AvatarUpdater avatarUpdater = new AvatarUpdater();
|
2014-03-22 23:31:55 +01:00
|
|
|
private ProgressDialog progressDialog = null;
|
2014-03-26 21:16:28 +01:00
|
|
|
private String nameToSet = null;
|
2015-09-24 22:52:02 +02:00
|
|
|
private int chatType = ChatObject.CHAT_TYPE_CHAT;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private final static int done_button = 1;
|
|
|
|
|
|
|
|
public GroupCreateFinalActivity(Bundle args) {
|
|
|
|
super(args);
|
2015-09-24 22:52:02 +02:00
|
|
|
chatType = args.getInt("chatType", ChatObject.CHAT_TYPE_CHAT);
|
2014-11-10 12:05:22 +01:00
|
|
|
avatarDrawable = new AvatarDrawable();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatDidCreated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatDidFailCreate);
|
2013-10-25 17:19:00 +02:00
|
|
|
avatarUpdater.parentFragment = this;
|
|
|
|
avatarUpdater.delegate = this;
|
2014-03-26 21:16:28 +01:00
|
|
|
selectedContacts = getArguments().getIntegerArrayList("result");
|
2015-02-26 02:32:51 +01:00
|
|
|
final ArrayList<Integer> usersToLoad = new ArrayList<>();
|
2014-03-26 21:16:28 +01:00
|
|
|
for (Integer uid : selectedContacts) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (MessagesController.getInstance().getUser(uid) == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
usersToLoad.add(uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!usersToLoad.isEmpty()) {
|
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2015-02-26 02:32:51 +01:00
|
|
|
final ArrayList<TLRPC.User> users = new ArrayList<>();
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-23 17:30:35 +02:00
|
|
|
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad));
|
2014-03-26 21:16:28 +01:00
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-10-23 17:30:35 +02:00
|
|
|
if (usersToLoad.size() != users.size()) {
|
2014-03-26 21:16:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!users.isEmpty()) {
|
|
|
|
for (TLRPC.User user : users) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putUser(user, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
return super.onFragmentCreate();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatDidCreated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatDidFailCreate);
|
2013-10-25 17:19:00 +02:00
|
|
|
avatarUpdater.clear();
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:04:31 +01:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chatType == ChatObject.CHAT_TYPE_BROADCAST) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == done_button) {
|
|
|
|
if (donePressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nameTextView.getText().length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
donePressed = true;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chatType == ChatObject.CHAT_TYPE_BROADCAST) {
|
2016-03-06 02:49:31 +01:00
|
|
|
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, null, chatType, GroupCreateFinalActivity.this);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
if (avatarUpdater.uploadingAvatar != null) {
|
|
|
|
createAfterUpload = true;
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
progressDialog = new ProgressDialog(getParentActivity());
|
|
|
|
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
|
|
|
progressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
final int reqId = MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, null, chatType, GroupCreateFinalActivity.this);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2015-09-24 22:52:02 +02:00
|
|
|
ConnectionsManager.getInstance().cancelRequest(reqId, true);
|
2015-04-09 20:00:14 +02:00
|
|
|
donePressed = false;
|
|
|
|
try {
|
|
|
|
dialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
progressDialog.show();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
|
|
|
|
|
|
|
fragmentView = new LinearLayout(context);
|
|
|
|
LinearLayout linearLayout = (LinearLayout) fragmentView;
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
linearLayout.addView(frameLayout);
|
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.WRAP_CONTENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
frameLayout.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
avatarImage = new BackupImageView(context);
|
|
|
|
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
|
2015-09-24 22:52:02 +02:00
|
|
|
avatarDrawable.setInfo(5, null, null, chatType == ChatObject.CHAT_TYPE_BROADCAST);
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarImage.setImageDrawable(avatarDrawable);
|
|
|
|
frameLayout.addView(avatarImage);
|
|
|
|
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
|
|
|
|
layoutParams1.width = AndroidUtilities.dp(64);
|
|
|
|
layoutParams1.height = AndroidUtilities.dp(64);
|
|
|
|
layoutParams1.topMargin = AndroidUtilities.dp(12);
|
|
|
|
layoutParams1.bottomMargin = AndroidUtilities.dp(12);
|
|
|
|
layoutParams1.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(16);
|
|
|
|
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : 0;
|
|
|
|
layoutParams1.gravity = Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
|
|
|
avatarImage.setLayoutParams(layoutParams1);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chatType != ChatObject.CHAT_TYPE_BROADCAST) {
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarDrawable.setDrawPhoto(true);
|
|
|
|
avatarImage.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
CharSequence[] items;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (avatar != null) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
|
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
|
2014-07-27 00:28:33 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +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) {
|
|
|
|
avatar = null;
|
|
|
|
uploadedAvatar = null;
|
|
|
|
avatarImage.setImage(avatar, "50_50", avatarDrawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
nameTextView = new EditText(context);
|
2015-09-24 22:52:02 +02:00
|
|
|
nameTextView.setHint(chatType == ChatObject.CHAT_TYPE_CHAT ? LocaleController.getString("EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder) : LocaleController.getString("EnterListName", R.string.EnterListName));
|
2015-04-09 20:00:14 +02:00
|
|
|
if (nameToSet != null) {
|
|
|
|
nameTextView.setText(nameToSet);
|
|
|
|
nameToSet = null;
|
|
|
|
}
|
|
|
|
nameTextView.setMaxLines(4);
|
|
|
|
nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
nameTextView.setHintTextColor(0xff979797);
|
|
|
|
nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
nameTextView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
|
|
|
nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
|
2015-09-24 22:52:02 +02:00
|
|
|
InputFilter[] inputFilters = new InputFilter[1];
|
|
|
|
inputFilters[0] = new InputFilter.LengthFilter(100);
|
|
|
|
nameTextView.setFilters(inputFilters);
|
2015-04-09 20:00:14 +02:00
|
|
|
AndroidUtilities.clearCursorDrawable(nameTextView);
|
|
|
|
nameTextView.setTextColor(0xff212121);
|
|
|
|
frameLayout.addView(nameTextView);
|
|
|
|
layoutParams1 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams1.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams1.height = LayoutHelper.WRAP_CONTENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams1.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(96);
|
|
|
|
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(96) : AndroidUtilities.dp(16);
|
|
|
|
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
|
|
|
nameTextView.setLayoutParams(layoutParams1);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chatType != ChatObject.CHAT_TYPE_BROADCAST) {
|
2015-04-09 20:00:14 +02:00
|
|
|
nameTextView.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
2015-09-24 22:52:02 +02:00
|
|
|
avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false);
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarImage.invalidate();
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
GreySectionCell sectionCell = new GreySectionCell(context);
|
|
|
|
sectionCell.setText(LocaleController.formatPluralString("Members", selectedContacts.size()));
|
|
|
|
linearLayout.addView(sectionCell);
|
|
|
|
|
|
|
|
listView = new ListView(context);
|
|
|
|
listView.setDivider(null);
|
|
|
|
listView.setDividerHeight(0);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
|
|
|
linearLayout.addView(listView);
|
|
|
|
layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 20:25:49 +01:00
|
|
|
public void didUploadedPhoto(final TLRPC.InputFile file, final TLRPC.PhotoSize small, final TLRPC.PhotoSize big) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
uploadedAvatar = file;
|
|
|
|
avatar = small.location;
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarImage.setImage(avatar, "50_50", avatarDrawable);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (createAfterUpload) {
|
2013-12-20 20:25:49 +01:00
|
|
|
FileLog.e("tmessages", "avatar did uploaded");
|
2016-03-06 02:49:31 +01:00
|
|
|
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, null, chatType, GroupCreateFinalActivity.this);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-26 21:16:28 +01:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2013-10-25 17:19:00 +02:00
|
|
|
avatarUpdater.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
if (avatarUpdater != null && avatarUpdater.currentPicturePath != null) {
|
|
|
|
args.putString("path", avatarUpdater.currentPicturePath);
|
|
|
|
}
|
|
|
|
if (nameTextView != null) {
|
|
|
|
String text = nameTextView.getText().toString();
|
|
|
|
if (text != null && text.length() != 0) {
|
|
|
|
args.putString("nameTextView", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
if (avatarUpdater != null) {
|
|
|
|
avatarUpdater.currentPicturePath = args.getString("path");
|
|
|
|
}
|
|
|
|
String text = args.getString("nameTextView");
|
|
|
|
if (text != null) {
|
|
|
|
if (nameTextView != null) {
|
|
|
|
nameTextView.setText(text);
|
|
|
|
} else {
|
|
|
|
nameToSet = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2015-10-29 18:10:07 +01:00
|
|
|
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
if (isOpen) {
|
|
|
|
nameTextView.requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(nameTextView);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, final Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.updateInterfaces) {
|
2014-02-04 19:36:55 +01:00
|
|
|
int mask = (Integer)args[0];
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
|
|
|
updateVisibleRows(mask);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.chatDidFailCreate) {
|
2014-03-22 23:31:55 +01:00
|
|
|
if (progressDialog != null) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
donePressed = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.chatDidCreated) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (progressDialog != null) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
int chat_id = (Integer)args[0];
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putInt("chat_id", chat_id);
|
|
|
|
presentFragment(new ChatActivity(args2), true);
|
|
|
|
if (uploadedAvatar != null) {
|
|
|
|
MessagesController.getInstance().changeChatAvatar(chat_id, uploadedAvatar);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private void updateVisibleRows(int mask) {
|
|
|
|
if (listView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = listView.getChildAt(a);
|
2014-11-10 12:05:22 +01:00
|
|
|
if (child instanceof UserCell) {
|
|
|
|
((UserCell) child).update(mask);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
private class ListAdapter extends BaseFragmentAdapter {
|
2013-10-25 17:19:00 +02:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int position) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-13 21:10:14 +01:00
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
if (view == null) {
|
2016-03-16 13:26:32 +01:00
|
|
|
view = new UserCell(mContext, 1, 0, false);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2014-11-14 16:40:15 +01:00
|
|
|
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(selectedContacts.get(i));
|
2014-11-13 21:10:14 +01:00
|
|
|
((UserCell) view).setData(user, null, null, 0);
|
|
|
|
return view;
|
2014-11-14 16:40:15 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return selectedContacts.size();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|