2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
import android.app.Activity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2014-02-11 14:32:09 +00:00
|
|
|
import android.content.SharedPreferences;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2014-07-10 21:15:39 +00:00
|
|
|
import android.text.InputType;
|
|
|
|
import android.view.Gravity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-07-10 21:15:39 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2014-05-24 22:47:05 +00:00
|
|
|
import android.widget.AbsListView;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.AdapterView;
|
2014-06-03 23:31:48 +00:00
|
|
|
import android.widget.EditText;
|
2014-07-13 10:50:31 +00:00
|
|
|
import android.widget.FrameLayout;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
|
|
|
import org.telegram.android.LocaleController;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLObject;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-02-11 14:32:09 +00:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.ContactsController;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
2014-02-11 14:32:09 +00:00
|
|
|
import org.telegram.messenger.RPCRequest;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.ui.Adapters.ContactsActivityAdapter;
|
|
|
|
import org.telegram.ui.Adapters.ContactsActivitySearchAdapter;
|
2014-02-04 18:36:55 +00:00
|
|
|
import org.telegram.ui.Cells.ChatOrUserCell;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.PinnedHeaderListView;
|
|
|
|
import org.telegram.ui.Views.SectionedBaseAdapter;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2014-02-11 14:32:09 +00:00
|
|
|
import java.util.Locale;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
public class ContactsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
private SectionedBaseAdapter listViewAdapter;
|
|
|
|
private PinnedHeaderListView listView;
|
2014-02-28 22:28:25 +00:00
|
|
|
private ContactsActivitySearchAdapter searchListViewAdapter;
|
2013-10-25 15:19:00 +00:00
|
|
|
private boolean searchWas;
|
|
|
|
private boolean searching;
|
|
|
|
private boolean onlyUsers;
|
|
|
|
private boolean usersAsSections;
|
|
|
|
private boolean destroyAfterSelect;
|
|
|
|
private boolean returnAsResult;
|
|
|
|
private boolean createSecretChat;
|
|
|
|
private boolean creatingChat = false;
|
2014-06-03 23:31:48 +00:00
|
|
|
private String selectAlertString = null;
|
2014-03-25 00:25:32 +00:00
|
|
|
private TextView emptyTextView;
|
2013-10-25 15:19:00 +00:00
|
|
|
private HashMap<Integer, TLRPC.User> ignoreUsers;
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
private String inviteText;
|
|
|
|
private boolean updatingInviteText = false;
|
2014-06-03 23:31:48 +00:00
|
|
|
private ContactsActivityDelegate delegate;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
public static interface ContactsActivityDelegate {
|
2014-07-10 21:15:39 +00:00
|
|
|
public abstract void didSelectContact(TLRPC.User user, String param);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public ContactsActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatCreated);
|
2014-06-03 23:31:48 +00:00
|
|
|
if (arguments != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
onlyUsers = getArguments().getBoolean("onlyUsers", false);
|
|
|
|
destroyAfterSelect = getArguments().getBoolean("destroyAfterSelect", false);
|
|
|
|
usersAsSections = getArguments().getBoolean("usersAsSections", false);
|
|
|
|
returnAsResult = getArguments().getBoolean("returnAsResult", false);
|
|
|
|
createSecretChat = getArguments().getBoolean("createSecretChat", false);
|
2014-06-03 23:31:48 +00:00
|
|
|
selectAlertString = arguments.getString("selectAlertString");
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-11 14:32:09 +00:00
|
|
|
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
inviteText = preferences.getString("invitetext", null);
|
|
|
|
int time = preferences.getInt("invitetexttime", 0);
|
|
|
|
if (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000)) {
|
|
|
|
updateInviteText();
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatCreated);
|
2013-10-25 15:19:00 +00:00
|
|
|
delegate = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
|
|
if (fragmentView == null) {
|
2014-06-12 01:13:15 +00:00
|
|
|
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
|
2014-06-12 15:53:20 +00:00
|
|
|
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
|
2014-06-03 23:31:48 +00:00
|
|
|
if (destroyAfterSelect) {
|
|
|
|
actionBarLayer.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
|
|
|
|
} else {
|
|
|
|
actionBarLayer.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBarLayer.createMenu();
|
|
|
|
menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
|
|
|
searching = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSearchCollapse() {
|
|
|
|
searchListViewAdapter.searchDialogs(null);
|
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
|
|
|
ViewGroup group = (ViewGroup) listView.getParent();
|
|
|
|
listView.setAdapter(listViewAdapter);
|
2014-06-14 08:36:01 +00:00
|
|
|
listViewAdapter.notifyDataSetChanged();
|
2014-06-03 23:31:48 +00:00
|
|
|
if (!LocaleController.isRTL) {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(30), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
} else {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(30), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
listView.setFastScrollAlwaysVisible(true);
|
|
|
|
}
|
|
|
|
listView.setFastScrollEnabled(true);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
if (searchListViewAdapter == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String text = editText.getText().toString();
|
|
|
|
if (text.length() != 0) {
|
|
|
|
searchWas = true;
|
|
|
|
if (listView != null) {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setAdapter(searchListViewAdapter);
|
2014-06-14 08:36:01 +00:00
|
|
|
searchListViewAdapter.notifyDataSetChanged();
|
2014-06-03 23:31:48 +00:00
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
listView.setFastScrollAlwaysVisible(false);
|
|
|
|
}
|
|
|
|
listView.setFastScrollEnabled(false);
|
|
|
|
listView.setVerticalScrollBarEnabled(true);
|
|
|
|
}
|
|
|
|
if (emptyTextView != null) {
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
searchListViewAdapter.searchDialogs(text);
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
fragmentView = inflater.inflate(R.layout.contacts_layout, container, false);
|
|
|
|
|
2014-03-25 00:25:32 +00:00
|
|
|
emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
|
2014-06-03 23:31:48 +00:00
|
|
|
searchListViewAdapter = new ContactsActivitySearchAdapter(getParentActivity(), ignoreUsers);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView);
|
2014-03-25 00:25:32 +00:00
|
|
|
listView.setEmptyView(emptyTextView);
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
listViewAdapter = new ContactsActivityAdapter(getParentActivity(), onlyUsers, usersAsSections, ignoreUsers);
|
2014-02-28 22:28:25 +00:00
|
|
|
listView.setAdapter(listViewAdapter);
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
if (searching && searchWas) {
|
2014-02-28 22:28:25 +00:00
|
|
|
TLRPC.User user = searchListViewAdapter.getItem(i);
|
2014-06-13 10:42:21 +00:00
|
|
|
if (user == null || user.id == UserConfig.getClientUserId()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (returnAsResult) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-10 21:15:39 +00:00
|
|
|
didSelectResult(user, true, null);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
if (createSecretChat) {
|
|
|
|
creatingChat = true;
|
2014-06-03 23:31:48 +00:00
|
|
|
MessagesController.getInstance().startSecretChat(getParentActivity(), user);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", user.id);
|
|
|
|
presentFragment(new ChatActivity(args), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int section = listViewAdapter.getSectionForPosition(i);
|
|
|
|
int row = listViewAdapter.getPositionInSectionForPosition(i);
|
2014-02-11 14:32:09 +00:00
|
|
|
if (row < 0 || section < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
TLRPC.User user = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (usersAsSections) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) {
|
|
|
|
ArrayList<TLRPC.TL_contact> arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section));
|
2014-02-11 14:32:09 +00:00
|
|
|
if (row < arr.size()) {
|
|
|
|
TLRPC.TL_contact contact = arr.get(row);
|
2014-08-22 14:24:33 +00:00
|
|
|
user = MessagesController.getInstance().getUser(contact.user_id);
|
2014-02-11 14:32:09 +00:00
|
|
|
} else {
|
2014-02-04 18:36:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (section == 0) {
|
|
|
|
if (row == 0) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType("text/plain");
|
2014-03-22 22:31:55 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText : LocaleController.getString("InviteText", R.string.InviteText));
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2013-10-25 15:19:00 +00:00
|
|
|
} catch (Exception e) {
|
2013-12-20 19:25:49 +00:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (row - 1 < ContactsController.getInstance().contacts.size()) {
|
2014-08-22 14:24:33 +00:00
|
|
|
user = MessagesController.getInstance().getUser(ContactsController.getInstance().contacts.get(row - 1).user_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user != null) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (user.id == UserConfig.getClientUserId()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (returnAsResult) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-10 21:15:39 +00:00
|
|
|
didSelectResult(user, true, null);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
if (createSecretChat) {
|
|
|
|
creatingChat = true;
|
2014-06-03 23:31:48 +00:00
|
|
|
MessagesController.getInstance().startSecretChat(getParentActivity(), user);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", user.id);
|
|
|
|
presentFragment(new ChatActivity(args), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
ArrayList<ContactsController.Contact> arr = ContactsController.getInstance().contactsSectionsDict.get(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1));
|
2014-02-04 18:36:55 +00:00
|
|
|
ContactsController.Contact contact = arr.get(row);
|
2013-10-25 15:19:00 +00:00
|
|
|
String usePhone = null;
|
2014-02-04 18:36:55 +00:00
|
|
|
if (!contact.phones.isEmpty()) {
|
|
|
|
usePhone = contact.phones.get(0);
|
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
if (usePhone == null || getParentActivity() == null) {
|
2014-02-04 18:36:55 +00:00
|
|
|
return;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2013-10-25 15:19:00 +00:00
|
|
|
final String arg1 = usePhone;
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
try {
|
2013-12-20 19:25:49 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
|
2014-03-22 22:31:55 +00:00
|
|
|
intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText));
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2013-10-25 15:19:00 +00:00
|
|
|
} catch (Exception e) {
|
2013-12-20 19:25:49 +00:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-24 22:47:05 +00:00
|
|
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
|
|
|
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2014-05-24 22:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2014-07-10 21:15:39 +00:00
|
|
|
private void didSelectResult(final TLRPC.User user, boolean useAlert, String param) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (useAlert && selectAlertString != null) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-02 17:36:57 +00:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-09-24 02:17:27 +00:00
|
|
|
builder.setMessage(LocaleController.formatStringSimple(selectAlertString, ContactsController.formatName(user.first_name, user.last_name)));
|
2014-07-10 21:15:39 +00:00
|
|
|
final EditText editText = new EditText(getParentActivity());
|
2014-07-13 10:50:31 +00:00
|
|
|
if (android.os.Build.VERSION.SDK_INT < 11) {
|
|
|
|
editText.setBackgroundResource(android.R.drawable.editbox_background_normal);
|
|
|
|
}
|
2014-07-10 21:15:39 +00:00
|
|
|
editText.setTextSize(18);
|
|
|
|
editText.setText("50");
|
|
|
|
editText.setGravity(Gravity.CENTER);
|
|
|
|
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
|
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
|
|
|
builder.setView(editText);
|
2013-10-25 15:19:00 +00:00
|
|
|
builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2014-07-10 21:15:39 +00:00
|
|
|
didSelectResult(user, false, editText.getText().toString());
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.Cancel, null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-07-10 21:15:39 +00:00
|
|
|
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams)editText.getLayoutParams();
|
|
|
|
if (layoutParams != null) {
|
2014-07-13 10:50:31 +00:00
|
|
|
if (layoutParams instanceof FrameLayout.LayoutParams) {
|
|
|
|
((FrameLayout.LayoutParams)layoutParams).gravity = Gravity.CENTER_HORIZONTAL;
|
|
|
|
}
|
2014-07-10 21:15:39 +00:00
|
|
|
layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(10);
|
|
|
|
editText.setLayoutParams(layoutParams);
|
|
|
|
}
|
2014-07-13 10:50:31 +00:00
|
|
|
editText.setSelection(editText.getText().length());
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
if (delegate != null) {
|
2014-07-10 21:15:39 +00:00
|
|
|
delegate.didSelectContact(user, param);
|
2013-10-25 15:19:00 +00:00
|
|
|
delegate = null;
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
2014-06-03 23:31:48 +00:00
|
|
|
if (listViewAdapter != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.contactsDidLoaded) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.updateInterfaces) {
|
2014-02-04 18:36:55 +00: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 15:19:00 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.encryptedChatCreated) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (createSecretChat && creatingChat) {
|
|
|
|
TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat)args[0];
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putInt("enc_id", encryptedChat.id);
|
|
|
|
presentFragment(new ChatActivity(args2), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
private void updateInviteText() {
|
2014-02-28 22:28:25 +00:00
|
|
|
if (!updatingInviteText) {
|
|
|
|
updatingInviteText = true;
|
|
|
|
TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText();
|
2014-09-13 23:40:36 +00:00
|
|
|
req.lang_code = LocaleController.getLocaleString(Locale.getDefault());
|
2014-02-28 22:28:25 +00:00
|
|
|
if (req.lang_code == null || req.lang_code.length() == 0) {
|
|
|
|
req.lang_code = "en";
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
2014-02-28 22:28:25 +00:00
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
if (error == null) {
|
|
|
|
final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response;
|
|
|
|
if (res.message.length() != 0) {
|
2014-08-22 14:24:33 +00:00
|
|
|
AndroidUtilities.RunOnUIThread(new Runnable() {
|
2014-02-28 22:28:25 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updatingInviteText = false;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putString("invitetext", res.message);
|
|
|
|
editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000));
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
private void updateVisibleRows(int mask) {
|
|
|
|
if (listView != null) {
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = listView.getChildAt(a);
|
|
|
|
if (child instanceof ChatOrUserCell) {
|
|
|
|
((ChatOrUserCell) child).update(mask);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
|
|
|
|
public void setDelegate(ContactsActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIgnoreUsers(HashMap<Integer, TLRPC.User> users) {
|
|
|
|
ignoreUsers = users;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|