use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class WallpapersListActivity method createView.
@Override
public View createView(Context context) {
colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
colorFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
colorFramePaint.setStrokeWidth(AndroidUtilities.dp(1));
colorFramePaint.setStyle(Paint.Style.STROKE);
colorFramePaint.setColor(0x33000000);
updater = new WallpaperUpdater(getParentActivity(), this, new WallpaperUpdater.WallpaperUpdaterDelegate() {
@Override
public void didSelectWallpaper(File file, Bitmap bitmap, boolean gallery) {
presentFragment(new ThemePreviewActivity(new FileWallpaper("", file, file), bitmap), gallery);
}
@Override
public void needOpenColorPicker() {
}
});
hasOwnBackground = true;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (currentType == TYPE_ALL) {
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
} else if (currentType == TYPE_COLOR) {
actionBar.setTitle(LocaleController.getString("SelectColorTitle", R.string.SelectColorTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (actionBar.isActionModeShowed()) {
selectedWallPapers.clear();
actionBar.hideActionMode();
updateRowsSelection();
} else {
finishFragment();
}
} else if (id == delete) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.formatPluralString("DeleteBackground", selectedWallPapers.size()));
builder.setMessage(LocaleController.formatString("DeleteChatBackgroundsAlert", R.string.DeleteChatBackgroundsAlert));
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
ArrayList<Integer> ids = new ArrayList<>();
int[] deleteCount = new int[] { 0 };
for (int b = 0; b < selectedWallPapers.size(); b++) {
Object object = selectedWallPapers.valueAt(b);
if (object instanceof ColorWallpaper) {
ColorWallpaper colorWallpaper = (ColorWallpaper) object;
if (colorWallpaper.parentWallpaper != null && colorWallpaper.parentWallpaper.id < 0) {
getMessagesStorage().deleteWallpaper(colorWallpaper.parentWallpaper.id);
localWallPapers.remove(colorWallpaper);
localDict.remove(colorWallpaper.getHash());
} else {
object = colorWallpaper.parentWallpaper;
}
}
if (!(object instanceof TLRPC.WallPaper)) {
continue;
}
deleteCount[0]++;
TLRPC.WallPaper wallPaper = (TLRPC.WallPaper) object;
TLRPC.TL_account_saveWallPaper req = new TLRPC.TL_account_saveWallPaper();
req.settings = new TLRPC.TL_wallPaperSettings();
req.unsave = true;
if (object instanceof TLRPC.TL_wallPaperNoFile) {
TLRPC.TL_inputWallPaperNoFile inputWallPaper = new TLRPC.TL_inputWallPaperNoFile();
inputWallPaper.id = wallPaper.id;
req.wallpaper = inputWallPaper;
} else {
TLRPC.TL_inputWallPaper inputWallPaper = new TLRPC.TL_inputWallPaper();
inputWallPaper.id = wallPaper.id;
inputWallPaper.access_hash = wallPaper.access_hash;
req.wallpaper = inputWallPaper;
}
if (wallPaper.slug != null && wallPaper.slug.equals(selectedBackgroundSlug)) {
selectedBackgroundSlug = Theme.hasWallpaperFromTheme() ? Theme.THEME_BACKGROUND_SLUG : Theme.DEFAULT_BACKGROUND_SLUG;
Theme.getActiveTheme().setOverrideWallpaper(null);
Theme.reloadWallpaper();
}
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
deleteCount[0]--;
if (deleteCount[0] == 0) {
loadWallpapers(true);
}
}));
}
if (deleteCount[0] == 0) {
loadWallpapers(true);
}
selectedWallPapers.clear();
actionBar.hideActionMode();
actionBar.closeSearchField();
});
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));
}
} else if (id == forward) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 3);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment1, dids, message, param) -> {
StringBuilder fmessage = new StringBuilder();
for (int b = 0; b < selectedWallPapers.size(); b++) {
Object object = selectedWallPapers.valueAt(b);
String link;
if (object instanceof TLRPC.TL_wallPaper) {
link = AndroidUtilities.getWallPaperUrl(object);
} else if (object instanceof ColorWallpaper) {
link = ((ColorWallpaper) object).getUrl();
} else {
continue;
}
if (!TextUtils.isEmpty(link)) {
if (fmessage.length() > 0) {
fmessage.append('\n');
}
fmessage.append(link);
}
}
selectedWallPapers.clear();
actionBar.hideActionMode();
actionBar.closeSearchField();
if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) {
updateRowsSelection();
for (int a = 0; a < dids.size(); a++) {
long did = dids.get(a);
if (message != null) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
if (!TextUtils.isEmpty(fmessage)) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
}
fragment1.finishFragment();
} else {
long did = dids.get(0);
Bundle args1 = new Bundle();
args1.putBoolean("scrollToTopOnResume", true);
if (DialogObject.isEncryptedDialog(did)) {
args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else {
if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else if (DialogObject.isChatDialog(did)) {
args1.putLong("chat_id", -did);
}
if (!MessagesController.getInstance(currentAccount).checkCanOpenChat(args1, fragment1)) {
return;
}
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args1);
presentFragment(chatActivity, true);
SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
});
presentFragment(fragment);
}
}
});
if (currentType == TYPE_ALL) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
listView.setAdapter(searchAdapter);
listView.invalidate();
}
@Override
public void onSearchCollapse() {
listView.setAdapter(listAdapter);
listView.invalidate();
searchAdapter.processSearch(null, true);
searchItem.setSearchFieldCaption(null);
onCaptionCleared();
}
@Override
public void onTextChanged(EditText editText) {
searchAdapter.processSearch(editText.getText().toString(), false);
}
@Override
public void onCaptionCleared() {
searchAdapter.clearColor();
searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
}
});
searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
final ActionBarMenu actionMode = actionBar.createActionMode(false, null);
actionMode.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
actionBar.setItemsColor(Theme.getColor(Theme.key_actionBarDefaultIcon), true);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSelector), true);
selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultIcon));
selectedMessagesCountTextView.setOnTouchListener((v, event) -> true);
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
actionModeViews.add(actionMode.addItemWithWidth(forward, R.drawable.msg_forward, AndroidUtilities.dp(54), LocaleController.getString("Forward", R.string.Forward)));
actionModeViews.add(actionMode.addItemWithWidth(delete, R.drawable.msg_delete, AndroidUtilities.dp(54), LocaleController.getString("Delete", R.string.Delete)));
selectedWallPapers.clear();
}
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context) {
private Paint paint = new Paint();
@Override
public boolean hasOverlappingRendering() {
return false;
}
@Override
public void onDraw(Canvas c) {
ViewHolder holder;
if (getAdapter() == listAdapter && resetInfoRow != -1) {
holder = findViewHolderForAdapterPosition(resetInfoRow);
} else {
holder = null;
}
int bottom;
int height = getMeasuredHeight();
if (holder != null) {
bottom = holder.itemView.getBottom();
if (holder.itemView.getBottom() >= height) {
bottom = height;
}
} else {
bottom = height;
}
paint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
c.drawRect(0, 0, getMeasuredWidth(), bottom, paint);
if (bottom != height) {
paint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
c.drawRect(0, bottom, getMeasuredWidth(), height, paint);
}
}
};
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
});
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
listView.setAdapter(listAdapter = new ListAdapter(context));
searchAdapter = new SearchAdapter(context);
listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null || listView.getAdapter() == searchAdapter) {
return;
}
if (position == uploadImageRow) {
updater.openGallery();
} else if (position == setColorRow) {
WallpapersListActivity activity = new WallpapersListActivity(TYPE_COLOR);
activity.patterns = patterns;
presentFragment(activity);
} else if (position == resetRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ResetChatBackgroundsAlertTitle", R.string.ResetChatBackgroundsAlertTitle));
builder.setMessage(LocaleController.getString("ResetChatBackgroundsAlert", R.string.ResetChatBackgroundsAlert));
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
if (actionBar.isActionModeShowed()) {
selectedWallPapers.clear();
actionBar.hideActionMode();
updateRowsSelection();
}
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
TLRPC.TL_account_resetWallPapers req = new TLRPC.TL_account_resetWallPapers();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> loadWallpapers(false)));
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
scrolling = newState != RecyclerView.SCROLL_STATE_IDLE;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (listView.getAdapter() == searchAdapter) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = layoutManager.getItemCount();
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2) {
searchAdapter.loadMoreResults();
}
}
}
}
});
searchEmptyView = new EmptyTextProgressView(context);
searchEmptyView.setVisibility(View.GONE);
searchEmptyView.setShowAtCenter(true);
searchEmptyView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
listView.setEmptyView(searchEmptyView);
frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
updateRows();
return fragmentView;
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeSetUrlActivity method saveTheme.
private void saveTheme() {
if (!checkUrl(linkField.getText().toString(), true)) {
return;
}
if (getParentActivity() == null) {
return;
}
if (nameField.length() == 0) {
AlertsCreator.showSimpleAlert(this, LocaleController.getString("Theme", R.string.Theme), LocaleController.getString("ThemeNameInvalid", R.string.ThemeNameInvalid));
return;
}
if (creatingNewTheme) {
String oldName = info.title;
String oldSlug = info.slug;
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setOnCancelListener(dialog -> {
});
progressDialog.show();
themeInfo.name = info.title = nameField.getText().toString();
themeInfo.info.slug = linkField.getText().toString();
Theme.saveCurrentTheme(themeInfo, true, true, true);
return;
}
String currentUrl = info.slug == null ? "" : info.slug;
String currentName = info.title == null ? "" : info.title;
String newUrl = linkField.getText().toString();
String newName = nameField.getText().toString();
if (currentUrl.equals(newUrl) && currentName.equals(newName)) {
finishFragment();
return;
}
progressDialog = new AlertDialog(getParentActivity(), 3);
final TLRPC.TL_account_updateTheme req = new TLRPC.TL_account_updateTheme();
TLRPC.TL_inputTheme inputTheme = new TLRPC.TL_inputTheme();
inputTheme.id = info.id;
inputTheme.access_hash = info.access_hash;
req.theme = inputTheme;
req.format = "android";
req.slug = newUrl;
req.flags |= 1;
req.title = newName;
req.flags |= 2;
final int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
if (response instanceof TLRPC.TL_theme) {
TLRPC.TL_theme theme = (TLRPC.TL_theme) response;
AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
progressDialog = null;
} catch (Exception e) {
FileLog.e(e);
}
Theme.setThemeUploadInfo(themeInfo, themeAccent, theme, currentAccount, false);
finishFragment();
});
} else {
AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
progressDialog = null;
} catch (Exception e) {
FileLog.e(e);
}
AlertsCreator.processError(currentAccount, error, ThemeSetUrlActivity.this, req);
});
}
}, ConnectionsManager.RequestFlagFailOnServerErrors);
ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
progressDialog.setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true));
progressDialog.show();
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPFragment method showErrorDialog.
private void showErrorDialog(CharSequence message) {
if (activity.isFinishing()) {
return;
}
AlertDialog dlg = new DarkAlertDialog.Builder(activity).setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed)).setMessage(message).setPositiveButton(LocaleController.getString("OK", R.string.OK), null).show();
dlg.setCanceledOnTouchOutside(true);
dlg.setOnDismissListener(dialog -> windowView.finish());
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPFragment method updateViewState.
private void updateViewState() {
if (isFinished || switchingToPip) {
return;
}
lockOnScreen = false;
boolean animated = previousState != -1;
boolean showAcceptDeclineView = false;
boolean showTimer = false;
boolean showReconnecting = false;
boolean showCallingAvatarMini = false;
int statusLayoutOffset = 0;
VoIPService service = VoIPService.getSharedInstance();
switch(currentState) {
case VoIPService.STATE_WAITING_INCOMING:
showAcceptDeclineView = true;
lockOnScreen = true;
statusLayoutOffset = AndroidUtilities.dp(24);
acceptDeclineView.setRetryMod(false);
if (service != null && service.privateCall.video) {
if (currentUserIsVideo && callingUser.photo != null) {
showCallingAvatarMini = true;
} else {
showCallingAvatarMini = false;
}
statusTextView.setText(LocaleController.getString("VoipInVideoCallBranding", R.string.VoipInVideoCallBranding), true, animated);
acceptDeclineView.setTranslationY(-AndroidUtilities.dp(60));
} else {
statusTextView.setText(LocaleController.getString("VoipInCallBranding", R.string.VoipInCallBranding), true, animated);
acceptDeclineView.setTranslationY(0);
}
break;
case VoIPService.STATE_WAIT_INIT:
case VoIPService.STATE_WAIT_INIT_ACK:
statusTextView.setText(LocaleController.getString("VoipConnecting", R.string.VoipConnecting), true, animated);
break;
case VoIPService.STATE_EXCHANGING_KEYS:
statusTextView.setText(LocaleController.getString("VoipExchangingKeys", R.string.VoipExchangingKeys), true, animated);
break;
case VoIPService.STATE_WAITING:
statusTextView.setText(LocaleController.getString("VoipWaiting", R.string.VoipWaiting), true, animated);
break;
case VoIPService.STATE_RINGING:
statusTextView.setText(LocaleController.getString("VoipRinging", R.string.VoipRinging), true, animated);
break;
case VoIPService.STATE_REQUESTING:
statusTextView.setText(LocaleController.getString("VoipRequesting", R.string.VoipRequesting), true, animated);
break;
case VoIPService.STATE_HANGING_UP:
break;
case VoIPService.STATE_BUSY:
showAcceptDeclineView = true;
statusTextView.setText(LocaleController.getString("VoipBusy", R.string.VoipBusy), false, animated);
acceptDeclineView.setRetryMod(true);
currentUserIsVideo = false;
callingUserIsVideo = false;
break;
case VoIPService.STATE_ESTABLISHED:
case VoIPService.STATE_RECONNECTING:
updateKeyView(animated);
showTimer = true;
if (currentState == VoIPService.STATE_RECONNECTING) {
showReconnecting = true;
}
break;
case VoIPService.STATE_ENDED:
currentUserTextureView.saveCameraLastBitmap();
AndroidUtilities.runOnUIThread(() -> windowView.finish(), 200);
break;
case VoIPService.STATE_FAILED:
statusTextView.setText(LocaleController.getString("VoipFailed", R.string.VoipFailed), false, animated);
final VoIPService voipService = VoIPService.getSharedInstance();
final String lastError = voipService != null ? voipService.getLastError() : Instance.ERROR_UNKNOWN;
if (!TextUtils.equals(lastError, Instance.ERROR_UNKNOWN)) {
if (TextUtils.equals(lastError, Instance.ERROR_INCOMPATIBLE)) {
final String name = ContactsController.formatName(callingUser.first_name, callingUser.last_name);
final String message = LocaleController.formatString("VoipPeerIncompatible", R.string.VoipPeerIncompatible, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
} else if (TextUtils.equals(lastError, Instance.ERROR_PEER_OUTDATED)) {
if (isVideoCall) {
final String name = UserObject.getFirstName(callingUser);
final String message = LocaleController.formatString("VoipPeerVideoOutdated", R.string.VoipPeerVideoOutdated, name);
boolean[] callAgain = new boolean[1];
AlertDialog dlg = new DarkAlertDialog.Builder(activity).setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed)).setMessage(AndroidUtilities.replaceTags(message)).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialogInterface, i) -> windowView.finish()).setPositiveButton(LocaleController.getString("VoipPeerVideoOutdatedMakeVoice", R.string.VoipPeerVideoOutdatedMakeVoice), (dialogInterface, i) -> {
callAgain[0] = true;
currentState = VoIPService.STATE_BUSY;
Intent intent = new Intent(activity, VoIPService.class);
intent.putExtra("user_id", callingUser.id);
intent.putExtra("is_outgoing", true);
intent.putExtra("start_incall_activity", false);
intent.putExtra("video_call", false);
intent.putExtra("can_video_call", false);
intent.putExtra("account", currentAccount);
try {
activity.startService(intent);
} catch (Throwable e) {
FileLog.e(e);
}
}).show();
dlg.setCanceledOnTouchOutside(true);
dlg.setOnDismissListener(dialog -> {
if (!callAgain[0]) {
windowView.finish();
}
});
} else {
final String name = UserObject.getFirstName(callingUser);
final String message = LocaleController.formatString("VoipPeerOutdated", R.string.VoipPeerOutdated, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
}
} else if (TextUtils.equals(lastError, Instance.ERROR_PRIVACY)) {
final String name = ContactsController.formatName(callingUser.first_name, callingUser.last_name);
final String message = LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
} else if (TextUtils.equals(lastError, Instance.ERROR_AUDIO_IO)) {
showErrorDialog("Error initializing audio hardware");
} else if (TextUtils.equals(lastError, Instance.ERROR_LOCALIZED)) {
windowView.finish();
} else if (TextUtils.equals(lastError, Instance.ERROR_CONNECTION_SERVICE)) {
showErrorDialog(LocaleController.getString("VoipErrorUnknown", R.string.VoipErrorUnknown));
} else {
AndroidUtilities.runOnUIThread(() -> windowView.finish(), 1000);
}
} else {
AndroidUtilities.runOnUIThread(() -> windowView.finish(), 1000);
}
break;
}
if (previewDialog != null) {
return;
}
if (service != null) {
callingUserIsVideo = service.getRemoteVideoState() == Instance.VIDEO_STATE_ACTIVE;
currentUserIsVideo = service.getVideoState(false) == Instance.VIDEO_STATE_ACTIVE || service.getVideoState(false) == Instance.VIDEO_STATE_PAUSED;
if (currentUserIsVideo && !isVideoCall) {
isVideoCall = true;
}
}
if (animated) {
currentUserCameraFloatingLayout.saveRelativePosition();
callingUserMiniFloatingLayout.saveRelativePosition();
}
if (callingUserIsVideo) {
if (!switchingToPip) {
callingUserPhotoView.setAlpha(1f);
}
if (animated) {
callingUserTextureView.animate().alpha(1f).setDuration(250).start();
} else {
callingUserTextureView.animate().cancel();
callingUserTextureView.setAlpha(1f);
}
if (!callingUserTextureView.renderer.isFirstFrameRendered() && !enterFromPiP) {
callingUserIsVideo = false;
}
}
if (currentUserIsVideo || callingUserIsVideo) {
fillNavigationBar(true, animated);
} else {
fillNavigationBar(false, animated);
callingUserPhotoView.setVisibility(View.VISIBLE);
if (animated) {
callingUserTextureView.animate().alpha(0f).setDuration(250).start();
} else {
callingUserTextureView.animate().cancel();
callingUserTextureView.setAlpha(0f);
}
}
if (!currentUserIsVideo || !callingUserIsVideo) {
cameraForceExpanded = false;
}
boolean showCallingUserVideoMini = currentUserIsVideo && cameraForceExpanded;
showCallingUserAvatarMini(showCallingAvatarMini, animated);
statusLayoutOffset += callingUserPhotoViewMini.getTag() == null ? 0 : AndroidUtilities.dp(135) + AndroidUtilities.dp(12);
showAcceptDeclineView(showAcceptDeclineView, animated);
windowView.setLockOnScreen(lockOnScreen || deviceIsLocked);
canHideUI = (currentState == VoIPService.STATE_ESTABLISHED) && (currentUserIsVideo || callingUserIsVideo);
if (!canHideUI && !uiVisible) {
showUi(true);
}
if (uiVisible && canHideUI && !hideUiRunnableWaiting && service != null && !service.isMicMute()) {
AndroidUtilities.runOnUIThread(hideUIRunnable, 3000);
hideUiRunnableWaiting = true;
} else if (service != null && service.isMicMute()) {
AndroidUtilities.cancelRunOnUIThread(hideUIRunnable);
hideUiRunnableWaiting = false;
}
if (!uiVisible) {
statusLayoutOffset -= AndroidUtilities.dp(50);
}
if (animated) {
if (lockOnScreen || !uiVisible) {
if (backIcon.getVisibility() != View.VISIBLE) {
backIcon.setVisibility(View.VISIBLE);
backIcon.setAlpha(0f);
}
backIcon.animate().alpha(0f).start();
} else {
backIcon.animate().alpha(1f).start();
}
notificationsLayout.animate().translationY(-AndroidUtilities.dp(16) - (uiVisible ? AndroidUtilities.dp(80) : 0)).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
} else {
if (!lockOnScreen) {
backIcon.setVisibility(View.VISIBLE);
}
backIcon.setAlpha(lockOnScreen ? 0 : 1f);
notificationsLayout.setTranslationY(-AndroidUtilities.dp(16) - (uiVisible ? AndroidUtilities.dp(80) : 0));
}
if (currentState != VoIPService.STATE_HANGING_UP && currentState != VoIPService.STATE_ENDED) {
updateButtons(animated);
}
if (showTimer) {
statusTextView.showTimer(animated);
}
statusTextView.showReconnect(showReconnecting, animated);
if (animated) {
if (statusLayoutOffset != statusLayoutAnimateToOffset) {
statusLayout.animate().translationY(statusLayoutOffset).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
}
} else {
statusLayout.setTranslationY(statusLayoutOffset);
}
statusLayoutAnimateToOffset = statusLayoutOffset;
overlayBackground.setShowBlackout(currentUserIsVideo || callingUserIsVideo, animated);
canSwitchToPip = (currentState != VoIPService.STATE_ENDED && currentState != VoIPService.STATE_BUSY) && (currentUserIsVideo || callingUserIsVideo);
int floatingViewsOffset;
if (service != null) {
if (currentUserIsVideo) {
service.sharedUIParams.tapToVideoTooltipWasShowed = true;
}
currentUserTextureView.setIsScreencast(service.isScreencast());
currentUserTextureView.renderer.setMirror(service.isFrontFaceCamera());
service.setSinks(currentUserIsVideo && !service.isScreencast() ? currentUserTextureView.renderer : null, showCallingUserVideoMini ? callingUserMiniTextureRenderer : callingUserTextureView.renderer);
if (animated) {
notificationsLayout.beforeLayoutChanges();
}
if ((currentUserIsVideo || callingUserIsVideo) && (currentState == VoIPService.STATE_ESTABLISHED || currentState == VoIPService.STATE_RECONNECTING) && service.getCallDuration() > 500) {
if (service.getRemoteAudioState() == Instance.AUDIO_STATE_MUTED) {
notificationsLayout.addNotification(R.drawable.calls_mute_mini, LocaleController.formatString("VoipUserMicrophoneIsOff", R.string.VoipUserMicrophoneIsOff, UserObject.getFirstName(callingUser)), "muted", animated);
} else {
notificationsLayout.removeNotification("muted");
}
if (service.getRemoteVideoState() == Instance.VIDEO_STATE_INACTIVE) {
notificationsLayout.addNotification(R.drawable.calls_camera_mini, LocaleController.formatString("VoipUserCameraIsOff", R.string.VoipUserCameraIsOff, UserObject.getFirstName(callingUser)), "video", animated);
} else {
notificationsLayout.removeNotification("video");
}
} else {
if (service.getRemoteAudioState() == Instance.AUDIO_STATE_MUTED) {
notificationsLayout.addNotification(R.drawable.calls_mute_mini, LocaleController.formatString("VoipUserMicrophoneIsOff", R.string.VoipUserMicrophoneIsOff, UserObject.getFirstName(callingUser)), "muted", animated);
} else {
notificationsLayout.removeNotification("muted");
}
notificationsLayout.removeNotification("video");
}
if (notificationsLayout.getChildCount() == 0 && callingUserIsVideo && service.privateCall != null && !service.privateCall.video && !service.sharedUIParams.tapToVideoTooltipWasShowed) {
service.sharedUIParams.tapToVideoTooltipWasShowed = true;
tapToVideoTooltip.showForView(bottomButtons[1], true);
} else if (notificationsLayout.getChildCount() != 0) {
tapToVideoTooltip.hide();
}
if (animated) {
notificationsLayout.animateLayoutChanges();
}
}
floatingViewsOffset = notificationsLayout.getChildsHight();
callingUserMiniFloatingLayout.setBottomOffset(floatingViewsOffset, animated);
currentUserCameraFloatingLayout.setBottomOffset(floatingViewsOffset, animated);
currentUserCameraFloatingLayout.setUiVisible(uiVisible);
callingUserMiniFloatingLayout.setUiVisible(uiVisible);
if (currentUserIsVideo) {
if (!callingUserIsVideo || cameraForceExpanded) {
showFloatingLayout(STATE_FULLSCREEN, animated);
} else {
showFloatingLayout(STATE_FLOATING, animated);
}
} else {
showFloatingLayout(STATE_GONE, animated);
}
if (showCallingUserVideoMini && callingUserMiniFloatingLayout.getTag() == null) {
callingUserMiniFloatingLayout.setIsActive(true);
if (callingUserMiniFloatingLayout.getVisibility() != View.VISIBLE) {
callingUserMiniFloatingLayout.setVisibility(View.VISIBLE);
callingUserMiniFloatingLayout.setAlpha(0f);
callingUserMiniFloatingLayout.setScaleX(0.5f);
callingUserMiniFloatingLayout.setScaleY(0.5f);
}
callingUserMiniFloatingLayout.animate().setListener(null).cancel();
callingUserMiniFloatingLayout.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).setStartDelay(150).start();
callingUserMiniFloatingLayout.setTag(1);
} else if (!showCallingUserVideoMini && callingUserMiniFloatingLayout.getTag() != null) {
callingUserMiniFloatingLayout.setIsActive(false);
callingUserMiniFloatingLayout.animate().alpha(0).scaleX(0.5f).scaleY(0.5f).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (callingUserMiniFloatingLayout.getTag() == null) {
callingUserMiniFloatingLayout.setVisibility(View.GONE);
}
}
}).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
callingUserMiniFloatingLayout.setTag(null);
}
currentUserCameraFloatingLayout.restoreRelativePosition();
callingUserMiniFloatingLayout.restoreRelativePosition();
updateSpeakerPhoneIcon();
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class TwoStepVerificationActivity method onPasswordForgot.
private void onPasswordForgot() {
if (currentPassword.pending_reset_date == 0 && currentPassword.has_recovery) {
needShowProgress(true);
TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
needHideProgress();
if (error == null) {
final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
currentPassword.email_unconfirmed_pattern = res.email_pattern;
TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TwoStepVerificationSetupActivity.TYPE_EMAIL_RECOVERY, currentPassword) {
@Override
protected void onReset() {
resetPasswordOnShow = true;
}
};
fragment.addFragmentToClose(this);
fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, false);
presentFragment(fragment);
} else {
if (error.text.startsWith("FLOOD_WAIT")) {
int time = Utilities.parseInt(error.text);
String timeString;
if (time < 60) {
timeString = LocaleController.formatPluralString("Seconds", time);
} else {
timeString = LocaleController.formatPluralString("Minutes", time / 60);
}
showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
} else {
showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
}
}
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
} else {
if (getParentActivity() == null) {
return;
}
if (currentPassword.pending_reset_date != 0) {
if (getConnectionsManager().getCurrentTime() > currentPassword.pending_reset_date) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialog, which) -> resetPassword());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setTitle(LocaleController.getString("ResetPassword", R.string.ResetPassword));
builder.setMessage(LocaleController.getString("RestorePasswordResetPasswordText", R.string.RestorePasswordResetPasswordText));
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
} else {
cancelPasswordReset();
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialog, which) -> resetPassword());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setTitle(LocaleController.getString("ResetPassword", R.string.ResetPassword));
builder.setMessage(LocaleController.getString("RestorePasswordNoEmailText2", R.string.RestorePasswordNoEmailText2));
showDialog(builder.create());
}
}
}
Aggregations