org.telegram.ui.ActionBar.AlertDialog Java Examples

The following examples show how to use org.telegram.ui.ActionBar.AlertDialog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupInviteActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void generateLink(final boolean newRequest) {
    loading = true;
    TLRPC.TL_messages_exportChatInvite req = new TLRPC.TL_messages_exportChatInvite();
    req.peer = MessagesController.getInstance(currentAccount).getInputPeer(-chat_id);
    final int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            invite = (TLRPC.ExportedChatInvite) response;
            if (newRequest) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("RevokeAlertNewLink", R.string.RevokeAlertNewLink));
                builder.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink));
                builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
                showDialog(builder.create());
            }
        }
        loading = false;
        listAdapter.notifyDataSetChanged();
    }));
    ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
    if (listAdapter != null) {
        listAdapter.notifyDataSetChanged();
    }
}
 
Example #2
Source File: ThemeActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void showPermissionAlert(boolean byButton) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (byButton) {
        builder.setMessage(LocaleController.getString("PermissionNoLocationPosition", R.string.PermissionNoLocationPosition));
    } else {
        builder.setMessage(LocaleController.getString("PermissionNoLocation", R.string.PermissionNoLocation));
    }
    builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), (dialog, which) -> {
        if (getParentActivity() == null) {
            return;
        }
        try {
            Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
            getParentActivity().startActivity(intent);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example #3
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void leaveChatPressed()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    if (ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup)
    {
        builder.setMessage(ChatObject.isChannel(chat_id, currentAccount) ? LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert) : LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    else
    {
        builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> kickUser(0));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    showDialog(builder.create());
}
 
Example #4
Source File: ChatUsersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    String newBannedRights = ChatObject.getBannedRightsString(defaultBannedRights);
    if (!newBannedRights.equals(initialBannedRights) || initialSlowmode != selectedSlowmode) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("UserRestrictionsApplyChanges", R.string.UserRestrictionsApplyChanges));
        if (isChannel) {
            builder.setMessage(LocaleController.getString("ChannelSettingsChangedAlert", R.string.ChannelSettingsChangedAlert));
        } else {
            builder.setMessage(LocaleController.getString("GroupSettingsChangedAlert", R.string.GroupSettingsChangedAlert));
        }
        builder.setPositiveButton(LocaleController.getString("ApplyTheme", R.string.ApplyTheme), (dialogInterface, i) -> processDone());
        builder.setNegativeButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialog, which) -> finishFragment());
        showDialog(builder.create());
        return false;
    }
    return true;
}
 
Example #5
Source File: ChatAttachAlertPollLayout.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    boolean allowDiscard = TextUtils.isEmpty(getFixedString(questionString));
    if (allowDiscard) {
        for (int a = 0; a < answersCount; a++) {
            allowDiscard = TextUtils.isEmpty(getFixedString(answers[a]));
            if (!allowDiscard) {
                break;
            }
        }
    }
    if (!allowDiscard) {
        AlertDialog.Builder builder = new AlertDialog.Builder(parentAlert.baseFragment.getParentActivity());
        builder.setTitle(LocaleController.getString("CancelPollAlertTitle", R.string.CancelPollAlertTitle));
        builder.setMessage(LocaleController.getString("CancelPollAlertText", R.string.CancelPollAlertText));
        builder.setPositiveButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialogInterface, i) -> parentAlert.dismiss());
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.show();
    }
    return allowDiscard;
}
 
Example #6
Source File: ChatAttachAlertPollLayout.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    boolean allowDiscard = TextUtils.isEmpty(getFixedString(questionString));
    if (allowDiscard) {
        for (int a = 0; a < answersCount; a++) {
            allowDiscard = TextUtils.isEmpty(getFixedString(answers[a]));
            if (!allowDiscard) {
                break;
            }
        }
    }
    if (!allowDiscard) {
        AlertDialog.Builder builder = new AlertDialog.Builder(parentAlert.baseFragment.getParentActivity());
        builder.setTitle(LocaleController.getString("CancelPollAlertTitle", R.string.CancelPollAlertTitle));
        builder.setMessage(LocaleController.getString("CancelPollAlertText", R.string.CancelPollAlertText));
        builder.setPositiveButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialogInterface, i) -> parentAlert.dismiss());
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.show();
    }
    return allowDiscard;
}
 
Example #7
Source File: CallLogActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void confirmAndDelete(final CallLogRow row) {
	if (getParentActivity() == null)
		return;
	new AlertDialog.Builder(getParentActivity())
			.setTitle(LocaleController.getString("AppName", R.string.AppName))
			.setMessage(LocaleController.getString("ConfirmDeleteCallLog", R.string.ConfirmDeleteCallLog))
			.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog, which) -> {
				ArrayList<Integer> ids = new ArrayList<>();
				for (TLRPC.Message msg : row.calls) {
					ids.add(msg.id);
				}
				MessagesController.getInstance(currentAccount).deleteMessages(ids, null, null, 0, 0, false, false);
			})
			.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
			.show()
			.setCanceledOnTouchOutside(true);
}
 
Example #8
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void showSendMediaAlert(int result, final BaseFragment fragment) {
    if (result == 0) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (result == 1) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickers", R.string.ErrorSendRestrictedStickers));
    } else if (result == 2) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMedia", R.string.ErrorSendRestrictedMedia));
    } else if (result == 3) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedPolls", R.string.ErrorSendRestrictedPolls));
    } else if (result == 4) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickersAll", R.string.ErrorSendRestrictedStickersAll));
    } else if (result == 5) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMediaAll", R.string.ErrorSendRestrictedMediaAll));
    } else if (result == 6) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedPollsAll", R.string.ErrorSendRestrictedPollsAll));
    }

    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example #9
Source File: CallLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void confirmAndDelete(final CallLogRow row)
{
    if (getParentActivity() == null)
        return;
    new AlertDialog.Builder(getParentActivity())
            .setTitle(LocaleController.getString("AppName", R.string.AppName))
            .setMessage(LocaleController.getString("ConfirmDeleteCallLog", R.string.ConfirmDeleteCallLog))
            .setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog, which) ->
            {
                ArrayList<Integer> ids = new ArrayList<>();
                for (TLRPC.Message msg : row.calls)
                {
                    ids.add(msg.id);
                }
                MessagesController.getInstance(currentAccount).deleteMessages(ids, null, null, 0, false);
            })
            .setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
            .show()
            .setCanceledOnTouchOutside(true);
}
 
Example #10
Source File: PopupNotificationActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == 3) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setMessage(LocaleController.getString("PermissionNoAudio", R.string.PermissionNoAudio));
        builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), (dialog, which) -> {
            try {
                Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
                startActivity(intent);
            } catch (Exception e) {
                FileLog.e(e);
            }
        });
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.show();
    }
}
 
Example #11
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment)
{
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null)
    {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example #12
Source File: PollCreateActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    boolean allowDiscard = TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(questionString));
    if (allowDiscard) {
        for (int a = 0; a < answersCount; a++) {
            allowDiscard = TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a]));
            if (!allowDiscard) {
                break;
            }
        }
    }
    if (!allowDiscard) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("CancelPollAlertTitle", R.string.CancelPollAlertTitle));
        builder.setMessage(LocaleController.getString("CancelPollAlertText", R.string.CancelPollAlertText));
        builder.setPositiveButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialogInterface, i) -> finishFragment());
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        showDialog(builder.create());
    }
    return allowDiscard;
}
 
Example #13
Source File: CallLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void confirmAndDelete(final CallLogRow row)
{
    if (getParentActivity() == null)
        return;
    new AlertDialog.Builder(getParentActivity())
            .setTitle(LocaleController.getString("AppName", R.string.AppName))
            .setMessage(LocaleController.getString("ConfirmDeleteCallLog", R.string.ConfirmDeleteCallLog))
            .setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog, which) ->
            {
                ArrayList<Integer> ids = new ArrayList<>();
                for (TLRPC.Message msg : row.calls)
                {
                    ids.add(msg.id);
                }
                MessagesController.getInstance(currentAccount).deleteMessages(ids, null, null, 0, false);
            })
            .setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
            .show()
            .setCanceledOnTouchOutside(true);
}
 
Example #14
Source File: BlockingUpdateView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static boolean checkApkInstallPermissions(final Context context) {
    if (Build.VERSION.SDK_INT >= 26 && !ApplicationLoader.applicationContext.getPackageManager().canRequestPackageInstalls()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setMessage(LocaleController.getString("ApkRestricted", R.string.ApkRestricted));
        builder.setPositiveButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), (dialogInterface, i) -> {
            try {
                context.startActivity(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName())));
            } catch (Exception e) {
                FileLog.e(e);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.show();
        return false;
    }
    return true;
}
 
Example #15
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static Dialog createSingleChoiceDialog(Activity parentActivity, final String[] options, final String title, final int selected, final DialogInterface.OnClickListener listener) {
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    for (int a = 0; a < options.length; a++) {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        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(options[a], selected == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v -> {
            int sel = (Integer) v.getTag();
            builder.getDismissRunnable().run();
            listener.onClick(null, sel);
        });
    }

    builder.setTitle(title);
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
 
Example #16
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static AlertDialog showUpdateAppAlert(final Context context, final String text, boolean updateApp)
{
    if (context == null || text == null)
    {
        return null;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(text);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    if (updateApp)
    {
        builder.setNegativeButton(LocaleController.getString("UpdateApp", R.string.UpdateApp), (dialog, which) -> Browser.openUrl(context, BuildVars.PLAYSTORE_APP_URL));
    }
    return builder.show();
}
 
Example #17
Source File: ChannelCreateActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void showErrorAlert(String error) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    switch (error) {
        case "USERNAME_INVALID":
            builder.setMessage(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
            break;
        case "USERNAME_OCCUPIED":
            builder.setMessage(LocaleController.getString("LinkInUse", R.string.LinkInUse));
            break;
        default:
            builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
            break;
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example #18
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void processCreate(EditTextBoldCursor editText, AlertDialog alertDialog, BaseFragment fragment) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    AndroidUtilities.hideKeyboard(editText);
    Theme.ThemeInfo themeInfo = Theme.createNewTheme(editText.getText().toString());
    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeListUpdated);

    ThemeEditorView themeEditorView = new ThemeEditorView();
    themeEditorView.show(fragment.getParentActivity(), themeInfo);
    alertDialog.dismiss();

    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    if (preferences.getBoolean("themehint", false)) {
        return;
    }
    preferences.edit().putBoolean("themehint", true).commit();
    try {
        Toast.makeText(fragment.getParentActivity(), LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp), Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example #19
Source File: VoIPHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
public static void permissionDenied(final Activity activity, final Runnable onFinish) {
	if (!activity.shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO)) {
		AlertDialog dlg = new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("AppName", R.string.AppName))
				.setMessage(LocaleController.getString("VoipNeedMicPermission", R.string.VoipNeedMicPermission))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.setNegativeButton(LocaleController.getString("Settings", R.string.Settings), (dialog, which) -> {
					Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
					Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
					intent.setData(uri);
					activity.startActivity(intent);
				})
				.show();
		dlg.setOnDismissListener(dialog -> {
			if (onFinish != null)
				onFinish.run();
		});
	}
}
 
Example #20
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void needShowProgress(final int reqiestId)
{
    if (getParentActivity() == null || getParentActivity().isFinishing() || progressDialog != null)
    {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), 1);
    builder.setMessage(LocaleController.getString("Loading", R.string.Loading));
    if (reqiestId != 0)
    {
        builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) ->
        {
            views[currentViewNum].onCancelPressed();
            ConnectionsManager.getInstance(currentAccount).cancelRequest(reqiestId, true);
            progressDialog = null;
        });
    }
    progressDialog = builder.show();
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);
}
 
Example #21
Source File: ChannelAdminLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void showOpenUrlAlert(final String url, boolean ask) {
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(getParentActivity(), url, true);
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setMessage(LocaleController.formatString("OpenUrlAlert", R.string.OpenUrlAlert, url));
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Browser.openUrl(getParentActivity(), url, true);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        showDialog(builder.create());
    }
}
 
Example #22
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void showPermissionAlert(boolean byButton) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (byButton) {
        builder.setMessage(LocaleController.getString("PermissionNoLocationPosition", R.string.PermissionNoLocationPosition));
    } else {
        builder.setMessage(LocaleController.getString("PermissionNoLocation", R.string.PermissionNoLocation));
    }
    builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), (dialog, which) -> {
        if (getParentActivity() == null) {
            return;
        }
        try {
            Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
            getParentActivity().startActivity(intent);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example #23
Source File: ChatUsersActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    String newBannedRights = ChatObject.getBannedRightsString(defaultBannedRights);
    if (!newBannedRights.equals(initialBannedRights) || initialSlowmode != selectedSlowmode) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("UserRestrictionsApplyChanges", R.string.UserRestrictionsApplyChanges));
        if (isChannel) {
            builder.setMessage(LocaleController.getString("ChannelSettingsChangedAlert", R.string.ChannelSettingsChangedAlert));
        } else {
            builder.setMessage(LocaleController.getString("GroupSettingsChangedAlert", R.string.GroupSettingsChangedAlert));
        }
        builder.setPositiveButton(LocaleController.getString("ApplyTheme", R.string.ApplyTheme), (dialogInterface, i) -> processDone());
        builder.setNegativeButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialog, which) -> finishFragment());
        showDialog(builder.create());
        return false;
    }
    return true;
}
 
Example #24
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog createAccountSelectDialog(Activity parentActivity, final AccountSelectDelegate delegate) {
    if (UserConfig.getActivatedAccountsCount() < 2) {
        return null;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    final Runnable dismissRunnable = builder.getDismissRunnable();
    final AlertDialog[] alertDialog = new AlertDialog[1];

    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        TLRPC.User u = UserConfig.getInstance(a).getCurrentUser();
        if (u != null) {
            AccountSelectCell cell = new AccountSelectCell(parentActivity);
            cell.setAccount(a, false);
            cell.setPadding(AndroidUtilities.dp(14), 0, AndroidUtilities.dp(14), 0);
            cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            cell.setOnClickListener(v -> {
                if (alertDialog[0] != null) {
                    alertDialog[0].setOnDismissListener(null);
                }
                dismissRunnable.run();
                AccountSelectCell cell1 = (AccountSelectCell) v;
                delegate.didSelectAccount(cell1.getAccountNumber());
            });
        }
    }

    builder.setTitle(LocaleController.getString("SelectAccount", R.string.SelectAccount));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return alertDialog[0] = builder.create();
}
 
Example #25
Source File: ChangePhoneActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void resendCode() {
    final Bundle params = new Bundle();
    params.putString("phone", phone);
    params.putString("ephone", emailPhone);
    params.putString("phoneFormated", requestPhone);

    nextPressed = true;
    needShowProgress();

    final TLRPC.TL_auth_resendCode req = new TLRPC.TL_auth_resendCode();
    req.phone_number = requestPhone;
    req.phone_code_hash = phoneHash;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        nextPressed = false;
        if (error == null) {
            fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
        } else {
            AlertDialog dialog = (AlertDialog) AlertsCreator.processError(currentAccount, error, ChangePhoneActivity.this, req);
            if (dialog != null && error.text.contains("PHONE_CODE_EXPIRED")) {
                dialog.setPositiveButtonListener((dialog1, which) -> {
                    onBackPressed(true);
                    finishFragment();
                });
            }
        }
        needHideProgress();
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example #26
Source File: LocationActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void showPermissionAlert(boolean byButton) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (byButton) {
        builder.setMessage(LocaleController.getString("PermissionNoLocationPosition", R.string.PermissionNoLocationPosition));
    } else {
        builder.setMessage(LocaleController.getString("PermissionNoLocation", R.string.PermissionNoLocation));
    }
    builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), new DialogInterface.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.GINGERBREAD)
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (getParentActivity() == null) {
                return;
            }
            try {
                Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
                getParentActivity().startActivity(intent);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    });
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example #27
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog createSingleChoiceDialog(Activity parentActivity, final BaseFragment parentFragment, final String[] options, final String title, final int selected, final DialogInterface.OnClickListener listener)
{
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    for (int a = 0; a < options.length; a++)
    {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        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(options[a], selected == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v ->
        {
            int sel = (Integer) v.getTag();

            if (parentFragment != null)
            {
                parentFragment.dismissCurrentDialig();
            }
            listener.onClick(null, sel);
        });
    }

    builder.setTitle(title);
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
 
Example #28
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog.Builder createContactsPermissionDialog(final Activity parentActivity, final MessagesStorage.IntCallback callback)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTopImage(R.drawable.permissions_contacts, Theme.getColor(Theme.key_dialogTopBackground));
    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("ContactsPermissionAlert", R.string.ContactsPermissionAlert)));
    builder.setPositiveButton(LocaleController.getString("ContactsPermissionAlertContinue", R.string.ContactsPermissionAlertContinue), (dialog, which) -> callback.run(1));
    builder.setNegativeButton(LocaleController.getString("ContactsPermissionAlertNotNow", R.string.ContactsPermissionAlertNotNow), (dialog, which) -> callback.run(0));
    return builder;
}
 
Example #29
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog createSingleChoiceDialog(Activity parentActivity, final BaseFragment parentFragment, final String[] options, final String title, final int selected, final DialogInterface.OnClickListener listener)
{
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    for (int a = 0; a < options.length; a++)
    {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        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(options[a], selected == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v ->
        {
            int sel = (Integer) v.getTag();

            if (parentFragment != null)
            {
                parentFragment.dismissCurrentDialig();
            }
            listener.onClick(null, sel);
        });
    }

    builder.setTitle(title);
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
 
Example #30
Source File: PrivacyControlActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void showErrorAlert() {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.getString("PrivacyFloodControlError", R.string.PrivacyFloodControlError));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}