Delete some files; add native functions for readling mrloginparam_t.

This commit is contained in:
B. Petersen
2016-10-07 15:20:18 +02:00
parent 55ebcfe8c1
commit 4c686bb278
10 changed files with 106 additions and 5832 deletions
+89 -3
View File
@@ -31,11 +31,10 @@
#define CHAR_REF(a) \
const char* a##Ptr = (*env)->GetStringUTFChars(env, (a), 0); \
if( a##Ptr == NULL ) { return 0; }
const char* a##Ptr = (a)? (*env)->GetStringUTFChars(env, (a), 0) : NULL; /* passing a NULL-jstring results in a NULL-ptr */
#define CHAR_UNREF(a) \
(*env)->ReleaseStringUTFChars(env, (a), a##Ptr);
if(a) { (*env)->ReleaseStringUTFChars(env, (a), a##Ptr); }
#define JSTRING_NEW(a) \
(*env)->NewStringUTF(env, a? a : "") /*should handle NULL arguments!*/
@@ -140,6 +139,18 @@ JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrMailboxGetConfig(JNIEn
}
JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrMailboxSuggestConfig(JNIEnv *env, jclass c, jlong hMailbox)
{
return (jlong)mrmailbox_suggest_config((mrmailbox_t*)hMailbox);
}
JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrMailboxIsConfigured(JNIEnv *env, jclass c, jlong hMailbox)
{
return (jint)mrmailbox_is_configured((mrmailbox_t*)hMailbox);
}
/*******************************************************************************
* MrChatlist
******************************************************************************/
@@ -337,6 +348,81 @@ JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrPoortextGetState(JNIEnv *
}
/*******************************************************************************
* MrLoginparam
******************************************************************************/
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrLoginparamUnref(JNIEnv *env, jclass c, jlong hLoginparam)
{
return mrloginparam_unref((mrloginparam_t*)hLoginparam);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetAddr(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_addr);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetMailServer(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_mail_server);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetMailUser(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_mail_user);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetMailPw(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_mail_pw);
}
JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrLoginparamGetMailPort(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return (jint)ths->m_mail_port;
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetSendServer(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_send_server);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetSendUser(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_send_user);
}
JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrLoginparamGetSendPw(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_send_pw);
}
JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrLoginparamGetSendPort(JNIEnv *env, jclass c, jlong hLoginparam)
{
mrloginparam_t* ths = (mrloginparam_t*)hLoginparam; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return (jint)ths->m_send_port;
}
/*******************************************************************************
* Tools
******************************************************************************/
@@ -89,6 +89,11 @@ public class MrMailbox {
public native static long MrMailboxGetChatlist (long hMailbox); // returns hChatlist which must be unref'd after usage
public native static long MrMailboxGetChatById (long hMailbox, int id); // return hChat which must be unref'd after usage
public native static int MrMailboxSetConfig (long hMailbox, String key, String value); // value may be NULL
public native static String MrMailboxGetConfig (long hMailbox, String key, String def); // def may be NULL, returns empty string as NULL
public native static long MrMailboxSuggestConfig (long hMailbox); // return hLoginparam which must be unref'd after usage
public native static int MrMailboxIsConfigured (long hMailbox);
// MrChatlist objects
public native static void MrChatlistUnref (long hChatlist);
public native static int MrChatlistGetCnt (long hChatlist);
@@ -125,6 +130,18 @@ public class MrMailbox {
public native static long MrPoortextGetTimestamp (long hPoortext);
public native static int MrPoortextGetState (long hPoortext);
// MrLoginparam objects
public native static void MrLoginparamUnref (long hLoginparam);
public native static String MrLoginparamGetAddr (long hLoginparam);
public native static String MrLoginparamGetMailServer (long hLoginparam);
public native static String MrLoginparamGetMailUser (long hLoginparam);
public native static String MrLoginparamGetMailPw (long hLoginparam);
public native static int MrLoginparamGetMailPort (long hLoginparam);
public native static String MrLoginparamGetSendServer (long hLoginparam);
public native static String MrLoginparamGetSendUser (long hLoginparam);
public native static String MrLoginparamGetSendPw (long hLoginparam);
public native static int MrLoginparamGetSendPort (long hLoginparam);
// Tools
public native static void MrStockAddStr (int id, String str);
public native static String MrGetVersionStr ();
File diff suppressed because it is too large Load Diff
@@ -1,156 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* 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.
*/
package org.telegram.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.LayoutHelper;
public class ChangePhoneHelpActivity extends BaseFragment {
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
TLRPC.User user = UserConfig.getCurrentUser();
String value;
if (user != null && user.phone != null && user.phone.length() != 0) {
value = PhoneFormat.getInstance().format("+" + user.phone);
} else {
value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
actionBar.setTitle(value);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new RelativeLayout(context);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
RelativeLayout relativeLayout = (RelativeLayout) fragmentView;
ScrollView scrollView = new ScrollView(context);
relativeLayout.addView(scrollView);
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
layoutParams3.width = LayoutHelper.MATCH_PARENT;
layoutParams3.height = LayoutHelper.WRAP_CONTENT;
layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
scrollView.setLayoutParams(layoutParams3);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
scrollView.addView(linearLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams);
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.phone_change);
linearLayout.addView(imageView);
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
imageView.setLayoutParams(layoutParams2);
TextView textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff212121);
try {
textView.setText(AndroidUtilities.replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
} catch (Exception e) {
FileLog.e("tmessages", e);
textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
}
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(56);
textView.setLayoutParams(layoutParams2);
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff4d83b3);
textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setPadding(0, AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10));
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.width = LayoutHelper.WRAP_CONTENT;
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(46);
textView.setLayoutParams(layoutParams2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
presentFragment(new ChangePhoneActivity(), true);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
});
return fragmentView;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,605 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* 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.
*/
package org.telegram.ui;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.AvatarUpdater;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.LayoutHelper;
import java.util.concurrent.Semaphore;
public class ChannelEditActivity extends BaseFragment implements AvatarUpdater.AvatarUpdaterDelegate, NotificationCenter.NotificationCenterDelegate {
private View doneButton;
private EditText nameTextView;
private EditText descriptionTextView;
private BackupImageView avatarImage;
private AvatarDrawable avatarDrawable;
private AvatarUpdater avatarUpdater;
private ProgressDialog progressDialog;
private TextSettingsCell typeCell;
private TextSettingsCell adminCell;
private TLRPC.FileLocation avatar;
private TLRPC.Chat currentChat;
private TLRPC.ChatFull info;
private int chatId;
private TLRPC.InputFile uploadedAvatar;
private boolean signMessages;
private boolean createAfterUpload;
private boolean donePressed;
private final static int done_button = 1;
public ChannelEditActivity(Bundle args) {
super(args);
avatarDrawable = new AvatarDrawable();
avatarUpdater = new AvatarUpdater();
chatId = args.getInt("chat_id", 0);
}
@SuppressWarnings("unchecked")
@Override
public boolean onFragmentCreate() {
currentChat = MessagesController.getInstance().getChat(chatId);
if (currentChat == null) {
final Semaphore semaphore = new Semaphore(0);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentChat = MessagesStorage.getInstance().getChat(chatId);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentChat != null) {
MessagesController.getInstance().putChat(currentChat, true);
} else {
return false;
}
if (info == null) {
MessagesStorage.getInstance().loadChatInfo(chatId, semaphore, false, false);
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (info == null) {
return false;
}
}
}
avatarUpdater.parentFragment = this;
avatarUpdater.delegate = this;
signMessages = currentChat.signatures;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
if (avatarUpdater != null) {
avatarUpdater.clear();
}
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
}
@Override
public void onResume() {
super.onResume();
AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid);
}
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
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.length() == 0) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(nameTextView, 2, 0);
return;
}
donePressed = true;
if (avatarUpdater.uploadingAvatar != null) {
createAfterUpload = true;
progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createAfterUpload = false;
progressDialog = null;
donePressed = false;
try {
dialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
progressDialog.show();
return;
}
if (!currentChat.title.equals(nameTextView.getText().toString())) {
MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString());
}
if (info != null && !info.about.equals(descriptionTextView.getText().toString())) {
MessagesController.getInstance().updateChannelAbout(chatId, descriptionTextView.getText().toString(), info);
}
if (signMessages != currentChat.signatures) {
currentChat.signatures = true;
MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages);
}
if (uploadedAvatar != null) {
MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar);
} else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) {
MessagesController.getInstance().changeChatAvatar(chatId, null);
}
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
LinearLayout linearLayout;
fragmentView = new ScrollView(context);
fragmentView.setBackgroundColor(0xfff0f0f0);
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
linearLayout = new LinearLayout(context);
scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));
LinearLayout linearLayout2 = new LinearLayout(context);
linearLayout2.setOrientation(LinearLayout.VERTICAL);
linearLayout2.setBackgroundColor(0xffffffff);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
FrameLayout frameLayout = new FrameLayout(context);
linearLayout2.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null, false);
avatarDrawable.setDrawPhoto(true);
frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
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)};
}
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);
}
}
});
showDialog(builder.create());
}
});
nameTextView = new EditText(context);
if (currentChat.megagroup) {
nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
} else {
nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
}
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_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(100);
nameTextView.setFilters(inputFilters);
AndroidUtilities.clearCursorDrawable(nameTextView);
nameTextView.setTextColor(0xff212121);
frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0, LocaleController.isRTL ? 96 : 16, 0));
nameTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false);
avatarImage.invalidate();
}
});
View lineView = new View(context);
lineView.setBackgroundColor(0xffcfcfcf);
linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
linearLayout2 = new LinearLayout(context);
linearLayout2.setOrientation(LinearLayout.VERTICAL);
linearLayout2.setBackgroundColor(0xffffffff);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
descriptionTextView = new EditText(context);
descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
descriptionTextView.setHintTextColor(0xff979797);
descriptionTextView.setTextColor(0xff212121);
descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
descriptionTextView.setBackgroundDrawable(null);
descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(255);
descriptionTextView.setFilters(inputFilters);
descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder", R.string.DescriptionOptionalPlaceholder));
AndroidUtilities.clearCursorDrawable(descriptionTextView);
linearLayout2.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6));
descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
}
});
descriptionTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
}
});
ShadowSectionCell sectionCell = new ShadowSectionCell(context);
sectionCell.setSize(20);
linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (currentChat.megagroup || !currentChat.megagroup) {
frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0xffffffff);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
typeCell = new TextSettingsCell(context);
updateTypeCell();
typeCell.setBackgroundResource(R.drawable.list_selector);
frameLayout.addView(typeCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
lineView = new View(context);
lineView.setBackgroundColor(0xffcfcfcf);
linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0xffffffff);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (!currentChat.megagroup) {
TextCheckCell textCheckCell = new TextCheckCell(context);
textCheckCell.setBackgroundResource(R.drawable.list_selector);
textCheckCell.setTextAndCheck(LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages), signMessages, false);
frameLayout.addView(textCheckCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
textCheckCell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signMessages = !signMessages;
((TextCheckCell) v).setChecked(signMessages);
}
});
TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
infoCell.setBackgroundResource(R.drawable.greydivider);
infoCell.setText(LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo));
linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
} else {
adminCell = new TextSettingsCell(context);
updateAdminCell();
adminCell.setBackgroundResource(R.drawable.list_selector);
frameLayout.addView(adminCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
adminCell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putInt("chat_id", chatId);
args.putInt("type", 1);
presentFragment(new ChannelUsersActivity(args));
}
});
sectionCell = new ShadowSectionCell(context);
sectionCell.setSize(20);
linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (!currentChat.creator) {
sectionCell.setBackgroundResource(R.drawable.greydivider_bottom);
}
}
}
if (currentChat.creator) {
frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0xffffffff);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
TextSettingsCell textCell = new TextSettingsCell(context);
textCell.setTextColor(0xffed3d39);
textCell.setBackgroundResource(R.drawable.list_selector);
if (currentChat.megagroup) {
textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false);
} else {
textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
}
frameLayout.addView(textCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
textCell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (currentChat.megagroup) {
builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
} else {
builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
}
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) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, -(long) chatId);
} else {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
}
MessagesController.getInstance().deleteUserFromChat(chatId, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), info);
finishFragment();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
});
TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
infoCell.setBackgroundResource(R.drawable.greydivider_bottom);
if (currentChat.megagroup) {
infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo));
} else {
infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo));
}
linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
nameTextView.setText(currentChat.title);
nameTextView.setSelection(nameTextView.length());
if (info != null) {
descriptionTextView.setText(info.about);
}
if (currentChat.photo != null) {
avatar = currentChat.photo.photo_small;
avatarImage.setImage(avatar, "50_50", avatarDrawable);
} else {
avatarImage.setImageDrawable(avatarDrawable);
}
return fragmentView;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.chatInfoDidLoaded) {
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (chatFull.id == chatId) {
if (info == null) {
descriptionTextView.setText(chatFull.about);
}
info = chatFull;
updateAdminCell();
updateTypeCell();
}
} else if (id == NotificationCenter.updateInterfaces) {
int updateMask = (Integer) args[0];
if ((updateMask & MessagesController.UPDATE_MASK_CHANNEL) != 0) {
updateTypeCell();
}
}
}
@Override
public void didUploadedPhoto(final TLRPC.InputFile file, final TLRPC.PhotoSize small, final TLRPC.PhotoSize big) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
uploadedAvatar = file;
avatar = small.location;
avatarImage.setImage(avatar, "50_50", avatarDrawable);
if (createAfterUpload) {
try {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
doneButton.performClick();
}
}
});
}
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
avatarUpdater.onActivityResult(requestCode, resultCode, data);
}
@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");
}
}
public void setInfo(TLRPC.ChatFull chatFull) {
info = chatFull;
}
private void updateTypeCell() {
String type = currentChat.username == null || currentChat.username.length() == 0 ? LocaleController.getString("ChannelTypePrivate", R.string.ChannelTypePrivate) : LocaleController.getString("ChannelTypePublic", R.string.ChannelTypePublic);
if (currentChat.megagroup) {
typeCell.setTextAndValue(LocaleController.getString("GroupType", R.string.GroupType), type, false);
} else {
typeCell.setTextAndValue(LocaleController.getString("ChannelType", R.string.ChannelType), type, false);
}
if (currentChat.creator && (info == null || info.can_set_username)) {
typeCell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putInt("chat_id", chatId);
ChannelEditTypeActivity fragment = new ChannelEditTypeActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
}
});
typeCell.setTextColor(0xff212121);
typeCell.setTextValueColor(0xff2f8cc9);
} else {
typeCell.setOnClickListener(null);
typeCell.setTextColor(0xffa8a8a8);
typeCell.setTextValueColor(0xffa8a8a8);
}
}
private void updateAdminCell() {
if (adminCell == null) {
return;
}
if (info != null) {
adminCell.setTextAndValue(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), String.format("%d", info.admins_count), false);
} else {
adminCell.setText(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), false);
}
}
}
@@ -1,538 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* 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.
*/
package org.telegram.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.RadioButtonCell;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextBlockCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Components.LayoutHelper;
import java.util.concurrent.Semaphore;
public class ChannelEditTypeActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private LinearLayout linkContainer;
private LinearLayout publicContainer;
private TextBlockCell privateContainer;
private RadioButtonCell radioButtonCell1;
private RadioButtonCell radioButtonCell2;
private TextInfoPrivacyCell typeInfoCell;
private TextView checkTextView;
private HeaderCell headerCell;
private EditText nameTextView;
private boolean isPrivate = false;
private boolean loadingInvite;
private TLRPC.ExportedChatInvite invite;
private int checkReqId = 0;
private String lastCheckName = null;
private Runnable checkRunnable = null;
private boolean lastNameAvailable = false;
private TLRPC.Chat currentChat;
private int chatId;
private boolean donePressed;
private final static int done_button = 1;
public ChannelEditTypeActivity(Bundle args) {
super(args);
chatId = args.getInt("chat_id", 0);
}
@SuppressWarnings("unchecked")
@Override
public boolean onFragmentCreate() {
currentChat = MessagesController.getInstance().getChat(chatId);
if (currentChat == null) {
final Semaphore semaphore = new Semaphore(0);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentChat = MessagesStorage.getInstance().getChat(chatId);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentChat != null) {
MessagesController.getInstance().putChat(currentChat, true);
} else {
return false;
}
}
isPrivate = currentChat.username == null || currentChat.username.length() == 0;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
}
@Override
public void onResume() {
super.onResume();
AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid);
}
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (donePressed) {
return;
}
if (!isPrivate && ((currentChat.username == null && nameTextView.length() != 0) || (currentChat.username != null && !currentChat.username.equalsIgnoreCase(nameTextView.getText().toString())))) {
if (nameTextView.length() != 0 && !lastNameAvailable) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
return;
}
}
donePressed = true;
String oldUserName = currentChat.username != null ? currentChat.username : "";
String newUserName = isPrivate ? "" : nameTextView.getText().toString();
if (!oldUserName.equals(newUserName)) {
MessagesController.getInstance().updateChannelUserName(chatId, newUserName);
}
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
LinearLayout linearLayout;
fragmentView = new ScrollView(context);
fragmentView.setBackgroundColor(0xfff0f0f0);
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
linearLayout = new LinearLayout(context);
scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
if (currentChat.megagroup) {
actionBar.setTitle(LocaleController.getString("GroupType", R.string.GroupType));
} else {
actionBar.setTitle(LocaleController.getString("ChannelType", R.string.ChannelType));
}
LinearLayout linearLayout2 = new LinearLayout(context);
linearLayout2.setOrientation(LinearLayout.VERTICAL);
linearLayout2.setBackgroundColor(0xffffffff);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell1 = new RadioButtonCell(context);
radioButtonCell1.setBackgroundResource(R.drawable.list_selector);
if (currentChat.megagroup) {
radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic), LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), !isPrivate, false);
} else {
radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false);
}
linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isPrivate) {
return;
}
isPrivate = false;
updatePrivatePublic();
}
});
radioButtonCell2 = new RadioButtonCell(context);
radioButtonCell2.setBackgroundResource(R.drawable.list_selector);
if (currentChat.megagroup) {
radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate), LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), isPrivate, false);
} else {
radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate, false);
}
linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isPrivate) {
return;
}
isPrivate = true;
updatePrivatePublic();
}
});
ShadowSectionCell sectionCell = new ShadowSectionCell(context);
linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
linkContainer = new LinearLayout(context);
linkContainer.setOrientation(LinearLayout.VERTICAL);
linkContainer.setBackgroundColor(0xffffffff);
linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
headerCell = new HeaderCell(context);
linkContainer.addView(headerCell);
publicContainer = new LinearLayout(context);
publicContainer.setOrientation(LinearLayout.HORIZONTAL);
linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));
EditText editText = new EditText(context);
editText.setText("telegram.me/");
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
editText.setHintTextColor(0xff979797);
editText.setTextColor(0xff212121);
editText.setMaxLines(1);
editText.setLines(1);
editText.setEnabled(false);
editText.setBackgroundDrawable(null);
editText.setPadding(0, 0, 0, 0);
editText.setSingleLine(true);
editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));
nameTextView = new EditText(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
if (!isPrivate) {
nameTextView.setText(currentChat.username);
}
nameTextView.setHintTextColor(0xff979797);
nameTextView.setTextColor(0xff212121);
nameTextView.setMaxLines(1);
nameTextView.setLines(1);
nameTextView.setBackgroundDrawable(null);
nameTextView.setPadding(0, 0, 0, 0);
nameTextView.setSingleLine(true);
nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
nameTextView.setHint(LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
AndroidUtilities.clearCursorDrawable(nameTextView);
publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
nameTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
checkUserName(nameTextView.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
privateContainer = new TextBlockCell(context);
privateContainer.setBackgroundResource(R.drawable.list_selector);
linkContainer.addView(privateContainer);
privateContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (invite == null) {
return;
}
try {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link);
clipboard.setPrimaryClip(clip);
Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
checkTextView = new TextView(context);
checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
checkTextView.setVisibility(View.GONE);
linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));
typeInfoCell = new TextInfoPrivacyCell(context);
typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
updatePrivatePublic();
return fragmentView;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.chatInfoDidLoaded) {
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (chatFull.id == chatId) {
invite = chatFull.exported_invite;
updatePrivatePublic();
}
}
}
public void setInfo(TLRPC.ChatFull chatFull) {
if (chatFull != null) {
if (chatFull.exported_invite instanceof TLRPC.TL_chatInviteExported) {
invite = chatFull.exported_invite;
} else {
generateLink();
}
}
}
private void updatePrivatePublic() {
radioButtonCell1.setChecked(!isPrivate, true);
radioButtonCell2.setChecked(isPrivate, true);
if (currentChat.megagroup) {
typeInfoCell.setText(isPrivate ? LocaleController.getString("MegaPrivateLinkHelp", R.string.MegaPrivateLinkHelp) : LocaleController.getString("MegaUsernameHelp", R.string.MegaUsernameHelp));
headerCell.setText(isPrivate ? LocaleController.getString("ChannelInviteLinkTitle", R.string.ChannelInviteLinkTitle) : LocaleController.getString("ChannelLinkTitle", R.string.ChannelLinkTitle));
} else {
typeInfoCell.setText(isPrivate ? LocaleController.getString("ChannelPrivateLinkHelp", R.string.ChannelPrivateLinkHelp) : LocaleController.getString("ChannelUsernameHelp", R.string.ChannelUsernameHelp));
headerCell.setText(isPrivate ? LocaleController.getString("ChannelInviteLinkTitle", R.string.ChannelInviteLinkTitle) : LocaleController.getString("ChannelLinkTitle", R.string.ChannelLinkTitle));
}
publicContainer.setVisibility(isPrivate ? View.GONE : View.VISIBLE);
privateContainer.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
linkContainer.setPadding(0, 0, 0, isPrivate ? 0 : AndroidUtilities.dp(7));
privateContainer.setText(invite != null ? invite.link : LocaleController.getString("Loading", R.string.Loading), false);
nameTextView.clearFocus();
checkTextView.setVisibility(!isPrivate && checkTextView.length() != 0 ? View.VISIBLE : View.GONE);
AndroidUtilities.hideKeyboard(nameTextView);
}
private boolean checkUserName(final String name, boolean alert) {
if (name != null && name.length() > 0) {
checkTextView.setVisibility(View.VISIBLE);
} else {
checkTextView.setVisibility(View.GONE);
}
if (alert && name.length() == 0) {
return true;
}
if (checkRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(checkRunnable);
checkRunnable = null;
lastCheckName = null;
if (checkReqId != 0) {
ConnectionsManager.getInstance().cancelRequest(checkReqId, true);
}
}
lastNameAvailable = false;
if (name != null) {
if (name.startsWith("_") || name.endsWith("_")) {
checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
checkTextView.setTextColor(0xffcf3030);
return false;
}
for (int a = 0; a < name.length(); a++) {
char ch = name.charAt(a);
if (a == 0 && ch >= '0' && ch <= '9') {
if (currentChat.megagroup) {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega));
checkTextView.setTextColor(0xffcf3030);
}
} else {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber));
checkTextView.setTextColor(0xffcf3030);
}
}
return false;
}
if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
checkTextView.setTextColor(0xffcf3030);
}
return false;
}
}
}
if (name == null || name.length() < 5) {
if (currentChat.megagroup) {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega));
checkTextView.setTextColor(0xffcf3030);
}
} else {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort));
checkTextView.setTextColor(0xffcf3030);
}
}
return false;
}
if (name.length() > 32) {
if (alert) {
showErrorAlert(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong));
} else {
checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong));
checkTextView.setTextColor(0xffcf3030);
}
return false;
}
if (!alert) {
checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking));
checkTextView.setTextColor(0xff6d6d72);
lastCheckName = name;
checkRunnable = new Runnable() {
@Override
public void run() {
TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername();
req.username = name;
req.channel = MessagesController.getInputChannel(chatId);
checkReqId = 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() {
checkReqId = 0;
if (lastCheckName != null && lastCheckName.equals(name)) {
if (error == null && response instanceof TLRPC.TL_boolTrue) {
checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name));
checkTextView.setTextColor(0xff26972c);
lastNameAvailable = true;
} else {
if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
checkTextView.setText(LocaleController.getString("ChangePublicLimitReached", R.string.ChangePublicLimitReached));
} else {
checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse));
}
checkTextView.setTextColor(0xffcf3030);
lastNameAvailable = false;
}
}
}
});
}
}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
};
AndroidUtilities.runOnUIThread(checkRunnable, 300);
}
return true;
}
private void generateLink() {
if (loadingInvite || invite != null) {
return;
}
loadingInvite = true;
TLRPC.TL_channels_exportInvite req = new TLRPC.TL_channels_exportInvite();
req.channel = MessagesController.getInputChannel(chatId);
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) {
invite = (TLRPC.ExportedChatInvite) response;
}
loadingInvite = false;
privateContainer.setText(invite != null ? invite.link : LocaleController.getString("Loading", R.string.Loading), false);
}
});
}
});
}
private void showErrorAlert(String error) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
switch (error) {
case "USERNAME_INVALID":
builder.setMessage(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
break;
case "USERNAME_OCCUPIED":
builder.setMessage(LocaleController.getString("LinkInUse", R.string.LinkInUse));
break;
case "USERNAMES_UNAVAILABLE":
builder.setMessage(LocaleController.getString("FeatureUnavailable", R.string.FeatureUnavailable));
break;
default:
builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
break;
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
}
@@ -1,150 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* 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.
*/
package org.telegram.ui;
import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.Theme;
public class ChannelIntroActivity extends BaseFragment {
private ImageView imageView;
private TextView createChannelText;
private TextView whatIsChannelText;
private TextView descriptionText;
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_COLOR);
actionBar.setBackButtonImage(R.drawable.pl_back);
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_SELECTOR_COLOR);
actionBar.setCastShadows(false);
if (!AndroidUtilities.isTablet()) {
actionBar.showActionModeTop();
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new ViewGroup(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (width > height) {
imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.EXACTLY));
whatIsChannelText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.5f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
createChannelText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
} else {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.EXACTLY));
whatIsChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
createChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
}
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
if (r > b) {
int y = (int) (height * 0.05f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
int x = (int) (width * 0.4f);
y = (int) (height * 0.14f);
whatIsChannelText.layout(x, y, x + whatIsChannelText.getMeasuredWidth(), y + whatIsChannelText.getMeasuredHeight());
y = (int) (height * 0.61f);
createChannelText.layout(x, y, x + createChannelText.getMeasuredWidth(), y + createChannelText.getMeasuredHeight());
x = (int) (width * 0.45f);
y = (int) (height * 0.31f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
} else {
int y = (int) (height * 0.05f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.59f);
whatIsChannelText.layout(0, y, whatIsChannelText.getMeasuredWidth(), y + whatIsChannelText.getMeasuredHeight());
y = (int) (height * 0.68f);
int x = (int) (width * 0.05f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
y = (int) (height * 0.86f);
createChannelText.layout(0, y, createChannelText.getMeasuredWidth(), y + createChannelText.getMeasuredHeight());
}
}
};
fragmentView.setBackgroundColor(0xffffffff);
ViewGroup viewGroup = (ViewGroup) fragmentView;
viewGroup.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
imageView = new ImageView(context);
imageView.setImageResource(R.drawable.channelintro);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
viewGroup.addView(imageView);
whatIsChannelText = new TextView(context);
whatIsChannelText.setTextColor(0xff212121);
whatIsChannelText.setGravity(Gravity.CENTER_HORIZONTAL);
whatIsChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
whatIsChannelText.setText(LocaleController.getString("ChannelAlertTitle", R.string.ChannelAlertTitle));
viewGroup.addView(whatIsChannelText);
descriptionText = new TextView(context);
descriptionText.setTextColor(0xff787878);
descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
descriptionText.setText(LocaleController.getString("ChannelAlertText", R.string.ChannelAlertText));
viewGroup.addView(descriptionText);
createChannelText = new TextView(context);
createChannelText.setTextColor(0xff4c8eca);
createChannelText.setGravity(Gravity.CENTER);
createChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
createChannelText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
createChannelText.setText(LocaleController.getString("ChannelAlertCreate", R.string.ChannelAlertCreate));
viewGroup.addView(createChannelText);
createChannelText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putInt("step", 0);
presentFragment(new ChannelCreateActivity(args), true);
}
});
return fragmentView;
}
}
@@ -1,717 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* 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.
*/
package org.telegram.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.RadioCell;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.EmptyTextProgressView;
import org.telegram.ui.Components.LayoutHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class ChannelUsersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListAdapter listViewAdapter;
private EmptyTextProgressView emptyView;
private ArrayList<TLRPC.ChannelParticipant> participants = new ArrayList<>();
private int chatId;
private int type;
private boolean loadingUsers;
private boolean firstLoaded;
private boolean isAdmin;
private boolean isPublic;
private boolean isMegagroup;
private int participantsStartRow;
public ChannelUsersActivity(Bundle args) {
super(args);
chatId = arguments.getInt("chat_id");
type = arguments.getInt("type");
TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
if (chat != null) {
if (chat.creator) {
isAdmin = true;
isPublic = (chat.flags & TLRPC.CHAT_FLAG_IS_PUBLIC) != 0;
}
isMegagroup = chat.megagroup;
}
if (type == 0) {
participantsStartRow = 0;
} else if (type == 1) {
participantsStartRow = isAdmin && isMegagroup ? 4 : 0;
} else if (type == 2) {
participantsStartRow = isAdmin ? (isPublic ? 2 : 3) : 0;
}
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
getChannelParticipants(0, 200);
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
}
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (type == 0) {
actionBar.setTitle(LocaleController.getString("ChannelBlockedUsers", R.string.ChannelBlockedUsers));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
} else if (type == 2) {
actionBar.setTitle(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(0xfff0f0f0);
FrameLayout frameLayout = (FrameLayout) fragmentView;
emptyView = new EmptyTextProgressView(context);
if (type == 0) {
if (isMegagroup) {
emptyView.setText(LocaleController.getString("NoBlockedGroup", R.string.NoBlockedGroup));
} else {
emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
}
}
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
final ListView listView = new ListView(context);
listView.setEmptyView(emptyView);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setDrawSelectorOnTop(true);
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (type == 2) {
if (isAdmin) {
if (i == 0) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
args.putBoolean("needForwardCount", false);
args.putBoolean("allowUsernameSearch", false);
args.putString("selectAlertString", LocaleController.getString("ChannelAddTo", R.string.ChannelAddTo));
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(TLRPC.User user, String param) {
MessagesController.getInstance().addUserToChat(chatId, user, null, param != null ? Utilities.parseInt(param) : 0, null, ChannelUsersActivity.this);
}
});
presentFragment(fragment);
} else if (!isPublic && i == 1) {
presentFragment(new GroupInviteActivity(chatId));
}
}
} else if (type == 1) {
if (isAdmin) {
if (isMegagroup && (i == 1 || i == 2)) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
if (chat == null) {
return;
}
boolean changed = false;
if (i == 1 && !chat.democracy) {
chat.democracy = true;
changed = true;
} else if (i == 2 && chat.democracy) {
chat.democracy = false;
changed = true;
}
if (changed) {
MessagesController.getInstance().toogleChannelInvites(chatId, chat.democracy);
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof RadioCell) {
int num = (Integer) child.getTag();
((RadioCell) child).setChecked(num == 0 && chat.democracy || num == 1 && !chat.democracy, true);
}
}
}
return;
}
if (i == participantsStartRow + participants.size()) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
args.putBoolean("needForwardCount", false);
args.putBoolean("allowUsernameSearch", true);
/*if (isMegagroup) {
args.putBoolean("allowBots", false);
}*/
args.putString("selectAlertString", LocaleController.getString("ChannelAddUserAdminAlert", R.string.ChannelAddUserAdminAlert));
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(TLRPC.User user, String param) {
setUserChannelRole(user, new TLRPC.TL_channelRoleEditor());
}
});
presentFragment(fragment);
return;
}
}
}
TLRPC.ChannelParticipant participant = null;
if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
participant = participants.get(i - participantsStartRow);
}
if (participant != null) {
Bundle args = new Bundle();
args.putInt("user_id", participant.user_id);
presentFragment(new ProfileActivity(args));
}
}
});
if (isAdmin || isMegagroup && type == 0) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (getParentActivity() == null) {
return false;
}
TLRPC.ChannelParticipant participant = null;
if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
participant = participants.get(i - participantsStartRow);
}
if (participant != null) {
final TLRPC.ChannelParticipant finalParticipant = participant;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = null;
if (type == 0) {
items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
} else if (type == 1) {
items = new CharSequence[]{LocaleController.getString("ChannelRemoveUserAdmin", R.string.ChannelRemoveUserAdmin)};
} else if (type == 2) {
items = new CharSequence[]{LocaleController.getString("ChannelRemoveUser", R.string.ChannelRemoveUser)};
}
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
if (type == 0) {
participants.remove(finalParticipant);
listViewAdapter.notifyDataSetChanged();
TLRPC.TL_channels_kickFromChannel req = new TLRPC.TL_channels_kickFromChannel();
req.kicked = false;
req.user_id = MessagesController.getInputUser(finalParticipant.user_id);
req.channel = MessagesController.getInputChannel(chatId);
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (response != null) {
final TLRPC.Updates updates = (TLRPC.Updates) response;
MessagesController.getInstance().processUpdates(updates, false);
if (!updates.chats.isEmpty()) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
TLRPC.Chat chat = updates.chats.get(0);
MessagesController.getInstance().loadFullChat(chat.id, 0, true);
}
}, 1000);
}
}
}
});
} else if (type == 1) {
setUserChannelRole(MessagesController.getInstance().getUser(finalParticipant.user_id), new TLRPC.TL_channelRoleEmpty());
} else if (type == 2) {
MessagesController.getInstance().deleteUserFromChat(chatId, MessagesController.getInstance().getUser(finalParticipant.user_id), null);
}
}
}
});
showDialog(builder.create());
return true;
} else {
return false;
}
}
});
}
if (loadingUsers) {
emptyView.showProgress();
} else {
emptyView.showTextView();
}
return fragmentView;
}
public void setUserChannelRole(TLRPC.User user, TLRPC.ChannelParticipantRole role) {
if (user == null || role == null) {
return;
}
TLRPC.TL_channels_editAdmin req = new TLRPC.TL_channels_editAdmin();
req.channel = MessagesController.getInputChannel(chatId);
req.user_id = MessagesController.getInputUser(user);
req.role = role;
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(chatId, 0, true);
}
}, 1000);
} else {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
AlertsCreator.showAddUserAlert(error.text, ChannelUsersActivity.this, !isMegagroup);
}
});
}
}
});
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.chatInfoDidLoaded) {
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (chatFull.id == chatId) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
getChannelParticipants(0, 200);
}
});
}
}
}
private int getChannelAdminParticipantType(TLRPC.ChannelParticipant participant) {
if (participant instanceof TLRPC.TL_channelParticipantCreator || participant instanceof TLRPC.TL_channelParticipantSelf) {
return 0;
} else if (participant instanceof TLRPC.TL_channelParticipantEditor) {
return 1;
} else {
return 2;
}
}
private void getChannelParticipants(int offset, int count) {
if (loadingUsers) {
return;
}
loadingUsers = true;
if (emptyView != null && !firstLoaded) {
emptyView.showProgress();
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
req.channel = MessagesController.getInputChannel(chatId);
if (type == 0) {
req.filter = new TLRPC.TL_channelParticipantsKicked();
} else if (type == 1) {
req.filter = new TLRPC.TL_channelParticipantsAdmins();
} else if (type == 2) {
req.filter = new TLRPC.TL_channelParticipantsRecent();
}
req.offset = offset;
req.limit = count;
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);
participants = res.participants;
try {
if (type == 0 || type == 2) {
Collections.sort(participants, new Comparator<TLRPC.ChannelParticipant>() {
@Override
public int compare(TLRPC.ChannelParticipant lhs, TLRPC.ChannelParticipant rhs) {
TLRPC.User user1 = MessagesController.getInstance().getUser(rhs.user_id);
TLRPC.User user2 = MessagesController.getInstance().getUser(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;
}
}
if (user2 != null && user2.status != null) {
if (user2.id == UserConfig.getClientUserId()) {
status2 = ConnectionsManager.getInstance().getCurrentTime() + 50000;
} else {
status2 = user2.status.expires;
}
}
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) {
return -1;
} else if (status2 < 0 && status1 > 0 || status2 == 0 && status1 != 0) {
return 1;
}
return 0;
}
});
} else if (type == 1) {
Collections.sort(res.participants, new Comparator<TLRPC.ChannelParticipant>() {
@Override
public int compare(TLRPC.ChannelParticipant lhs, TLRPC.ChannelParticipant rhs) {
int type1 = getChannelAdminParticipantType(lhs);
int type2 = getChannelAdminParticipantType(rhs);
if (type1 > type2) {
return 1;
} else if (type1 < type2) {
return -1;
}
return 0;
}
});
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
loadingUsers = false;
firstLoaded = true;
if (emptyView != null) {
emptyView.showTextView();
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
}
});
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
@Override
public void onResume() {
super.onResume();
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
}
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int i) {
if (type == 2) {
if (isAdmin) {
if (!isPublic) {
if (i == 0 || i == 1) {
return true;
} else if (i == 2) {
return false;
}
} else {
if (i == 0) {
return true;
} else if (i == 1) {
return false;
}
}
}
} else if (type == 1) {
if (i == participantsStartRow + participants.size()) {
return isAdmin;
} else if (i == participantsStartRow + participants.size() + 1) {
return false;
} else if (isMegagroup && isAdmin && i < 4) {
return i == 1 || i == 2;
}
}
return i != participants.size() + participantsStartRow && participants.get(i - participantsStartRow).user_id != UserConfig.getClientUserId();
}
@Override
public int getCount() {
if (participants.isEmpty() && type == 0 || loadingUsers && !firstLoaded) {
return 0;
} else if (type == 1) {
return participants.size() + (isAdmin ? 2 : 1) + (isAdmin && isMegagroup ? 4 : 0);
}
return participants.size() + participantsStartRow + 1;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int viewType = getItemViewType(i);
if (viewType == 0) {
if (view == null) {
view = new UserCell(mContext, 1, 0, false);
view.setBackgroundColor(0xffffffff);
}
UserCell userCell = (UserCell) view;
TLRPC.ChannelParticipant participant = participants.get(i - participantsStartRow);
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
if (user != null) {
if (type == 0) {
userCell.setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0);
} else if (type == 1) {
String role = null;
if (participant instanceof TLRPC.TL_channelParticipantCreator || participant instanceof TLRPC.TL_channelParticipantSelf) {
role = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else if (participant instanceof TLRPC.TL_channelParticipantModerator) {
role = LocaleController.getString("ChannelModerator", R.string.ChannelModerator);
} else if (participant instanceof TLRPC.TL_channelParticipantEditor) {
role = LocaleController.getString("ChannelEditor", R.string.ChannelEditor);
}
userCell.setData(user, null, role, 0);
} else if (type == 2) {
userCell.setData(user, null, null, 0);
}
}
} else if (viewType == 1) {
if (view == null) {
view = new TextInfoPrivacyCell(mContext);
}
if (type == 0) {
((TextInfoPrivacyCell) view).setText(String.format("%1$s\n\n%2$s", LocaleController.getString("NoBlockedGroup", R.string.NoBlockedGroup), LocaleController.getString("UnblockText", R.string.UnblockText)));
view.setBackgroundResource(R.drawable.greydivider_bottom);
} else if (type == 1) {
if (isAdmin) {
if (isMegagroup) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("MegaAdminsInfo", R.string.MegaAdminsInfo));
view.setBackgroundResource(R.drawable.greydivider_bottom);
} else {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("ChannelAdminsInfo", R.string.ChannelAdminsInfo));
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else {
((TextInfoPrivacyCell) view).setText("");
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (type == 2) {
if ((!isPublic && i == 2 || i == 1) && isAdmin) {
if (isMegagroup) {
((TextInfoPrivacyCell) view).setText("");
} else {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("ChannelMembersInfo", R.string.ChannelMembersInfo));
}
view.setBackgroundResource(R.drawable.greydivider);
} else {
((TextInfoPrivacyCell) view).setText("");
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
}
} else if (viewType == 2) {
if (view == null) {
view = new TextSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextSettingsCell actionCell = (TextSettingsCell) view;
if (type == 2) {
if (i == 0) {
actionCell.setText(LocaleController.getString("AddMember", R.string.AddMember), true);
} else if (i == 1) {
actionCell.setText(LocaleController.getString("ChannelInviteViaLink", R.string.ChannelInviteViaLink), false);
}
} else if (type == 1) {
actionCell.setTextAndIcon(LocaleController.getString("ChannelAddAdmin", R.string.ChannelAddAdmin), R.drawable.managers, false);
}
} else if (viewType == 3) {
if (view == null) {
view = new ShadowSectionCell(mContext);
}
} else if (viewType == 4) {
if (view == null) {
view = new TextCell(mContext);
view.setBackgroundColor(0xffffffff);
}
((TextCell) view).setTextAndIcon(LocaleController.getString("ChannelAddAdmin", R.string.ChannelAddAdmin), R.drawable.managers);
} else if (viewType == 5) {
if (view == null) {
view = new HeaderCell(mContext);
view.setBackgroundColor(0xffffffff);
}
((HeaderCell) view).setText(LocaleController.getString("WhoCanAddMembers", R.string.WhoCanAddMembers));
} else if (viewType == 6) {
if (view == null) {
view = new RadioCell(mContext);
view.setBackgroundColor(0xffffffff);
}
RadioCell radioCell = (RadioCell) view;
TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
if (i == 1) {
radioCell.setTag(0);
radioCell.setText(LocaleController.getString("WhoCanAddMembersAllMembers", R.string.WhoCanAddMembersAllMembers), chat != null && chat.democracy, true);
} else if (i == 2) {
radioCell.setTag(1);
radioCell.setText(LocaleController.getString("WhoCanAddMembersAdmins", R.string.WhoCanAddMembersAdmins), chat != null && !chat.democracy, false);
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (type == 1) {
if (isAdmin) {
if (isMegagroup) {
if (i == 0) {
return 5;
} else if (i == 1 || i == 2) {
return 6;
} else if (i == 3) {
return 3;
}
}
if (i == participantsStartRow + participants.size()) {
return 4;
} else if (i == participantsStartRow + participants.size() + 1) {
return 1;
}
}
} else if (type == 2) {
if (isAdmin) {
if (!isPublic) {
if (i == 0 || i == 1) {
return 2;
} else if (i == 2) {
return 1;
}
} else {
if (i == 0) {
return 2;
} else if (i == 1) {
return 1;
}
}
}
}
if (i == participants.size() + participantsStartRow) {
return 1;
}
return 0;
}
@Override
public int getViewTypeCount() {
return 7;
}
@Override
public boolean isEmpty() {
return getCount() == 0 || participants.isEmpty() && loadingUsers;
}
}
}
File diff suppressed because it is too large Load Diff