Search in sources :

Example 86 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method scrollToLastMessage.

private void scrollToLastMessage(boolean skipSponsored) {
    if (chatListView.isFastScrollAnimationRunning()) {
        return;
    }
    forceNextPinnedMessageId = 0;
    nextScrollToMessageId = 0;
    forceScrollToFirst = false;
    chatScrollHelper.setScrollDirection(RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN);
    if (forwardEndReached[0] && first_unread_id == 0 && startLoadFromMessageId == 0) {
        if (chatLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) {
            canShowPagedownButton = false;
            updatePagedownButtonVisibility(true);
            removeSelectedMessageHighlight();
            updateVisibleRows();
        } else {
            chatAdapter.updateRowsSafe();
            chatScrollHelperCallback.scrollTo = null;
            int position = 0;
            if (skipSponsored) {
                while (position < messages.size()) {
                    if (!messages.get(position).isSponsored()) {
                        break;
                    }
                    position++;
                }
            }
            chatScrollHelper.scrollToPosition(position, 0, true, true);
        }
    } else {
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        updatePinnedListButton(false);
        progressDialog = new AlertDialog(getParentActivity(), 3, themeDelegate);
        progressDialog.setOnCancelListener(postponedScrollCancelListener);
        progressDialog.showDelayed(1000);
        postponedScrollToLastMessageQueryIndex = lastLoadIndex;
        postponedScrollMessageId = 0;
        postponedScrollIsCanceled = false;
        waitingForLoad.clear();
        waitingForLoad.add(lastLoadIndex);
        getMessagesController().loadMessages(dialog_id, mergeDialogId, false, 30, 0, 0, true, 0, classGuid, 0, 0, chatMode, threadMessageId, replyMaxReadId, lastLoadIndex++);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 87 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class PrivacyControlActivity method applyCurrentPrivacySettings.

private void applyCurrentPrivacySettings() {
    TLRPC.TL_account_setPrivacy req = new TLRPC.TL_account_setPrivacy();
    if (rulesType == PRIVACY_RULES_TYPE_PHONE) {
        req.key = new TLRPC.TL_inputPrivacyKeyPhoneNumber();
        if (currentType == TYPE_NOBODY) {
            TLRPC.TL_account_setPrivacy req2 = new TLRPC.TL_account_setPrivacy();
            req2.key = new TLRPC.TL_inputPrivacyKeyAddedByPhone();
            if (currentSubType == 0) {
                req2.rules.add(new TLRPC.TL_inputPrivacyValueAllowAll());
            } else {
                req2.rules.add(new TLRPC.TL_inputPrivacyValueAllowContacts());
            }
            ConnectionsManager.getInstance(currentAccount).sendRequest(req2, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                if (error == null) {
                    TLRPC.TL_account_privacyRules privacyRules = (TLRPC.TL_account_privacyRules) response;
                    ContactsController.getInstance(currentAccount).setPrivacyRules(privacyRules.rules, PRIVACY_RULES_TYPE_ADDED_BY_PHONE);
                }
            }), ConnectionsManager.RequestFlagFailOnServerErrors);
        }
    } else if (rulesType == PRIVACY_RULES_TYPE_FORWARDS) {
        req.key = new TLRPC.TL_inputPrivacyKeyForwards();
    } else if (rulesType == PRIVACY_RULES_TYPE_PHOTO) {
        req.key = new TLRPC.TL_inputPrivacyKeyProfilePhoto();
    } else if (rulesType == PRIVACY_RULES_TYPE_P2P) {
        req.key = new TLRPC.TL_inputPrivacyKeyPhoneP2P();
    } else if (rulesType == PRIVACY_RULES_TYPE_CALLS) {
        req.key = new TLRPC.TL_inputPrivacyKeyPhoneCall();
    } else if (rulesType == PRIVACY_RULES_TYPE_INVITE) {
        req.key = new TLRPC.TL_inputPrivacyKeyChatInvite();
    } else {
        req.key = new TLRPC.TL_inputPrivacyKeyStatusTimestamp();
    }
    if (currentType != 0 && currentPlus.size() > 0) {
        TLRPC.TL_inputPrivacyValueAllowUsers usersRule = new TLRPC.TL_inputPrivacyValueAllowUsers();
        TLRPC.TL_inputPrivacyValueAllowChatParticipants chatsRule = new TLRPC.TL_inputPrivacyValueAllowChatParticipants();
        for (int a = 0; a < currentPlus.size(); a++) {
            long id = currentPlus.get(a);
            if (DialogObject.isUserDialog(id)) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(id);
                if (user != null) {
                    TLRPC.InputUser inputUser = MessagesController.getInstance(currentAccount).getInputUser(user);
                    if (inputUser != null) {
                        usersRule.users.add(inputUser);
                    }
                }
            } else {
                chatsRule.chats.add(-id);
            }
        }
        req.rules.add(usersRule);
        req.rules.add(chatsRule);
    }
    if (currentType != 1 && currentMinus.size() > 0) {
        TLRPC.TL_inputPrivacyValueDisallowUsers usersRule = new TLRPC.TL_inputPrivacyValueDisallowUsers();
        TLRPC.TL_inputPrivacyValueDisallowChatParticipants chatsRule = new TLRPC.TL_inputPrivacyValueDisallowChatParticipants();
        for (int a = 0; a < currentMinus.size(); a++) {
            long id = currentMinus.get(a);
            if (DialogObject.isUserDialog(id)) {
                TLRPC.User user = getMessagesController().getUser(id);
                if (user != null) {
                    TLRPC.InputUser inputUser = getMessagesController().getInputUser(user);
                    if (inputUser != null) {
                        usersRule.users.add(inputUser);
                    }
                }
            } else {
                chatsRule.chats.add(-id);
            }
        }
        req.rules.add(usersRule);
        req.rules.add(chatsRule);
    }
    if (currentType == TYPE_EVERYBODY) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueAllowAll());
    } else if (currentType == TYPE_NOBODY) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueDisallowAll());
    } else if (currentType == TYPE_CONTACTS) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueAllowContacts());
    }
    AlertDialog progressDialog = null;
    if (getParentActivity() != null) {
        progressDialog = new AlertDialog(getParentActivity(), 3);
        progressDialog.setCanCacnel(false);
        progressDialog.show();
    }
    final AlertDialog progressDialogFinal = progressDialog;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        try {
            if (progressDialogFinal != null) {
                progressDialogFinal.dismiss();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        if (error == null) {
            TLRPC.TL_account_privacyRules privacyRules = (TLRPC.TL_account_privacyRules) response;
            MessagesController.getInstance(currentAccount).putUsers(privacyRules.users, false);
            MessagesController.getInstance(currentAccount).putChats(privacyRules.chats, false);
            ContactsController.getInstance(currentAccount).setPrivacyRules(privacyRules.rules, rulesType);
            finishFragment();
        } else {
            showErrorAlert();
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC)

Example 88 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class PrivacySettingsActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    });
    listView.setVerticalScrollBarEnabled(false);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (!view.isEnabled()) {
            return;
        }
        if (position == blockedRow) {
            presentFragment(new PrivacyUsersActivity());
        } else if (position == sessionsRow) {
            presentFragment(new SessionsActivity(0));
        } else if (position == webSessionsRow) {
            presentFragment(new SessionsActivity(1));
        } else if (position == deleteAccountRow) {
            if (getParentActivity() == null) {
                return;
            }
            int ttl = getContactsController().getDeleteAccountTTL();
            int selected;
            if (ttl <= 31) {
                selected = 0;
            } else if (ttl <= 93) {
                selected = 1;
            } else if (ttl <= 182) {
                selected = 2;
            } else {
                selected = 3;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
            String[] items = new String[] { LocaleController.formatPluralString("Months", 1), LocaleController.formatPluralString("Months", 3), LocaleController.formatPluralString("Months", 6), LocaleController.formatPluralString("Years", 1) };
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < items.length; a++) {
                RadioColorCell cell = new RadioColorCell(getParentActivity());
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(items[a], selected == a);
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    builder.getDismissRunnable().run();
                    Integer which = (Integer) v.getTag();
                    int value = 0;
                    if (which == 0) {
                        value = 30;
                    } else if (which == 1) {
                        value = 90;
                    } else if (which == 2) {
                        value = 182;
                    } else if (which == 3) {
                        value = 365;
                    }
                    final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
                    progressDialog.setCanCacnel(false);
                    progressDialog.show();
                    final TLRPC.TL_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
                    req.ttl = new TLRPC.TL_accountDaysTTL();
                    req.ttl.days = value;
                    getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        if (response instanceof TLRPC.TL_boolTrue) {
                            getContactsController().setDeleteAccountTTL(req.ttl.days);
                            listAdapter.notifyDataSetChanged();
                        }
                    }));
                });
            }
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == lastSeenRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_LASTSEEN));
        } else if (position == phoneNumberRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHONE));
        } else if (position == groupsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_INVITE));
        } else if (position == callsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_CALLS));
        } else if (position == profilePhotoRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHOTO));
        } else if (position == forwardsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_FORWARDS));
        } else if (position == passwordRow) {
            if (currentPassword == null) {
                return;
            }
            if (!TwoStepVerificationActivity.canHandleCurrentPassword(currentPassword, false)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
            }
            if (currentPassword.has_password) {
                TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
                fragment.setPassword(currentPassword);
                presentFragment(fragment);
            } else {
                int type;
                if (TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern)) {
                    type = TwoStepVerificationSetupActivity.TYPE_INTRO;
                } else {
                    type = TwoStepVerificationSetupActivity.TYPE_EMAIL_CONFIRM;
                }
                presentFragment(new TwoStepVerificationSetupActivity(type, currentPassword));
            }
        } else if (position == passcodeRow) {
            if (SharedConfig.passcodeHash.length() > 0) {
                presentFragment(new PasscodeActivity(2));
            } else {
                presentFragment(new PasscodeActivity(0));
            }
        } else if (position == secretWebpageRow) {
            if (getMessagesController().secretWebpagePreview == 1) {
                getMessagesController().secretWebpagePreview = 0;
            } else {
                getMessagesController().secretWebpagePreview = 1;
            }
            MessagesController.getGlobalMainSettings().edit().putInt("secretWebpage2", getMessagesController().secretWebpagePreview).commit();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(getMessagesController().secretWebpagePreview == 1);
            }
        } else if (position == contactsDeleteRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SyncContactsDeleteTitle", R.string.SyncContactsDeleteTitle));
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("SyncContactsDeleteText", R.string.SyncContactsDeleteText)));
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
                AlertDialog.Builder builder12 = new AlertDialog.Builder(getParentActivity(), 3, null);
                progressDialog = builder12.show();
                progressDialog.setCanCacnel(false);
                if (currentSync != newSync) {
                    currentSync = getUserConfig().syncContacts = newSync;
                    getUserConfig().saveConfig(false);
                }
                getContactsController().deleteAllContacts(() -> progressDialog.dismiss());
            });
            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 (position == contactsSuggestRow) {
            final TextCheckCell cell = (TextCheckCell) view;
            if (newSuggest) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("SuggestContactsTitle", R.string.SuggestContactsTitle));
                builder.setMessage(LocaleController.getString("SuggestContactsAlert", R.string.SuggestContactsAlert));
                builder.setPositiveButton(LocaleController.getString("MuteDisable", R.string.MuteDisable), (dialogInterface, i) -> {
                    TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
                    req.credentials = clear[1];
                    req.info = clear[0];
                    getUserConfig().tmpPassword = null;
                    getUserConfig().saveConfig(false);
                    getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        newSuggest = !newSuggest;
                        cell.setChecked(newSuggest);
                    }));
                });
                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 {
                cell.setChecked(newSuggest = true);
            }
        } else if (position == newChatsRow) {
            final TextCheckCell cell = (TextCheckCell) view;
            archiveChats = !archiveChats;
            cell.setChecked(archiveChats);
        } else if (position == contactsSyncRow) {
            newSync = !newSync;
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(newSync);
            }
        } else if (position == secretMapRow) {
            AlertsCreator.showSecretLocationAlert(getParentActivity(), currentAccount, () -> listAdapter.notifyDataSetChanged(), false, null);
        } else if (position == paymentsClearRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
            builder.setMessage(LocaleController.getString("PrivacyPaymentsClearAlertText", R.string.PrivacyPaymentsClearAlertText));
            LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < 2; a++) {
                String name;
                if (a == 0) {
                    name = LocaleController.getString("PrivacyClearShipping", R.string.PrivacyClearShipping);
                } else {
                    name = LocaleController.getString("PrivacyClearPayment", R.string.PrivacyClearPayment);
                }
                clear[a] = true;
                CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity(), 1, 21, null);
                checkBoxCell.setTag(a);
                checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                checkBoxCell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                checkBoxCell.setText(name, null, true, false);
                checkBoxCell.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
                checkBoxCell.setOnClickListener(v -> {
                    CheckBoxCell cell = (CheckBoxCell) v;
                    int num = (Integer) cell.getTag();
                    clear[num] = !clear[num];
                    cell.setChecked(clear[num], true);
                });
            }
            builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface, i) -> {
                try {
                    if (visibleDialog != null) {
                        visibleDialog.dismiss();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
                builder1.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
                builder1.setMessage(LocaleController.getString("PrivacyPaymentsClearAlert", R.string.PrivacyPaymentsClearAlert));
                builder1.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface2, i2) -> {
                    TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
                    req.credentials = clear[1];
                    req.info = clear[0];
                    getUserConfig().tmpPassword = null;
                    getUserConfig().saveConfig(false);
                    getConnectionsManager().sendRequest(req, (response, error) -> {
                    });
                    String text;
                    if (clear[0] && clear[1]) {
                        text = LocaleController.getString("PrivacyPaymentsPaymentShippingCleared", R.string.PrivacyPaymentsPaymentShippingCleared);
                    } else if (clear[0]) {
                        text = LocaleController.getString("PrivacyPaymentsShippingInfoCleared", R.string.PrivacyPaymentsShippingInfoCleared);
                    } else if (clear[1]) {
                        text = LocaleController.getString("PrivacyPaymentsPaymentInfoCleared", R.string.PrivacyPaymentsPaymentInfoCleared);
                    } else {
                        return;
                    }
                    BulletinFactory.of(PrivacySettingsActivity.this).createSimpleBulletin(R.raw.chats_infotip, text).show();
                });
                builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder1.create());
                AlertDialog alertDialog = builder1.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
            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 (position == passportRow) {
            presentFragment(new PassportActivity(PassportActivity.TYPE_PASSWORD, 0, "", "", null, null, null, null, null));
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) BulletinFactory(org.telegram.ui.Components.BulletinFactory) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) ActionBar(org.telegram.ui.ActionBar.ActionBar) View(android.view.View) SharedConfig(org.telegram.messenger.SharedConfig) RecyclerView(androidx.recyclerview.widget.RecyclerView) DialogInterface(android.content.DialogInterface) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) ContactsController(org.telegram.messenger.ContactsController) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) FrameLayout(android.widget.FrameLayout) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Example 89 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class CropView method showAspectRatioDialog.

public void showAspectRatioDialog() {
    if (state == null) {
        return;
    }
    if (hasAspectRatioDialog) {
        return;
    }
    hasAspectRatioDialog = true;
    String[] actions = new String[8];
    final Integer[][] ratios = new Integer[][] { new Integer[] { 3, 2 }, new Integer[] { 5, 3 }, new Integer[] { 4, 3 }, new Integer[] { 5, 4 }, new Integer[] { 7, 5 }, new Integer[] { 16, 9 } };
    actions[0] = LocaleController.getString("CropOriginal", R.string.CropOriginal);
    actions[1] = LocaleController.getString("CropSquare", R.string.CropSquare);
    int i = 2;
    for (Integer[] ratioPair : ratios) {
        if (areaView.getAspectRatio() > 1.0f) {
            actions[i] = String.format("%d:%d", ratioPair[0], ratioPair[1]);
        } else {
            actions[i] = String.format("%d:%d", ratioPair[1], ratioPair[0]);
        }
        i++;
    }
    AlertDialog dialog = new AlertDialog.Builder(getContext()).setItems(actions, (dialog12, which) -> {
        hasAspectRatioDialog = false;
        switch(which) {
            case 0:
                {
                    float w = state.getBaseRotation() % 180 != 0 ? state.getHeight() : state.getWidth();
                    float h = state.getBaseRotation() % 180 != 0 ? state.getWidth() : state.getHeight();
                    setLockedAspectRatio(w / h);
                }
                break;
            case 1:
                {
                    setLockedAspectRatio(1.0f);
                }
                break;
            default:
                {
                    Integer[] ratioPair = ratios[which - 2];
                    if (areaView.getAspectRatio() > 1.0f) {
                        setLockedAspectRatio(ratioPair[0] / (float) ratioPair[1]);
                    } else {
                        setLockedAspectRatio(ratioPair[1] / (float) ratioPair[0]);
                    }
                }
                break;
        }
    }).create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnCancelListener(dialog1 -> hasAspectRatioDialog = false);
    dialog.show();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) FileLoader(org.telegram.messenger.FileLoader) Context(android.content.Context) PointF(android.graphics.PointF) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) BitmapFactory(android.graphics.BitmapFactory) LocaleController(org.telegram.messenger.LocaleController) Swatch(org.telegram.ui.Components.Paint.Swatch) Animator(android.animation.Animator) PaintingOverlay(org.telegram.ui.Components.PaintingOverlay) TextPaintView(org.telegram.ui.Components.Paint.Views.TextPaintView) ArrayList(java.util.ArrayList) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) BubbleActivity(org.telegram.ui.BubbleActivity) MotionEvent(android.view.MotionEvent) Point(org.telegram.ui.Components.Point) MediaController(org.telegram.messenger.MediaController) Canvas(android.graphics.Canvas) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Matrix(android.graphics.Matrix) Build(android.os.Build) RectF(android.graphics.RectF) R(org.telegram.messenger.R) FileOutputStream(java.io.FileOutputStream) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FileLog(org.telegram.messenger.FileLog) File(java.io.File) Color(android.graphics.Color) Bitmap(android.graphics.Bitmap) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) ViewTreeObserver(android.view.ViewTreeObserver) Paint(android.graphics.Paint) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ValueAnimator(android.animation.ValueAnimator) Point(org.telegram.ui.Components.Point) Paint(android.graphics.Paint)

Example 90 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method jumpToDate.

public void jumpToDate(int date) {
    if (messages.isEmpty()) {
        return;
    }
    MessageObject firstMessage = messages.get(0);
    MessageObject lastMessage = messages.get(messages.size() - 1);
    if (firstMessage.messageOwner.date >= date && lastMessage.messageOwner.date <= date || lastMessage.messageOwner.date >= date && endReached[0]) {
        for (int a = messages.size() - 1; a >= 0; a--) {
            MessageObject message = messages.get(a);
            if (message.messageOwner.date >= date && message.getId() != 0) {
                scrollToMessageId(message.getId(), 0, false, message.getDialogId() == mergeDialogId ? 1 : 0, true, 0);
                break;
            }
        }
    } else if (!DialogObject.isEncryptedDialog(dialog_id)) {
        int scrollDirection = RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UNSET;
        int end = chatLayoutManager.findLastVisibleItemPosition();
        for (int i = chatLayoutManager.findFirstVisibleItemPosition(); i <= end; i++) {
            if (i >= chatAdapter.messagesStartRow && i <= chatAdapter.messagesEndRow) {
                TLRPC.Message message = messages.get(i - chatAdapter.messagesStartRow).messageOwner;
                if (message != null) {
                    boolean scrollDown = message.date < date;
                    if (isSecretChat()) {
                        scrollDown = !scrollDown;
                    }
                    scrollDirection = scrollDown ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
                    break;
                }
            }
        }
        chatScrollHelper.setScrollDirection(scrollDirection);
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        updatePinnedListButton(false);
        progressDialog = new AlertDialog(getParentActivity(), 3, themeDelegate);
        progressDialog.setOnCancelListener(postponedScrollCancelListener);
        progressDialog.showDelayed(1000);
        postponedScrollToLastMessageQueryIndex = lastLoadIndex;
        waitingForLoad.add(lastLoadIndex);
        postponedScrollMessageId = 0;
        postponedScrollIsCanceled = false;
        getMessagesController().loadMessages(dialog_id, mergeDialogId, false, 30, 0, date, true, 0, classGuid, 4, 0, chatMode, threadMessageId, replyMaxReadId, lastLoadIndex++);
        floatingDateView.setAlpha(0.0f);
        floatingDateView.setTag(null);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Aggregations

AlertDialog (org.telegram.ui.ActionBar.AlertDialog)101 TLRPC (org.telegram.tgnet.TLRPC)71 TextView (android.widget.TextView)63 FrameLayout (android.widget.FrameLayout)47 ArrayList (java.util.ArrayList)47 Context (android.content.Context)45 View (android.view.View)44 AndroidUtilities (org.telegram.messenger.AndroidUtilities)41 LocaleController (org.telegram.messenger.LocaleController)41 Theme (org.telegram.ui.ActionBar.Theme)41 R (org.telegram.messenger.R)40 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)40 LinearLayout (android.widget.LinearLayout)38 Paint (android.graphics.Paint)37 MessagesController (org.telegram.messenger.MessagesController)37 SuppressLint (android.annotation.SuppressLint)36 TextUtils (android.text.TextUtils)36 FileLog (org.telegram.messenger.FileLog)36 Build (android.os.Build)34 Gravity (android.view.Gravity)34