org.telegram.ui.ActionBar.BaseFragment Java Examples

The following examples show how to use org.telegram.ui.ActionBar.BaseFragment. 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: AlertsCreator.java    From TelePlus-Android 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));
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example #2
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment) {
    try {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        if (fragment.getParentActivity() == null) {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage(LocaleController.getString("InstallGoogleMaps", R.string.InstallGoogleMaps));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            } catch (Exception e1) {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example #3
Source File: AboutLinkCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public AboutLinkCell(Context context, BaseFragment fragment) {
    super(context);

    parentFragment = fragment;

    valueTextView = new TextView(context);
    valueTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
    valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    valueTextView.setLines(1);
    valueTextView.setMaxLines(1);
    valueTextView.setSingleLine(true);
    valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(valueTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, 23, 0, 23, 10));

    setWillNotDraw(false);
}
 
Example #4
Source File: FilterCreateActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void processAddFilter(MessagesController.DialogFilter filter, int newFilterFlags, String newFilterName, ArrayList<Integer> newAlwaysShow, ArrayList<Integer> newNeverShow, boolean creatingNew, boolean atBegin, boolean hasUserChanged, boolean resetUnreadCounter, BaseFragment fragment, Runnable onFinish) {
    if (filter.flags != newFilterFlags || hasUserChanged) {
        filter.pendingUnreadCount = -1;
        if (resetUnreadCounter) {
            filter.unreadCount = -1;
        }
    }
    filter.flags = newFilterFlags;
    filter.name = newFilterName;
    filter.neverShow = newNeverShow;
    filter.alwaysShow = newAlwaysShow;
    if (creatingNew) {
        fragment.getMessagesController().addFilter(filter, atBegin);
    } else {
        fragment.getMessagesController().onFilterUpdate(filter);
    }
    fragment.getMessagesStorage().saveDialogFilter(filter, atBegin, true);
    if (onFinish != null) {
        onFinish.run();
    }
}
 
Example #5
Source File: AboutLinkCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public AboutLinkCell(Context context, BaseFragment fragment) {
    super(context);

    parentFragment = fragment;

    valueTextView = new TextView(context);
    valueTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
    valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    valueTextView.setLines(1);
    valueTextView.setMaxLines(1);
    valueTextView.setSingleLine(true);
    valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(valueTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, 23, 0, 23, 10));

    setWillNotDraw(false);
}
 
Example #6
Source File: FilterCreateActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void processAddFilter(MessagesController.DialogFilter filter, int newFilterFlags, String newFilterName, ArrayList<Integer> newAlwaysShow, ArrayList<Integer> newNeverShow, boolean creatingNew, boolean atBegin, boolean hasUserChanged, boolean resetUnreadCounter, BaseFragment fragment, Runnable onFinish) {
    if (filter.flags != newFilterFlags || hasUserChanged) {
        filter.pendingUnreadCount = -1;
        if (resetUnreadCounter) {
            filter.unreadCount = -1;
        }
    }
    filter.flags = newFilterFlags;
    filter.name = newFilterName;
    filter.neverShow = newNeverShow;
    filter.alwaysShow = newAlwaysShow;
    if (creatingNew) {
        fragment.getMessagesController().addFilter(filter, atBegin);
    } else {
        fragment.getMessagesController().onFilterUpdate(filter);
    }
    fragment.getMessagesStorage().saveDialogFilter(filter, atBegin, true);
    if (onFinish != null) {
        onFinish.run();
    }
}
 
Example #7
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static Toast showSimpleToast(BaseFragment baseFragment, final String text)
{
    if (text == null)
    {
        return null;
    }
    Context context;
    if (baseFragment != null && baseFragment.getParentActivity() != null)
    {
        context = baseFragment.getParentActivity();
    }
    else
    {
        context = ApplicationLoader.applicationContext;
    }
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();
    return toast;
}
 
Example #8
Source File: AlertsCreator.java    From Telegram 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: 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 #10
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 #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: AlertsCreator.java    From Telegram-FOSS 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 #13
Source File: AlertsCreator.java    From Telegram 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 #14
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment)
{
    try
    {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        if (fragment.getParentActivity() == null)
        {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage("Install Google Maps?");
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
        {
            try
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            }
            catch (Exception e1)
            {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example #15
Source File: ExternalActionActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void needLayout() {
    if (AndroidUtilities.isTablet()) {
        RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams();
        relativeLayoutParams.leftMargin = (AndroidUtilities.displaySize.x - relativeLayoutParams.width) / 2;
        int y = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        relativeLayoutParams.topMargin = y + (AndroidUtilities.displaySize.y - relativeLayoutParams.height - y) / 2;
        layersActionBarLayout.setLayoutParams(relativeLayoutParams);


        if (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            int leftWidth = AndroidUtilities.displaySize.x / 100 * 35;
            if (leftWidth < AndroidUtilities.dp(320)) {
                leftWidth = AndroidUtilities.dp(320);
            }

            relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
            relativeLayoutParams.width = leftWidth;
            relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
            actionBarLayout.setLayoutParams(relativeLayoutParams);

            if (AndroidUtilities.isSmallTablet() && actionBarLayout.fragmentsStack.size() == 2) {
                BaseFragment chatFragment = actionBarLayout.fragmentsStack.get(1);
                chatFragment.onPause();
                actionBarLayout.fragmentsStack.remove(1);
                actionBarLayout.showLastFragment();
            }
        } else {
            relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
            relativeLayoutParams.width = LayoutHelper.MATCH_PARENT;
            relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
            actionBarLayout.setLayoutParams(relativeLayoutParams);
        }
    }
}
 
Example #16
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String title, final String text) {
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null) {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), title, text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example #17
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String text)
{
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null)
    {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example #18
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog createVibrationSelectDialog(Activity parentActivity, final BaseFragment parentFragment, final long dialog_id, final boolean globalGroup, final boolean globalAll, final Runnable onSelect)
{
    String prefix;
    if (dialog_id != 0)
    {
        prefix = "vibrate_";
    }
    else
    {
        prefix = globalGroup ? "vibrate_group" : "vibrate_messages";
    }
    return createVibrationSelectDialog(parentActivity, parentFragment, dialog_id, prefix, onSelect);
}
 
Example #19
Source File: FiltersListBottomSheet.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static ArrayList<MessagesController.DialogFilter> getCanAddDialogFilters(BaseFragment fragment, ArrayList<Long> selectedDialogs) {
    ArrayList<MessagesController.DialogFilter> result = new ArrayList<>();
    ArrayList<MessagesController.DialogFilter> filters = fragment.getMessagesController().dialogFilters;
    for (int a = 0, N = filters.size(); a < N; a++) {
        MessagesController.DialogFilter filter = filters.get(a);
        if (!getDialogsCount(fragment, filter, selectedDialogs, true, true).isEmpty()) {
            result.add(filter);
        }
    }
    return result;
}
 
Example #20
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 #21
Source File: ExternalActionActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void needLayout() {
    if (AndroidUtilities.isTablet()) {
        RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams();
        relativeLayoutParams.leftMargin = (AndroidUtilities.displaySize.x - relativeLayoutParams.width) / 2;
        int y = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        relativeLayoutParams.topMargin = y + (AndroidUtilities.displaySize.y - relativeLayoutParams.height - y) / 2;
        layersActionBarLayout.setLayoutParams(relativeLayoutParams);


        if (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            int leftWidth = AndroidUtilities.displaySize.x / 100 * 35;
            if (leftWidth < AndroidUtilities.dp(320)) {
                leftWidth = AndroidUtilities.dp(320);
            }

            relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
            relativeLayoutParams.width = leftWidth;
            relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
            actionBarLayout.setLayoutParams(relativeLayoutParams);

            if (AndroidUtilities.isSmallTablet() && actionBarLayout.fragmentsStack.size() == 2) {
                BaseFragment chatFragment = actionBarLayout.fragmentsStack.get(1);
                chatFragment.onPause();
                actionBarLayout.fragmentsStack.remove(1);
                actionBarLayout.showLastFragment();
            }
        } else {
            relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
            relativeLayoutParams.width = LayoutHelper.MATCH_PARENT;
            relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
            actionBarLayout.setLayoutParams(relativeLayoutParams);
        }
    }
}
 
Example #22
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment)
{
    try
    {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        if (fragment.getParentActivity() == null)
        {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage("Install Google Maps?");
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
        {
            try
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            }
            catch (Exception e1)
            {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example #23
Source File: FiltersListBottomSheet.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static ArrayList<MessagesController.DialogFilter> getCanAddDialogFilters(BaseFragment fragment, ArrayList<Long> selectedDialogs) {
    ArrayList<MessagesController.DialogFilter> result = new ArrayList<>();
    ArrayList<MessagesController.DialogFilter> filters = fragment.getMessagesController().dialogFilters;
    for (int a = 0, N = filters.size(); a < N; a++) {
        MessagesController.DialogFilter filter = filters.get(a);
        if (!getDialogsCount(fragment, filter, selectedDialogs, true, true).isEmpty()) {
            result.add(filter);
        }
    }
    return result;
}
 
Example #24
Source File: FiltersListBottomSheet.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static ArrayList<Integer> getDialogsCount(BaseFragment fragment, MessagesController.DialogFilter filter, ArrayList<Long> selectedDialogs, boolean always, boolean check) {
    ArrayList<Integer> dids = new ArrayList<>();
    for (int b = 0, N2 = selectedDialogs.size(); b < N2; b++) {
        long did = selectedDialogs.get(b);
        int lowerId = (int) did;
        if (lowerId == 0) {
            int highId = (int) (did >> 32);
            TLRPC.EncryptedChat encryptedChat = fragment.getMessagesController().getEncryptedChat(highId);
            if (encryptedChat != null) {
                lowerId = encryptedChat.user_id;
                if (dids.contains(lowerId)) {
                    continue;
                }
            } else {
                continue;
            }
        }
        if (filter != null && (always && filter.alwaysShow.contains(lowerId) || !always && filter.neverShow.contains(lowerId))) {
            continue;
        }
        dids.add(lowerId);
        if (check) {
            break;
        }
    }
    return dids;
}
 
Example #25
Source File: StickersAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public StickersAlert(Context context, BaseFragment baseFragment, TLRPC.InputStickerSet set, TLRPC.TL_messages_stickerSet loadedSet, StickersAlertDelegate stickersAlertDelegate) {
    super(context, false);
    delegate = stickersAlertDelegate;
    inputStickerSet = set;
    stickerSet = loadedSet;
    parentFragment = baseFragment;
    loadStickerSet();
    init(context);
}
 
Example #26
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Toast showSimpleToast(BaseFragment baseFragment, final String text) {
    if (text == null) {
        return null;
    }
    Context context;
    if (baseFragment != null && baseFragment.getParentActivity() != null) {
        context = baseFragment.getParentActivity();
    } else {
        context = ApplicationLoader.applicationContext;
    }
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();
    return toast;
}
 
Example #27
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static Toast showSimpleToast(BaseFragment baseFragment, final String text) {
    if (text == null) {
        return null;
    }
    Context context;
    if (baseFragment != null && baseFragment.getParentActivity() != null) {
        context = baseFragment.getParentActivity();
    } else {
        context = ApplicationLoader.applicationContext;
    }
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();
    return toast;
}
 
Example #28
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String title, final String text) {
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null) {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), title, text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example #29
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog createSupportAlert(BaseFragment fragment) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return null;
    }
    final TextView message = new TextView(fragment.getParentActivity());
    Spannable spanned = new SpannableString(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo).replace("\n", "<br>")));
    URLSpan[] spans = spanned.getSpans(0, spanned.length(), URLSpan.class);
    for (int i = 0; i < spans.length; i++) {
        URLSpan span = spans[i];
        int start = spanned.getSpanStart(span);
        int end = spanned.getSpanEnd(span);
        spanned.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL()) {
            @Override
            public void onClick(View widget) {
                fragment.dismissCurrentDialig();
                super.onClick(widget);
            }
        };
        spanned.setSpan(span, start, end, 0);
    }
    message.setText(spanned);
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
    message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
    message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
    message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));

    AlertDialog.Builder builder1 = new AlertDialog.Builder(fragment.getParentActivity());
    builder1.setView(message);
    builder1.setTitle(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
    builder1.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), (dialogInterface, i) -> performAskAQuestion(fragment));
    builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder1.create();
}
 
Example #30
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}