use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createClearDaysDialogAlert.
public static void createClearDaysDialogAlert(BaseFragment fragment, int days, TLRPC.User user, MessagesStorage.BooleanCallback onProcessRunnable, Theme.ResourcesProvider resourcesProvider) {
if (fragment == null || fragment.getParentActivity() == null || user == null) {
return;
}
int account = fragment.getCurrentAccount();
Context context = fragment.getParentActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context, resourcesProvider);
long selfUserId = UserConfig.getInstance(account).getClientUserId();
CheckBoxCell[] cell = new CheckBoxCell[1];
TextView messageTextView = new TextView(context);
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
FrameLayout frameLayout = new FrameLayout(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (cell[0] != null) {
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + cell[0].getMeasuredHeight());
}
}
};
builder.setView(frameLayout);
TextView textView = new TextView(context);
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setText(LocaleController.formatPluralString("DeleteDays", days));
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 11, 24, 0));
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 48, 24, 18));
messageTextView.setText(LocaleController.getString("DeleteHistoryByDaysMessage", R.string.DeleteHistoryByDaysMessage));
final boolean[] deleteForAll = new boolean[] { false };
if (user.id != selfUserId) {
cell[0] = new CheckBoxCell(context, 1, resourcesProvider);
cell[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
cell[0].setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", false, false);
cell[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
cell[0].setChecked(false, false);
cell[0].setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell1.setChecked(deleteForAll[0], true);
});
}
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
onProcessRunnable.run(deleteForAll[0]);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
fragment.showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createImportDialogAlert.
public static void createImportDialogAlert(BaseFragment fragment, String title, String message, TLRPC.User user, TLRPC.Chat chat, Runnable onProcessRunnable) {
if (fragment == null || fragment.getParentActivity() == null || chat == null && user == null) {
return;
}
int account = fragment.getCurrentAccount();
Context context = fragment.getParentActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
long selfUserId = UserConfig.getInstance(account).getClientUserId();
TextView messageTextView = new TextView(context);
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
FrameLayout frameLayout = new FrameLayout(context);
builder.setView(frameLayout);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
BackupImageView imageView = new BackupImageView(context);
imageView.setRoundRadius(AndroidUtilities.dp(20));
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
TextView textView = new TextView(context);
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setText(LocaleController.getString("ImportMessages", R.string.ImportMessages));
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
if (user != null) {
if (UserObject.isReplyUser(user)) {
avatarDrawable.setSmallSize(true);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
imageView.setImage(null, null, avatarDrawable, user);
} else if (user.id == selfUserId) {
avatarDrawable.setSmallSize(true);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
imageView.setImage(null, null, avatarDrawable, user);
} else {
avatarDrawable.setSmallSize(false);
avatarDrawable.setInfo(user);
imageView.setForUserOrChat(user, avatarDrawable);
}
} else {
avatarDrawable.setInfo(chat);
imageView.setForUserOrChat(chat, avatarDrawable);
}
messageTextView.setText(AndroidUtilities.replaceTags(message));
/*if (chat != null) {
if (TextUtils.isEmpty(title)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ImportToChatNoTitle", R.string.ImportToChatNoTitle, chat.title)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ImportToChat", R.string.ImportToChat, title, chat.title)));
}
} else {
if (TextUtils.isEmpty(title)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ImportToUserNoTitle", R.string.ImportToUserNoTitle, ContactsController.formatName(user.first_name, user.last_name))));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ImportToUser", R.string.ImportToUser, title, ContactsController.formatName(user.first_name, user.last_name))));
}
}*/
builder.setPositiveButton(LocaleController.getString("Import", R.string.Import), (dialogInterface, i) -> {
if (onProcessRunnable != null) {
onProcessRunnable.run();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
fragment.showDialog(alertDialog);
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createSupportAlert.
public static AlertDialog createSupportAlert(BaseFragment fragment) {
if (fragment == null || fragment.getParentActivity() == null) {
return null;
}
final TextView message = new TextView(fragment.getParentActivity());
Spannable spanned = new SpannableString(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo).replace("\n", "<br>")));
URLSpan[] spans = spanned.getSpans(0, spanned.length(), URLSpan.class);
for (int i = 0; i < spans.length; i++) {
URLSpan span = spans[i];
int start = spanned.getSpanStart(span);
int end = spanned.getSpanEnd(span);
spanned.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL()) {
@Override
public void onClick(View widget) {
fragment.dismissCurrentDialog();
super.onClick(widget);
}
};
spanned.setSpan(span, start, end, 0);
}
message.setText(spanned);
message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
AlertDialog.Builder builder1 = new AlertDialog.Builder(fragment.getParentActivity());
builder1.setView(message);
builder1.setTitle(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
builder1.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), (dialogInterface, i) -> performAskAQuestion(fragment));
builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
return builder1.create();
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createBlockDialogAlert.
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
return;
}
Context context = fragment.getParentActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
CheckBoxCell[] cell = new CheckBoxCell[2];
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
String actionText;
if (count == 1) {
String name = ContactsController.formatName(user.first_name, user.last_name);
builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
} else {
builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
}
final boolean[] checks = new boolean[] { true, true };
for (int a = 0; a < cell.length; a++) {
if (a == 0 && !reportSpam) {
continue;
}
int num = a;
cell[a] = new CheckBoxCell(context, 1);
cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (a == 0) {
cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
} else {
cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
}
cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
cell[a].setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
checks[num] = !checks[num];
cell1.setChecked(checks[num], true);
});
}
builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
fragment.showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createChangeBioAlert.
public static void createChangeBioAlert(String currentBio, long peerId, Context context, int currentAccount) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(peerId > 0 ? LocaleController.getString("UserBio", R.string.UserBio) : LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
builder.setMessage(peerId > 0 ? LocaleController.getString("VoipGroupBioEditAlertText", R.string.VoipGroupBioEditAlertText) : LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo));
FrameLayout dialogView = new FrameLayout(context);
dialogView.setClipChildren(false);
if (peerId < 0) {
TLRPC.ChatFull chatFull = MessagesController.getInstance(currentAccount).getChatFull(-peerId);
if (chatFull == null) {
MessagesController.getInstance(currentAccount).loadFullChat(-peerId, ConnectionsManager.generateClassGuid(), true);
}
}
NumberTextView checkTextView = new NumberTextView(context);
EditText editTextView = new EditText(context);
editTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
editTextView.setHint(peerId > 0 ? LocaleController.getString("UserBio", R.string.UserBio) : LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
editTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
editTextView.setBackground(Theme.createEditTextDrawable(context, true));
editTextView.setMaxLines(4);
editTextView.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
InputFilter[] inputFilters = new InputFilter[1];
int maxSymbolsCount = peerId > 0 ? 70 : 255;
inputFilters[0] = new CodepointsLengthInputFilter(maxSymbolsCount) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
CharSequence result = super.filter(source, start, end, dest, dstart, dend);
if (result != null && source != null && result.length() != source.length()) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
}
return result;
}
};
editTextView.setFilters(inputFilters);
checkTextView.setCenterAlign(true);
checkTextView.setTextSize(15);
checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
checkTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
dialogView.addView(checkTextView, LayoutHelper.createFrame(20, 20, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT, 0, 14, 21, 0));
editTextView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(24) : 0, AndroidUtilities.dp(8), LocaleController.isRTL ? 0 : AndroidUtilities.dp(24), AndroidUtilities.dp(8));
editTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable s) {
int count = maxSymbolsCount - Character.codePointCount(s, 0, s.length());
if (count < 30) {
checkTextView.setNumber(count, checkTextView.getVisibility() == View.VISIBLE);
AndroidUtilities.updateViewVisibilityAnimated(checkTextView, true);
} else {
AndroidUtilities.updateViewVisibilityAnimated(checkTextView, false);
}
}
});
AndroidUtilities.updateViewVisibilityAnimated(checkTextView, false, 0, false);
editTextView.setText(currentBio);
editTextView.setSelection(editTextView.getText().toString().length());
builder.setView(dialogView);
DialogInterface.OnClickListener onDoneListener = (dialogInterface, i) -> {
if (peerId > 0) {
final TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(UserConfig.getInstance(currentAccount).getClientUserId());
final String newName = editTextView.getText().toString().replace("\n", " ").replaceAll(" +", " ").trim();
if (userFull != null) {
String currentName = userFull.about;
if (currentName == null) {
currentName = "";
}
if (currentName.equals(newName)) {
AndroidUtilities.hideKeyboard(editTextView);
dialogInterface.dismiss();
return;
}
userFull.about = newName;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.userInfoDidLoad, peerId, userFull);
}
final TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile();
req.about = newName;
req.flags |= 4;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, Bulletin.TYPE_BIO_CHANGED, peerId);
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
}, ConnectionsManager.RequestFlagFailOnServerErrors);
} else {
TLRPC.ChatFull chatFull = MessagesController.getInstance(currentAccount).getChatFull(-peerId);
final String newAbout = editTextView.getText().toString();
if (chatFull != null) {
String currentName = chatFull.about;
if (currentName == null) {
currentName = "";
}
if (currentName.equals(newAbout)) {
AndroidUtilities.hideKeyboard(editTextView);
dialogInterface.dismiss();
return;
}
chatFull.about = newAbout;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, chatFull, 0, false, false);
}
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, Bulletin.TYPE_BIO_CHANGED, peerId);
MessagesController.getInstance(currentAccount).updateChatAbout(-peerId, newAbout, chatFull);
}
dialogInterface.dismiss();
};
builder.setPositiveButton(LocaleController.getString("Save", R.string.Save), onDoneListener);
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setOnPreDismissListener(dialogInterface -> AndroidUtilities.hideKeyboard(editTextView));
dialogView.addView(editTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 23, 12, 23, 21));
editTextView.requestFocus();
AndroidUtilities.showKeyboard(editTextView);
AlertDialog dialog = builder.create();
editTextView.setOnEditorActionListener((textView, i, keyEvent) -> {
if ((i == EditorInfo.IME_ACTION_DONE || (peerId > 0 && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && dialog.isShowing()) {
onDoneListener.onClick(dialog, 0);
return true;
}
return false;
});
dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
dialog.show();
dialog.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
}
Aggregations