2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
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 23:31:55 +01:00
|
|
|
import android.widget.Button;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-03-22 23:31:55 +01:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
public class ChatProfileChangeNameActivity extends BaseFragment {
|
|
|
|
private EditText firstNameField;
|
|
|
|
private View headerLabelView;
|
|
|
|
private int chat_id;
|
|
|
|
private View doneButton;
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public ChatProfileChangeNameActivity(Bundle args) {
|
|
|
|
super(args);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
|
|
|
chat_id = getArguments().getInt("chat_id", 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
|
|
if (fragmentView == null) {
|
|
|
|
actionBarLayer.setCustomView(R.layout.settings_do_action_layout);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
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) {
|
|
|
|
saveName();
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
|
|
|
|
TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text);
|
|
|
|
textView.setText(LocaleController.getString("Done", R.string.Done));
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
fragmentView = inflater.inflate(R.layout.chat_profile_change_name_layout, container, false);
|
|
|
|
|
2014-03-22 23:31:55 +01:00
|
|
|
TLRPC.Chat currentChat = MessagesController.getInstance().chats.get(chat_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
firstNameField = (EditText)fragmentView.findViewById(R.id.first_name_field);
|
2014-03-22 23:31:55 +01:00
|
|
|
firstNameField.setHint(LocaleController.getString("GroupName", R.string.GroupName));
|
2013-10-25 17:19:00 +02:00
|
|
|
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
2014-04-05 02:38:10 +02:00
|
|
|
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
doneButton.performClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
firstNameField.setText(currentChat.title);
|
|
|
|
firstNameField.setSelection(firstNameField.length());
|
|
|
|
|
|
|
|
TextView headerLabel = (TextView)fragmentView.findViewById(R.id.settings_section_text);
|
2014-03-22 23:31:55 +01:00
|
|
|
headerLabel.setText(LocaleController.getString("EnterGroupNameTitle", R.string.EnterGroupNameTitle));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 17:19:00 +02:00
|
|
|
boolean animations = preferences.getBoolean("view_animations", true);
|
|
|
|
if (!animations) {
|
|
|
|
firstNameField.requestFocus();
|
|
|
|
Utilities.showKeyboard(firstNameField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onOpenAnimationEnd() {
|
|
|
|
firstNameField.requestFocus();
|
|
|
|
Utilities.showKeyboard(firstNameField);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void saveName() {
|
2014-03-22 23:31:55 +01:00
|
|
|
MessagesController.getInstance().changeChatTitle(chat_id, firstNameField.getText().toString());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|