use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method showRequestUrlAlert.
public void showRequestUrlAlert(final TLRPC.TL_urlAuthResultRequest request, TLRPC.TL_messages_requestUrlAuth buttonReq, String url, boolean ask) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
int index = format.indexOf("%");
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, url));
if (index >= 0) {
stringBuilder.setSpan(new URLSpan(url), index, index + url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
builder.setMessage(stringBuilder);
builder.setMessageTextViewClickable(false);
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
CheckBoxCell[] cells = new CheckBoxCell[2];
LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
TLRPC.User selfUser = getUserConfig().getCurrentUser();
for (int a = 0; a < (request.request_write_access ? 2 : 1); a++) {
cells[a] = new CheckBoxCell(getParentActivity(), 5, themeDelegate);
cells[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
cells[a].setMultiline(true);
cells[a].setTag(a);
if (a == 0) {
stringBuilder = AndroidUtilities.replaceTags(LocaleController.formatString("OpenUrlOption1", R.string.OpenUrlOption1, request.domain, ContactsController.formatName(selfUser.first_name, selfUser.last_name)));
index = TextUtils.indexOf(stringBuilder, request.domain);
if (index >= 0) {
stringBuilder.setSpan(new URLSpan(""), index, index + request.domain.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
cells[a].setText(stringBuilder, "", true, false);
} else {
cells[a].setText(AndroidUtilities.replaceTags(LocaleController.formatString("OpenUrlOption2", R.string.OpenUrlOption2, UserObject.getFirstName(request.bot))), "", true, false);
}
cells[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
linearLayout.addView(cells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
cells[a].setOnClickListener(v -> {
if (!v.isEnabled()) {
return;
}
Integer num = (Integer) v.getTag();
cells[num].setChecked(!cells[num].isChecked(), true);
if (num == 0 && cells[1] != null) {
if (cells[num].isChecked()) {
cells[1].setEnabled(true);
} else {
cells[1].setChecked(false, true);
cells[1].setEnabled(false);
}
}
});
}
builder.setCustomViewOffset(12);
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> {
if (!cells[0].isChecked()) {
Browser.openUrl(getParentActivity(), url, false);
} else {
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
TLRPC.TL_messages_acceptUrlAuth req = new TLRPC.TL_messages_acceptUrlAuth();
if (buttonReq.url != null) {
req.url = buttonReq.url;
req.flags |= 4;
} else {
req.button_id = buttonReq.button_id;
req.msg_id = buttonReq.msg_id;
req.peer = buttonReq.peer;
req.flags |= 2;
}
if (request.request_write_access) {
req.write_allowed = cells[1].isChecked();
}
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_urlAuthResultAccepted) {
TLRPC.TL_urlAuthResultAccepted res = (TLRPC.TL_urlAuthResultAccepted) response;
Browser.openUrl(getParentActivity(), res.url, false);
} else if (response instanceof TLRPC.TL_urlAuthResultDefault) {
Browser.openUrl(getParentActivity(), url, false);
} else if (buttonReq.url != null) {
AlertsCreator.showOpenUrlAlert(ChatActivity.this, buttonReq.url, false, ask, themeDelegate);
}
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
}
});
showDialog(builder.create());
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelCreateActivity method createView.
@Override
public View createView(Context context) {
if (nameTextView != null) {
nameTextView.onDestroy();
}
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 (currentStep == 0) {
if (donePressed || getParentActivity() == null) {
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 (imageUpdater.isUploadingImage()) {
createAfterUpload = true;
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setOnCancelListener(dialog -> {
createAfterUpload = false;
progressDialog = null;
donePressed = false;
});
progressDialog.show();
return;
}
final int reqId = MessagesController.getInstance(currentAccount).createChat(nameTextView.getText().toString(), new ArrayList<>(), descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL, false, null, null, ChannelCreateActivity.this);
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setOnCancelListener(dialog -> {
ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
donePressed = false;
});
progressDialog.show();
} else if (currentStep == 1) {
if (!isPrivate) {
if (descriptionTextView.length() == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ChannelPublicEmptyUsernameTitle", R.string.ChannelPublicEmptyUsernameTitle));
builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername", R.string.ChannelPublicEmptyUsername));
builder.setPositiveButton(LocaleController.getString("Close", R.string.Close), null);
showDialog(builder.create());
return;
} else {
if (!lastNameAvailable) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
return;
} else {
MessagesController.getInstance(currentAccount).updateChannelUserName(chatId, lastCheckName);
}
}
}
Bundle args = new Bundle();
args.putInt("step", 2);
args.putLong("chatId", chatId);
args.putInt("chatType", ChatObject.CHAT_TYPE_CHANNEL);
presentFragment(new GroupCreateActivity(args), true);
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
if (currentStep == 0) {
actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel));
SizeNotifierFrameLayout sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
private boolean ignoreLayout;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
heightSize -= getPaddingTop();
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int keyboardSize = measureKeyboardHeight();
if (keyboardSize > AndroidUtilities.dp(20)) {
ignoreLayout = true;
nameTextView.hideEmojiView();
ignoreLayout = false;
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
if (nameTextView != null && nameTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
int keyboardSize = measureKeyboardHeight();
int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? nameTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (nameTextView != null && nameTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
sizeNotifierFrameLayout.setOnTouchListener((v, event) -> true);
fragmentView = sizeNotifierFrameLayout;
fragmentView.setTag(Theme.key_windowBackgroundWhite);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
sizeNotifierFrameLayout.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
avatarImage = new BackupImageView(context) {
@Override
public void invalidate() {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate();
}
@Override
public void invalidate(int l, int t, int r, int b) {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate(l, t, r, b);
}
};
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null);
avatarImage.setImageDrawable(avatarDrawable);
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));
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(0x55000000);
avatarOverlay = new View(context) {
@Override
protected void onDraw(Canvas canvas) {
if (avatarImage != null && avatarImage.getImageReceiver().hasNotThumb()) {
paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha()));
canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, getMeasuredWidth() / 2.0f, paint);
}
}
};
frameLayout.addView(avatarOverlay, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
avatarOverlay.setOnClickListener(view -> {
imageUpdater.openMenu(avatar != null, () -> {
avatar = null;
avatarBig = null;
inputPhoto = null;
inputVideo = null;
inputVideoPath = null;
videoTimestamp = 0;
showAvatarProgress(false, true);
avatarImage.setImage(null, null, avatarDrawable, null);
avatarEditor.setAnimation(cameraDrawable);
cameraDrawable.setCurrentFrame(0);
}, dialog -> {
if (!imageUpdater.isUploadingImage()) {
cameraDrawable.setCustomEndFrame(86);
avatarEditor.playAnimation();
} else {
cameraDrawable.setCurrentFrame(0, false);
}
});
cameraDrawable.setCurrentFrame(0);
cameraDrawable.setCustomEndFrame(43);
avatarEditor.playAnimation();
});
cameraDrawable = new RLottieDrawable(R.raw.camera, "" + R.raw.camera, AndroidUtilities.dp(60), AndroidUtilities.dp(60), false, null);
avatarEditor = new RLottieImageView(context) {
@Override
public void invalidate(int l, int t, int r, int b) {
super.invalidate(l, t, r, b);
avatarOverlay.invalidate();
}
@Override
public void invalidate() {
super.invalidate();
avatarOverlay.invalidate();
}
};
avatarEditor.setScaleType(ImageView.ScaleType.CENTER);
avatarEditor.setAnimation(cameraDrawable);
avatarEditor.setEnabled(false);
avatarEditor.setClickable(false);
avatarEditor.setPadding(AndroidUtilities.dp(2), 0, 0, AndroidUtilities.dp(1));
frameLayout.addView(avatarEditor, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
avatarProgressView = new RadialProgressView(context);
avatarProgressView.setSize(AndroidUtilities.dp(30));
avatarProgressView.setProgressColor(0xffffffff);
avatarProgressView.setNoProgress(false);
frameLayout.addView(avatarProgressView, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
showAvatarProgress(false, false);
nameTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, this, EditTextEmoji.STYLE_FRAGMENT);
nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
if (nameToSet != null) {
nameTextView.setText(nameToSet);
nameToSet = null;
}
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(100);
nameTextView.setFilters(inputFilters);
nameTextView.getEditText().setSingleLine(true);
nameTextView.getEditText().setImeOptions(EditorInfo.IME_ACTION_NEXT);
nameTextView.getEditText().setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT && !TextUtils.isEmpty(nameTextView.getEditText().getText())) {
descriptionTextView.requestFocus();
return true;
}
return false;
});
frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 5 : 96, 0, LocaleController.isRTL ? 96 : 5, 0));
descriptionTextView = new EditTextBoldCursor(context);
descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
descriptionTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
descriptionTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
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(120);
descriptionTextView.setFilters(inputFilters);
descriptionTextView.setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
descriptionTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setCursorSize(AndroidUtilities.dp(20));
descriptionTextView.setCursorWidth(1.5f);
linearLayout.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
descriptionTextView.setOnEditorActionListener((textView, i, 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) {
}
});
helpTextView = new TextView(context);
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo));
linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20));
} else if (currentStep == 1) {
fragmentView = new ScrollView(context);
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
actionBar.setTitle(LocaleController.getString("ChannelSettingsTitle", R.string.ChannelSettingsTitle));
fragmentView.setTag(Theme.key_windowBackgroundGray);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
headerCell2 = new HeaderCell(context, 23);
headerCell2.setHeight(46);
headerCell2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
headerCell2.setText(LocaleController.getString("ChannelTypeHeader", R.string.ChannelTypeHeader));
linearLayout.addView(headerCell2);
linearLayout2 = new LinearLayout(context);
linearLayout2.setOrientation(LinearLayout.VERTICAL);
linearLayout2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell1 = new RadioButtonCell(context);
radioButtonCell1.setBackgroundDrawable(Theme.getSelectorDrawable(false));
radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), false, !isPrivate);
linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell1.setOnClickListener(v -> {
if (!isPrivate) {
return;
}
isPrivate = false;
updatePrivatePublic();
});
radioButtonCell2 = new RadioButtonCell(context);
radioButtonCell2.setBackgroundDrawable(Theme.getSelectorDrawable(false));
radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), false, isPrivate);
linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell2.setOnClickListener(v -> {
if (isPrivate) {
return;
}
isPrivate = true;
updatePrivatePublic();
});
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(Theme.getColor(Theme.key_windowBackgroundWhite));
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 = new EditTextBoldCursor(context);
editText.setText(MessagesController.getInstance(currentAccount).linkPrefix + "/");
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
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));
descriptionTextView = new EditTextBoldCursor(context);
descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
descriptionTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
descriptionTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setMaxLines(1);
descriptionTextView.setLines(1);
descriptionTextView.setBackgroundDrawable(null);
descriptionTextView.setPadding(0, 0, 0, 0);
descriptionTextView.setSingleLine(true);
descriptionTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
descriptionTextView.setHint(LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
descriptionTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setCursorSize(AndroidUtilities.dp(20));
descriptionTextView.setCursorWidth(1.5f);
publicContainer.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
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) {
checkUserName(descriptionTextView.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
privateContainer = new LinearLayout(context);
privateContainer.setOrientation(LinearLayout.VERTICAL);
linkContainer.addView(privateContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
permanentLinkView = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(getMessagesController().getChat(chatId)));
// permanentLinkView.showOptions(false);
permanentLinkView.hideRevokeOption(true);
permanentLinkView.setUsers(0, null);
privateContainer.addView(permanentLinkView);
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.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
loadingAdminedCell = new LoadingCell(context);
linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
adminnedChannelsLayout = new LinearLayout(context);
adminnedChannelsLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
adminnedChannelsLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(adminnedChannelsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
adminedInfoCell = new TextInfoPrivacyCell(context);
adminedInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
updatePrivatePublic();
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsActivity method didSelectResult.
private void didSelectResult(final long dialogId, boolean useAlert, final boolean param) {
if (addToGroupAlertString == null && checkCanWrite) {
if (DialogObject.isChatDialog(dialogId)) {
TLRPC.Chat chat = getMessagesController().getChat(-dialogId);
if (ChatObject.isChannel(chat) && !chat.megagroup && ((cantSendToChannels || !ChatObject.isCanWriteToChannel(-dialogId, currentAccount)) || hasPoll == 2)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle));
if (hasPoll == 2) {
builder.setMessage(LocaleController.getString("PublicPollCantForward", R.string.PublicPollCantForward));
} else {
builder.setMessage(LocaleController.getString("ChannelCantSendMessage", R.string.ChannelCantSendMessage));
}
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
return;
}
} else if (DialogObject.isEncryptedDialog(dialogId) && (hasPoll != 0 || hasInvoice)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle));
if (hasPoll != 0) {
builder.setMessage(LocaleController.getString("PollCantForwardSecretChat", R.string.PollCantForwardSecretChat));
} else {
builder.setMessage(LocaleController.getString("InvoiceCantForwardSecretChat", R.string.InvoiceCantForwardSecretChat));
}
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
return;
}
}
if (initialDialogsType == 11 || initialDialogsType == 12 || initialDialogsType == 13) {
if (checkingImportDialog) {
return;
}
TLRPC.User user;
TLRPC.Chat chat;
if (DialogObject.isUserDialog(dialogId)) {
user = getMessagesController().getUser(dialogId);
chat = null;
if (!user.mutual_contact) {
getUndoView().showWithAction(dialogId, UndoView.ACTION_IMPORT_NOT_MUTUAL, null);
return;
}
} else {
user = null;
chat = getMessagesController().getChat(-dialogId);
if (!ChatObject.hasAdminRights(chat) || !ChatObject.canChangeChatInfo(chat)) {
getUndoView().showWithAction(dialogId, UndoView.ACTION_IMPORT_GROUP_NOT_ADMIN, null);
return;
}
}
final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
TLRPC.TL_messages_checkHistoryImportPeer req = new TLRPC.TL_messages_checkHistoryImportPeer();
req.peer = getMessagesController().getInputPeer(dialogId);
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
checkingImportDialog = false;
if (response != null) {
TLRPC.TL_messages_checkedHistoryImportPeer res = (TLRPC.TL_messages_checkedHistoryImportPeer) response;
AlertsCreator.createImportDialogAlert(this, arguments.getString("importTitle"), res.confirm_text, user, chat, () -> {
setDialogsListFrozen(true);
ArrayList<Long> dids = new ArrayList<>();
dids.add(dialogId);
delegate.didSelectDialogs(DialogsActivity.this, dids, null, param);
});
} else {
AlertsCreator.processError(currentAccount, error, this, req);
getNotificationCenter().postNotificationName(NotificationCenter.historyImportProgressChanged, dialogId, req, error);
}
}));
try {
progressDialog.showDelayed(300);
} catch (Exception ignore) {
}
} else if (useAlert && (selectAlertString != null && selectAlertStringGroup != null || addToGroupAlertString != null)) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
String title;
String message;
String buttonText;
if (DialogObject.isEncryptedDialog(dialogId)) {
TLRPC.EncryptedChat chat = getMessagesController().getEncryptedChat(DialogObject.getEncryptedChatId(dialogId));
TLRPC.User user = getMessagesController().getUser(chat.user_id);
if (user == null) {
return;
}
title = LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle);
message = LocaleController.formatStringSimple(selectAlertString, UserObject.getUserName(user));
buttonText = LocaleController.getString("Send", R.string.Send);
} else if (DialogObject.isUserDialog(dialogId)) {
if (dialogId == getUserConfig().getClientUserId()) {
title = LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle);
message = LocaleController.formatStringSimple(selectAlertStringGroup, LocaleController.getString("SavedMessages", R.string.SavedMessages));
buttonText = LocaleController.getString("Send", R.string.Send);
} else {
TLRPC.User user = getMessagesController().getUser(dialogId);
if (user == null || selectAlertString == null) {
return;
}
title = LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle);
message = LocaleController.formatStringSimple(selectAlertString, UserObject.getUserName(user));
buttonText = LocaleController.getString("Send", R.string.Send);
}
} else {
TLRPC.Chat chat = getMessagesController().getChat(-dialogId);
if (chat == null) {
return;
}
if (addToGroupAlertString != null) {
title = LocaleController.getString("AddToTheGroupAlertTitle", R.string.AddToTheGroupAlertTitle);
message = LocaleController.formatStringSimple(addToGroupAlertString, chat.title);
buttonText = LocaleController.getString("Add", R.string.Add);
} else {
title = LocaleController.getString("SendMessageTitle", R.string.SendMessageTitle);
message = LocaleController.formatStringSimple(selectAlertStringGroup, chat.title);
buttonText = LocaleController.getString("Send", R.string.Send);
}
}
builder.setTitle(title);
builder.setMessage(AndroidUtilities.replaceTags(message));
builder.setPositiveButton(buttonText, (dialogInterface, i) -> didSelectResult(dialogId, false, false));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
if (delegate != null) {
ArrayList<Long> dids = new ArrayList<>();
dids.add(dialogId);
delegate.didSelectDialogs(DialogsActivity.this, dids, null, param);
if (resetDelegate) {
delegate = null;
}
} else {
finishFragment();
}
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsActivity method performSelectedDialogsAction.
private void performSelectedDialogsAction(ArrayList<Long> selectedDialogs, int action, boolean alert) {
if (getParentActivity() == null) {
return;
}
MessagesController.DialogFilter filter;
boolean containsFilter = (viewPages[0].dialogsType == 7 || viewPages[0].dialogsType == 8) && (!actionBar.isActionModeShowed() || actionBar.isActionModeShowed(null));
if (containsFilter) {
filter = getMessagesController().selectedDialogFilter[viewPages[0].dialogsType == 8 ? 1 : 0];
} else {
filter = null;
}
int count = selectedDialogs.size();
int pinedActionCount = 0;
if (action == archive || action == archive2) {
ArrayList<Long> copy = new ArrayList<>(selectedDialogs);
getMessagesController().addDialogToFolder(copy, canUnarchiveCount == 0 ? 1 : 0, -1, null, 0);
if (canUnarchiveCount == 0) {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
boolean hintShowed = preferences.getBoolean("archivehint_l", false) || SharedConfig.archiveHidden;
if (!hintShowed) {
preferences.edit().putBoolean("archivehint_l", true).commit();
}
int undoAction;
if (hintShowed) {
undoAction = copy.size() > 1 ? UndoView.ACTION_ARCHIVE_FEW : UndoView.ACTION_ARCHIVE;
} else {
undoAction = copy.size() > 1 ? UndoView.ACTION_ARCHIVE_FEW_HINT : UndoView.ACTION_ARCHIVE_HINT;
}
getUndoView().showWithAction(0, undoAction, null, () -> getMessagesController().addDialogToFolder(copy, folderId == 0 ? 0 : 1, -1, null, 0));
} else {
ArrayList<TLRPC.Dialog> dialogs = getMessagesController().getDialogs(folderId);
if (viewPages != null && dialogs.isEmpty()) {
viewPages[0].listView.setEmptyView(null);
viewPages[0].progressView.setVisibility(View.INVISIBLE);
finishFragment();
}
}
hideActionMode(false);
return;
} else if ((action == pin || action == pin2) && canPinCount != 0) {
int pinnedCount = 0;
int pinnedSecretCount = 0;
int newPinnedCount = 0;
int newPinnedSecretCount = 0;
ArrayList<TLRPC.Dialog> dialogs = getMessagesController().getDialogs(folderId);
for (int a = 0, N = dialogs.size(); a < N; a++) {
TLRPC.Dialog dialog = dialogs.get(a);
if (dialog instanceof TLRPC.TL_dialogFolder) {
continue;
}
if (isDialogPinned(dialog)) {
if (DialogObject.isEncryptedDialog(dialog.id)) {
pinnedSecretCount++;
} else {
pinnedCount++;
}
} else if (!getMessagesController().isPromoDialog(dialog.id, false)) {
break;
}
}
int alreadyAdded = 0;
for (int a = 0; a < count; a++) {
long selectedDialog = selectedDialogs.get(a);
TLRPC.Dialog dialog = getMessagesController().dialogs_dict.get(selectedDialog);
if (dialog == null || isDialogPinned(dialog)) {
continue;
}
if (DialogObject.isEncryptedDialog(selectedDialog)) {
newPinnedSecretCount++;
} else {
newPinnedCount++;
}
if (filter != null && filter.alwaysShow.contains(selectedDialog)) {
alreadyAdded++;
}
}
int maxPinnedCount;
if (containsFilter) {
maxPinnedCount = 100 - filter.alwaysShow.size();
} else if (folderId != 0 || filter != null) {
maxPinnedCount = getMessagesController().maxFolderPinnedDialogsCount;
} else {
maxPinnedCount = getMessagesController().maxPinnedDialogsCount;
}
if (newPinnedSecretCount + pinnedSecretCount > maxPinnedCount || newPinnedCount + pinnedCount - alreadyAdded > maxPinnedCount) {
if (folderId != 0 || filter != null) {
AlertsCreator.showSimpleAlert(DialogsActivity.this, LocaleController.formatString("PinFolderLimitReached", R.string.PinFolderLimitReached, LocaleController.formatPluralString("Chats", maxPinnedCount)));
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.formatString("PinToTopLimitReached2", R.string.PinToTopLimitReached2, LocaleController.formatPluralString("Chats", maxPinnedCount)));
builder.setNegativeButton(LocaleController.getString("FiltersSetupPinAlert", R.string.FiltersSetupPinAlert), (dialog, which) -> presentFragment(new FiltersSetupActivity()));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
AndroidUtilities.shakeView(pinItem, 2, 0);
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
return;
}
} else if ((action == delete || action == clear) && count > 1 && alert) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (action == delete) {
builder.setTitle(LocaleController.formatString("DeleteFewChatsTitle", R.string.DeleteFewChatsTitle, LocaleController.formatPluralString("ChatsSelected", count)));
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewChats", R.string.AreYouSureDeleteFewChats));
} else {
if (canClearCacheCount != 0) {
builder.setTitle(LocaleController.formatString("ClearCacheFewChatsTitle", R.string.ClearCacheFewChatsTitle, LocaleController.formatPluralString("ChatsSelectedClearCache", count)));
builder.setMessage(LocaleController.getString("AreYouSureClearHistoryCacheFewChats", R.string.AreYouSureClearHistoryCacheFewChats));
} else {
builder.setTitle(LocaleController.formatString("ClearFewChatsTitle", R.string.ClearFewChatsTitle, LocaleController.formatPluralString("ChatsSelectedClear", count)));
builder.setMessage(LocaleController.getString("AreYouSureClearHistoryFewChats", R.string.AreYouSureClearHistoryFewChats));
}
}
builder.setPositiveButton(action == delete ? LocaleController.getString("Delete", R.string.Delete) : canClearCacheCount != 0 ? LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache) : LocaleController.getString("ClearHistory", R.string.ClearHistory), (dialog1, which) -> {
if (selectedDialogs.isEmpty()) {
return;
}
ArrayList<Long> didsCopy = new ArrayList<>(selectedDialogs);
getUndoView().showWithAction(didsCopy, action == delete ? UndoView.ACTION_DELETE_FEW : UndoView.ACTION_CLEAR_FEW, null, null, () -> {
if (action == delete) {
getMessagesController().setDialogsInTransaction(true);
performSelectedDialogsAction(didsCopy, action, false);
getMessagesController().setDialogsInTransaction(false);
getMessagesController().checkIfFolderEmpty(folderId);
if (folderId != 0 && getDialogsArray(currentAccount, viewPages[0].dialogsType, folderId, false).size() == 0) {
viewPages[0].listView.setEmptyView(null);
viewPages[0].progressView.setVisibility(View.INVISIBLE);
finishFragment();
}
} else {
performSelectedDialogsAction(didsCopy, action, false);
}
}, null);
hideActionMode(action == clear);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
return;
} else if (action == block && alert) {
TLRPC.User user;
if (count == 1) {
long did = selectedDialogs.get(0);
user = getMessagesController().getUser(did);
} else {
user = null;
}
AlertsCreator.createBlockDialogAlert(DialogsActivity.this, count, canReportSpamCount != 0, user, (report, delete) -> {
for (int a = 0, N = selectedDialogs.size(); a < N; a++) {
long did = selectedDialogs.get(a);
if (report) {
TLRPC.User u = getMessagesController().getUser(did);
getMessagesController().reportSpam(did, u, null, null, false);
}
if (delete) {
getMessagesController().deleteDialog(did, 0, true);
}
getMessagesController().blockPeer(did);
}
hideActionMode(false);
});
return;
}
int minPinnedNum = Integer.MAX_VALUE;
if (filter != null && (action == pin || action == pin2) && canPinCount != 0) {
for (int c = 0, N = filter.pinnedDialogs.size(); c < N; c++) {
minPinnedNum = Math.min(minPinnedNum, filter.pinnedDialogs.valueAt(c));
}
minPinnedNum -= canPinCount;
}
boolean scrollToTop = false;
for (int a = 0; a < count; a++) {
long selectedDialog = selectedDialogs.get(a);
TLRPC.Dialog dialog = getMessagesController().dialogs_dict.get(selectedDialog);
if (dialog == null) {
continue;
}
TLRPC.Chat chat;
TLRPC.User user = null;
TLRPC.EncryptedChat encryptedChat = null;
if (DialogObject.isEncryptedDialog(selectedDialog)) {
encryptedChat = getMessagesController().getEncryptedChat(DialogObject.getEncryptedChatId(selectedDialog));
chat = null;
if (encryptedChat != null) {
user = getMessagesController().getUser(encryptedChat.user_id);
} else {
user = new TLRPC.TL_userEmpty();
}
} else if (DialogObject.isUserDialog(selectedDialog)) {
user = getMessagesController().getUser(selectedDialog);
chat = null;
} else {
chat = getMessagesController().getChat(-selectedDialog);
}
if (chat == null && user == null) {
continue;
}
boolean isBot = user != null && user.bot && !MessagesController.isSupportUser(user);
if (action == pin || action == pin2) {
if (canPinCount != 0) {
if (isDialogPinned(dialog)) {
continue;
}
pinedActionCount++;
pinDialog(selectedDialog, true, filter, minPinnedNum, count == 1);
if (filter != null) {
minPinnedNum++;
if (encryptedChat != null) {
if (!filter.alwaysShow.contains(encryptedChat.user_id)) {
filter.alwaysShow.add(encryptedChat.user_id);
}
} else {
if (!filter.alwaysShow.contains(dialog.id)) {
filter.alwaysShow.add(dialog.id);
}
}
}
} else {
if (!isDialogPinned(dialog)) {
continue;
}
pinedActionCount++;
pinDialog(selectedDialog, false, filter, minPinnedNum, count == 1);
}
} else if (action == read) {
if (canReadCount != 0) {
debugLastUpdateAction = 2;
int selectedDialogIndex = -1;
if (filter != null && (filter.flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ) != 0 && !filter.alwaysShow(currentAccount, dialog)) {
setDialogsListFrozen(true);
if (frozenDialogsList != null) {
for (int i = 0; i < frozenDialogsList.size(); i++) {
if (frozenDialogsList.get(i).id == selectedDialog) {
selectedDialogIndex = i;
break;
}
}
if (selectedDialogIndex < 0) {
setDialogsListFrozen(false, false);
}
}
}
getMessagesController().markMentionsAsRead(selectedDialog);
getMessagesController().markDialogAsRead(selectedDialog, dialog.top_message, dialog.top_message, dialog.last_message_date, false, 0, 0, true, 0);
if (selectedDialogIndex >= 0) {
frozenDialogsList.remove(selectedDialogIndex);
viewPages[0].dialogsItemAnimator.prepareForRemove();
viewPages[0].dialogsAdapter.notifyItemRemoved(selectedDialogIndex);
dialogRemoveFinished = 2;
}
} else {
getMessagesController().markDialogAsUnread(selectedDialog, null, 0);
}
} else if (action == delete || action == clear) {
if (count == 1) {
if (action == delete && canDeletePsaSelected) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("PsaHideChatAlertTitle", R.string.PsaHideChatAlertTitle));
builder.setMessage(LocaleController.getString("PsaHideChatAlertText", R.string.PsaHideChatAlertText));
builder.setPositiveButton(LocaleController.getString("PsaHide", R.string.PsaHide), (dialog1, which) -> {
getMessagesController().hidePromoDialog();
hideActionMode(false);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
AlertsCreator.createClearOrDeleteDialogAlert(DialogsActivity.this, action == clear, chat, user, DialogObject.isEncryptedDialog(dialog.id), action == delete, (param) -> {
hideActionMode(false);
if (action == clear && ChatObject.isChannel(chat) && (!chat.megagroup || !TextUtils.isEmpty(chat.username))) {
getMessagesController().deleteDialog(selectedDialog, 2, param);
} else {
if (action == delete && folderId != 0 && getDialogsArray(currentAccount, viewPages[0].dialogsType, folderId, false).size() == 1) {
viewPages[0].progressView.setVisibility(View.INVISIBLE);
}
debugLastUpdateAction = 3;
int selectedDialogIndex = -1;
if (action == delete) {
setDialogsListFrozen(true);
if (frozenDialogsList != null) {
for (int i = 0; i < frozenDialogsList.size(); i++) {
if (frozenDialogsList.get(i).id == selectedDialog) {
selectedDialogIndex = i;
break;
}
}
}
}
getUndoView().showWithAction(selectedDialog, action == clear ? UndoView.ACTION_CLEAR : UndoView.ACTION_DELETE, () -> performDeleteOrClearDialogAction(action, selectedDialog, chat, isBot, param));
ArrayList<TLRPC.Dialog> currentDialogs = new ArrayList<>(getDialogsArray(currentAccount, viewPages[0].dialogsType, folderId, false));
int currentDialogIndex = -1;
for (int i = 0; i < currentDialogs.size(); i++) {
if (currentDialogs.get(i).id == selectedDialog) {
currentDialogIndex = i;
break;
}
}
if (action == delete) {
if (selectedDialogIndex >= 0 && currentDialogIndex < 0 && frozenDialogsList != null) {
frozenDialogsList.remove(selectedDialogIndex);
viewPages[0].dialogsItemAnimator.prepareForRemove();
viewPages[0].dialogsAdapter.notifyItemRemoved(selectedDialogIndex);
dialogRemoveFinished = 2;
} else {
setDialogsListFrozen(false);
}
}
}
});
}
return;
} else {
if (getMessagesController().isPromoDialog(selectedDialog, true)) {
getMessagesController().hidePromoDialog();
} else {
if (action == clear && canClearCacheCount != 0) {
getMessagesController().deleteDialog(selectedDialog, 2, false);
} else {
performDeleteOrClearDialogAction(action, selectedDialog, chat, isBot, false);
}
}
}
} else if (action == mute) {
if (count == 1 && canMuteCount == 1) {
showDialog(AlertsCreator.createMuteAlert(this, selectedDialog, null), dialog12 -> hideActionMode(true));
return;
} else {
if (canUnmuteCount != 0) {
if (!getMessagesController().isDialogMuted(selectedDialog)) {
continue;
}
getNotificationsController().setDialogNotificationsSettings(selectedDialog, NotificationsController.SETTING_MUTE_UNMUTE);
} else {
if (getMessagesController().isDialogMuted(selectedDialog)) {
continue;
}
getNotificationsController().setDialogNotificationsSettings(selectedDialog, NotificationsController.SETTING_MUTE_FOREVER);
}
}
}
}
if (action == mute && !(count == 1 && canMuteCount == 1)) {
BulletinFactory.createMuteBulletin(this, canUnmuteCount == 0, null).show();
}
if (action == pin || action == pin2) {
if (filter != null) {
FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.name, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, true, false, DialogsActivity.this, null);
} else {
getMessagesController().reorderPinnedDialogs(folderId, null, 0);
}
if (searchIsShowed) {
getUndoView().showWithAction(0, canPinCount != 0 ? UndoView.ACTION_PIN_DIALOGS : UndoView.ACTION_UNPIN_DIALOGS, pinedActionCount);
}
}
if (scrollToTop) {
if (initialDialogsType != 10) {
hideFloatingButton(false);
}
scrollToTop();
}
hideActionMode(action != pin2 && action != pin && action != delete);
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class JoinCallAlert method open.
public static void open(Context context, long did, AccountInstance accountInstance, BaseFragment fragment, int type, TLRPC.Peer scheduledPeer, JoinCallAlertDelegate delegate) {
if (context == null || delegate == null) {
return;
}
if (lastCachedAccount == accountInstance.getCurrentAccount() && lastCacheDid == did && cachedChats != null && SystemClock.elapsedRealtime() - lastCacheTime < 5 * 60 * 1000) {
if (cachedChats.size() == 1 && type != TYPE_CREATE) {
TLRPC.InputPeer peer = accountInstance.getMessagesController().getInputPeer(MessageObject.getPeerId(cachedChats.get(0)));
delegate.didSelectChat(peer, false, false);
} else {
showAlert(context, did, cachedChats, fragment, type, scheduledPeer, delegate);
}
} else {
final AlertDialog progressDialog = new AlertDialog(context, 3);
TLRPC.TL_phone_getGroupCallJoinAs req = new TLRPC.TL_phone_getGroupCallJoinAs();
req.peer = accountInstance.getMessagesController().getInputPeer(did);
int reqId = accountInstance.getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response != null) {
TLRPC.TL_phone_joinAsPeers res = (TLRPC.TL_phone_joinAsPeers) response;
if (res.peers.size() == 1) {
TLRPC.InputPeer peer = accountInstance.getMessagesController().getInputPeer(MessageObject.getPeerId(res.peers.get(0)));
delegate.didSelectChat(peer, false, false);
return;
}
cachedChats = res.peers;
lastCacheDid = did;
lastCacheTime = SystemClock.elapsedRealtime();
lastCachedAccount = accountInstance.getCurrentAccount();
accountInstance.getMessagesController().putChats(res.chats, false);
accountInstance.getMessagesController().putUsers(res.users, false);
showAlert(context, did, res.peers, fragment, type, scheduledPeer, delegate);
}
}));
progressDialog.setOnCancelListener(dialog -> accountInstance.getConnectionsManager().cancelRequest(reqId, true));
try {
progressDialog.showDelayed(500);
} catch (Exception ignore) {
}
}
}
Aggregations