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;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2014-03-22 22:31:55 +00:00
|
|
|
import android.widget.Button;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.ContactsController;
|
|
|
|
import org.telegram.android.LocaleController;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLRPC;
|
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;
|
|
|
|
import org.telegram.messenger.Utilities;
|
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
public class ContactAddActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
private int user_id;
|
2013-12-20 19:25:49 +00:00
|
|
|
private String phone = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
private View doneButton;
|
|
|
|
private EditText firstNameField;
|
|
|
|
private EditText lastNameField;
|
|
|
|
private BackupImageView avatarImage;
|
|
|
|
private TextView onlineText;
|
|
|
|
private TextView phoneText;
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public ContactAddActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
user_id = getArguments().getInt("user_id", 0);
|
2013-12-20 19:25:49 +00:00
|
|
|
phone = getArguments().getString("phone");
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
|
2014-06-03 23:31:48 +00:00
|
|
|
return user != null && super.onFragmentCreate();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (fragmentView == null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setCustomView(R.layout.settings_do_action_layout);
|
|
|
|
Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button);
|
|
|
|
cancelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
doneButton = actionBarLayer.findViewById(R.id.done_button);
|
|
|
|
doneButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (firstNameField.getText().length() != 0) {
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
|
2014-06-03 23:31:48 +00:00
|
|
|
user.first_name = firstNameField.getText().toString();
|
|
|
|
user.last_name = lastNameField.getText().toString();
|
|
|
|
ContactsController.getInstance().addContact(user);
|
|
|
|
finishFragment();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-12 15:53:20 +00:00
|
|
|
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
|
2014-06-03 23:31:48 +00:00
|
|
|
TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text);
|
2014-06-12 15:53:20 +00:00
|
|
|
textView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
|
2014-06-03 23:31:48 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false);
|
|
|
|
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user.phone == null) {
|
|
|
|
if (phone != null) {
|
|
|
|
user.phone = PhoneFormat.stripExceptNumbers(phone);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
onlineText = (TextView)fragmentView.findViewById(R.id.settings_online);
|
|
|
|
avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image);
|
2014-06-16 12:36:54 +00:00
|
|
|
avatarImage.processDetach = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
phoneText = (TextView)fragmentView.findViewById(R.id.settings_name);
|
2014-07-02 22:39:05 +00:00
|
|
|
Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
|
2013-12-20 19:25:49 +00:00
|
|
|
phoneText.setTypeface(typeface);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
firstNameField = (EditText)fragmentView.findViewById(R.id.first_name_field);
|
2014-03-22 22:31:55 +00:00
|
|
|
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
|
2013-10-25 15:19:00 +00:00
|
|
|
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
lastNameField.requestFocus();
|
|
|
|
lastNameField.setSelection(lastNameField.length());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
lastNameField = (EditText)fragmentView.findViewById(R.id.last_name_field);
|
2014-03-22 22:31:55 +00:00
|
|
|
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
|
2013-10-25 15:19:00 +00:00
|
|
|
lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
doneButton.performClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
firstNameField.setText(user.first_name);
|
|
|
|
firstNameField.setSelection(firstNameField.length());
|
|
|
|
lastNameField.setText(user.last_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAvatarLayout();
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAvatarLayout() {
|
|
|
|
if (phoneText == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
phoneText.setText(PhoneFormat.getInstance().format("+" + user.phone));
|
2014-05-16 23:05:49 +00:00
|
|
|
onlineText.setText(LocaleController.formatUserStatus(user));
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
}
|
|
|
|
avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
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_STATUS) != 0) {
|
|
|
|
updateAvatarLayout();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean animations = preferences.getBoolean("view_animations", true);
|
|
|
|
if (!animations) {
|
|
|
|
firstNameField.requestFocus();
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.showKeyboard(firstNameField);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public void onOpenAnimationEnd() {
|
|
|
|
firstNameField.requestFocus();
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.showKeyboard(firstNameField);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|