Java Code Examples for org.telegram.messenger.LocaleController#formatString()

The following examples show how to use org.telegram.messenger.LocaleController#formatString() . 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: ThemeActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private String getLocationSunString() {
    int currentHour = Theme.autoNightSunriseTime / 60;
    int currentMinute = (Theme.autoNightSunriseTime - currentHour * 60);
    String sunriseTimeStr = String.format("%02d:%02d", currentHour, currentMinute);
    currentHour = Theme.autoNightSunsetTime / 60;
    currentMinute = (Theme.autoNightSunsetTime - currentHour * 60);
    String sunsetTimeStr = String.format("%02d:%02d", currentHour, currentMinute);
    return LocaleController.formatString("AutoNightUpdateLocationInfo", R.string.AutoNightUpdateLocationInfo, sunsetTimeStr, sunriseTimeStr);
}
 
Example 2
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static String getFloodWaitString(String error) {
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60) {
        timeString = LocaleController.formatPluralString("Seconds", time);
    } else {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }
    return LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString);
}
 
Example 3
Source File: ChatUsersActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public ChooseView(Context context) {
    super(context);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(AndroidUtilities.dp(13));

    for (int a = 0; a < 7; a++) {
        String string;
        switch (a) {
            case 0:
                string = LocaleController.getString("SlowmodeOff", R.string.SlowmodeOff);
                break;
            case 1:
                string = LocaleController.formatString("SlowmodeSeconds", R.string.SlowmodeSeconds, 10);
                break;
            case 2:
                string = LocaleController.formatString("SlowmodeSeconds", R.string.SlowmodeSeconds, 30);
                break;
            case 3:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 1);
                break;
            case 4:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 5);
                break;
            case 5:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 15);
                break;
            case 6:
            default:
                string = LocaleController.formatString("SlowmodeHours", R.string.SlowmodeHours, 1);
                break;
        }
        strings.add(string);
        sizes.add((int) Math.ceil(textPaint.measureText(string)));
    }
}
 
Example 4
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static String getFloodWaitString(String error)
{
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }
    return LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString);
}
 
Example 5
Source File: DocumentSelectActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getRootSubtitle(String path) {
    try {
        StatFs stat = new StatFs(path);
        long total = (long)stat.getBlockCount() * (long)stat.getBlockSize();
        long free = (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
        if (total == 0) {
            return "";
        }
        return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
    } catch (Exception e) {
        FileLog.e(e);
    }
    return path;
}
 
Example 6
Source File: ThemeActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getLocationSunString() {
    int currentHour = Theme.autoNightSunriseTime / 60;
    int currentMinute = (Theme.autoNightSunriseTime - currentHour * 60);
    String sunriseTimeStr = String.format("%02d:%02d", currentHour, currentMinute);
    currentHour = Theme.autoNightSunsetTime / 60;
    currentMinute = (Theme.autoNightSunsetTime - currentHour * 60);
    String sunsetTimeStr = String.format("%02d:%02d", currentHour, currentMinute);
    return LocaleController.formatString("AutoNightUpdateLocationInfo", R.string.AutoNightUpdateLocationInfo, sunsetTimeStr, sunriseTimeStr);
}
 
Example 7
Source File: ChatAttachAlertDocumentLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private String getRootSubtitle(String path) {
    try {
        StatFs stat = new StatFs(path);
        long total = (long) stat.getBlockCount() * (long) stat.getBlockSize();
        long free = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        if (total == 0) {
            return "";
        }
        return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
    } catch (Exception e) {
        FileLog.e(e);
    }
    return path;
}
 
Example 8
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static String getFloodWaitString(String error)
{
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }
    return LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString);
}
 
Example 9
Source File: DocumentSelectActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getRootSubtitle(String path) {
    try {
        StatFs stat = new StatFs(path);
        long total = (long)stat.getBlockCount() * (long)stat.getBlockSize();
        long free = (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
        if (total == 0) {
            return "";
        }
        return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
    } catch (Exception e) {
        FileLog.e(e);
    }
    return path;
}
 
Example 10
Source File: ChatUsersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public ChooseView(Context context) {
    super(context);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(AndroidUtilities.dp(13));

    for (int a = 0; a < 7; a++) {
        String string;
        switch (a) {
            case 0:
                string = LocaleController.getString("SlowmodeOff", R.string.SlowmodeOff);
                break;
            case 1:
                string = LocaleController.formatString("SlowmodeSeconds", R.string.SlowmodeSeconds, 10);
                break;
            case 2:
                string = LocaleController.formatString("SlowmodeSeconds", R.string.SlowmodeSeconds, 30);
                break;
            case 3:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 1);
                break;
            case 4:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 5);
                break;
            case 5:
                string = LocaleController.formatString("SlowmodeMinutes", R.string.SlowmodeMinutes, 15);
                break;
            case 6:
            default:
                string = LocaleController.formatString("SlowmodeHours", R.string.SlowmodeHours, 1);
                break;
        }
        strings.add(string);
        sizes.add((int) Math.ceil(textPaint.measureText(string)));
    }
}
 
Example 11
Source File: ChatActionCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setCustomDate(int date, boolean scheduled, boolean inLayout) {
    if (customDate == date) {
        return;
    }
    CharSequence newText;
    if (scheduled) {
        if (date == 0x7ffffffe) {
            newText = LocaleController.getString("MessageScheduledUntilOnline", R.string.MessageScheduledUntilOnline);
        } else {
            newText = LocaleController.formatString("MessageScheduledOn", R.string.MessageScheduledOn, LocaleController.formatDateChat(date));
        }
    } else {
        newText = LocaleController.formatDateChat(date);
    }
    if (customText != null && TextUtils.equals(newText, customText)) {
        return;
    }
    customDate = date;
    customText = newText;
    if (getMeasuredWidth() != 0) {
        createLayout(customText, getMeasuredWidth());
        invalidate();
    }
    if (!wasLayout) {
        if (inLayout) {
            AndroidUtilities.runOnUIThread(this::requestLayout);
        } else {
            requestLayout();
        }
    } else {
        buildLayout();
    }
}
 
Example 12
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog createMuteAlert(Context context, final long dialog_id) {
    if (context == null) {
        return null;
    }

    BottomSheet.Builder builder = new BottomSheet.Builder(context);
    builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true);
    CharSequence[] items = new CharSequence[]{
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
            LocaleController.getString("MuteDisable", R.string.MuteDisable)
    };
    builder.setItems(items, (dialogInterface, i) -> {
                int setting;
                if (i == 0) {
                    setting = NotificationsController.SETTING_MUTE_HOUR;
                } else if (i == 1) {
                    setting = NotificationsController.SETTING_MUTE_8_HOURS;
                } else if (i == 2) {
                    setting = NotificationsController.SETTING_MUTE_2_DAYS;
                } else {
                    setting = NotificationsController.SETTING_MUTE_FOREVER;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting);
            }
    );
    return builder.create();
}
 
Example 13
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog createMuteAlert(Context context, final long dialog_id) {
    if (context == null) {
        return null;
    }

    BottomSheet.Builder builder = new BottomSheet.Builder(context);
    builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true);
    CharSequence[] items = new CharSequence[]{
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
            LocaleController.getString("MuteDisable", R.string.MuteDisable)
    };
    builder.setItems(items, (dialogInterface, i) -> {
                int setting;
                if (i == 0) {
                    setting = NotificationsController.SETTING_MUTE_HOUR;
                } else if (i == 1) {
                    setting = NotificationsController.SETTING_MUTE_8_HOURS;
                } else if (i == 2) {
                    setting = NotificationsController.SETTING_MUTE_2_DAYS;
                } else {
                    setting = NotificationsController.SETTING_MUTE_FOREVER;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting);
            }
    );
    return builder.create();
}
 
Example 14
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static String getFloodWaitString(String error) {
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60) {
        timeString = LocaleController.formatPluralString("Seconds", time);
    } else {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }
    return LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString);
}
 
Example 15
Source File: ChatLinkActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void showLinkAlert(TLRPC.Chat chat, boolean query) {
    TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id);
    if (chatFull == null) {
        if (query) {
            getMessagesController().loadFullChat(chat.id, 0, true);
            waitingForFullChat = chat;
            waitingForFullChatProgressAlert = new AlertDialog(getParentActivity(), 3);
            AndroidUtilities.runOnUIThread(() -> {
                if (waitingForFullChatProgressAlert == null) {
                    return;
                }
                waitingForFullChatProgressAlert.setOnCancelListener(dialog -> waitingForFullChat = null);
                showDialog(waitingForFullChatProgressAlert);
            }, 500);
        }
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

    TextView messageTextView = new TextView(getParentActivity());
    messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    String message;
    if (TextUtils.isEmpty(chat.username)) {
        message = LocaleController.formatString("DiscussionLinkGroupPublicPrivateAlert", R.string.DiscussionLinkGroupPublicPrivateAlert, chat.title, currentChat.title);
    } else {
        if (TextUtils.isEmpty(currentChat.username)) {
            message = LocaleController.formatString("DiscussionLinkGroupPrivateAlert", R.string.DiscussionLinkGroupPrivateAlert, chat.title, currentChat.title);
        } else {
            message = LocaleController.formatString("DiscussionLinkGroupPublicAlert", R.string.DiscussionLinkGroupPublicAlert, chat.title, currentChat.title);
        }
    }
    if (chatFull.hidden_prehistory) {
        message += "\n\n" + LocaleController.getString("DiscussionLinkGroupAlertHistory", R.string.DiscussionLinkGroupAlertHistory);
    }
    messageTextView.setText(AndroidUtilities.replaceTags(message));

    FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
    builder.setView(frameLayout2);

    AvatarDrawable avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));

    BackupImageView imageView = new BackupImageView(getParentActivity());
    imageView.setRoundRadius(AndroidUtilities.dp(20));
    frameLayout2.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));

    TextView textView = new TextView(getParentActivity());
    textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setText(chat.title);

    frameLayout2.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
    frameLayout2.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
    avatarDrawable.setInfo(chat);
    imageView.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable, chat);
    builder.setPositiveButton(LocaleController.getString("DiscussionLinkGroup", R.string.DiscussionLinkGroup), (dialogInterface, i) -> {
        if (chatFull.hidden_prehistory) {
            MessagesController.getInstance(currentAccount).toogleChannelInvitesHistory(chat.id, false);
        }
        linkChat(chat, null);
    });
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    showDialog(builder.create());
}
 
Example 16
Source File: ChatLinkActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void showLinkAlert(TLRPC.Chat chat, boolean query) {
    TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id);
    if (chatFull == null) {
        if (query) {
            getMessagesController().loadFullChat(chat.id, 0, true);
            waitingForFullChat = chat;
            waitingForFullChatProgressAlert = new AlertDialog(getParentActivity(), 3);
            AndroidUtilities.runOnUIThread(() -> {
                if (waitingForFullChatProgressAlert == null) {
                    return;
                }
                waitingForFullChatProgressAlert.setOnCancelListener(dialog -> waitingForFullChat = null);
                showDialog(waitingForFullChatProgressAlert);
            }, 500);
        }
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

    TextView messageTextView = new TextView(getParentActivity());
    messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    String message;
    if (TextUtils.isEmpty(chat.username)) {
        message = LocaleController.formatString("DiscussionLinkGroupPublicPrivateAlert", R.string.DiscussionLinkGroupPublicPrivateAlert, chat.title, currentChat.title);
    } else {
        if (TextUtils.isEmpty(currentChat.username)) {
            message = LocaleController.formatString("DiscussionLinkGroupPrivateAlert", R.string.DiscussionLinkGroupPrivateAlert, chat.title, currentChat.title);
        } else {
            message = LocaleController.formatString("DiscussionLinkGroupPublicAlert", R.string.DiscussionLinkGroupPublicAlert, chat.title, currentChat.title);
        }
    }
    if (chatFull.hidden_prehistory) {
        message += "\n\n" + LocaleController.getString("DiscussionLinkGroupAlertHistory", R.string.DiscussionLinkGroupAlertHistory);
    }
    messageTextView.setText(AndroidUtilities.replaceTags(message));

    FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
    builder.setView(frameLayout2);

    AvatarDrawable avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));

    BackupImageView imageView = new BackupImageView(getParentActivity());
    imageView.setRoundRadius(AndroidUtilities.dp(20));
    frameLayout2.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));

    TextView textView = new TextView(getParentActivity());
    textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setText(chat.title);

    frameLayout2.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
    frameLayout2.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
    avatarDrawable.setInfo(chat);
    imageView.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable, chat);
    builder.setPositiveButton(LocaleController.getString("DiscussionLinkGroup", R.string.DiscussionLinkGroup), (dialogInterface, i) -> {
        if (chatFull.hidden_prehistory) {
            MessagesController.getInstance(currentAccount).toogleChannelInvitesHistory(chat.id, false);
        }
        linkChat(chat, null);
    });
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    showDialog(builder.create());
}
 
Example 17
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static Dialog createMuteAlert(Context context, final long dialog_id)
{
    if (context == null)
    {
        return null;
    }

    BottomSheet.Builder builder = new BottomSheet.Builder(context);
    builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
    CharSequence[] items = new CharSequence[]{
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
            LocaleController.getString("MuteDisable", R.string.MuteDisable)
    };
    builder.setItems(items, (dialogInterface, i) ->
            {
                int untilTime = ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime();
                if (i == 0)
                {
                    untilTime += 60 * 60;
                }
                else if (i == 1)
                {
                    untilTime += 60 * 60 * 8;
                }
                else if (i == 2)
                {
                    untilTime += 60 * 60 * 48;
                }
                else if (i == 3)
                {
                    untilTime = Integer.MAX_VALUE;
                }

                SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
                SharedPreferences.Editor editor = preferences.edit();
                long flags;
                if (i == 3)
                {
                    editor.putInt("notify2_" + dialog_id, 2);
                    flags = 1;
                }
                else
                {
                    editor.putInt("notify2_" + dialog_id, 3);
                    editor.putInt("notifyuntil_" + dialog_id, untilTime);
                    flags = ((long) untilTime << 32) | 1;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).removeNotificationsForDialog(dialog_id);
                MessagesStorage.getInstance(UserConfig.selectedAccount).setDialogFlags(dialog_id, flags);
                editor.commit();
                TLRPC.TL_dialog dialog = MessagesController.getInstance(UserConfig.selectedAccount).dialogs_dict.get(dialog_id);
                if (dialog != null)
                {
                    dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                    dialog.notify_settings.mute_until = untilTime;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).updateServerNotificationsSettings(dialog_id);
            }
    );
    return builder.create();
}
 
Example 18
Source File: PrivacySettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private String formatRulesString(int rulesType) {
    ArrayList<TLRPC.PrivacyRule> privacyRules = ContactsController.getInstance(currentAccount).getPrivacyRules(rulesType);
    if (privacyRules.size() == 0) {
        return LocaleController.getString("LastSeenNobody", R.string.LastSeenNobody);
    }
    int type = -1;
    int plus = 0;
    int minus = 0;
    for (int a = 0; a < privacyRules.size(); a++) {
        TLRPC.PrivacyRule rule = privacyRules.get(a);
        if (rule instanceof TLRPC.TL_privacyValueAllowUsers) {
            plus += rule.users.size();
        } else if (rule instanceof TLRPC.TL_privacyValueDisallowUsers) {
            minus += rule.users.size();
        } else if (rule instanceof TLRPC.TL_privacyValueAllowAll) {
            type = 0;
        } else if (rule instanceof TLRPC.TL_privacyValueDisallowAll) {
            type = 1;
        } else {
            type = 2;
        }
    }
    if (type == 0 || type == -1 && minus > 0) {
        if (minus == 0) {
            return LocaleController.getString("LastSeenEverybody", R.string.LastSeenEverybody);
        } else {
            return LocaleController.formatString("LastSeenEverybodyMinus", R.string.LastSeenEverybodyMinus, minus);
        }
    } else if (type == 2 || type == -1 && minus > 0 && plus > 0) {
        if (plus == 0 && minus == 0) {
            return LocaleController.getString("LastSeenContacts", R.string.LastSeenContacts);
        } else {
            if (plus != 0 && minus != 0) {
                return LocaleController.formatString("LastSeenContactsMinusPlus", R.string.LastSeenContactsMinusPlus, minus, plus);
            } else if (minus != 0) {
                return LocaleController.formatString("LastSeenContactsMinus", R.string.LastSeenContactsMinus, minus);
            } else {
                return LocaleController.formatString("LastSeenContactsPlus", R.string.LastSeenContactsPlus, plus);
            }
        }
    } else if (type == 1 || plus > 0) {
        if (plus == 0) {
            return LocaleController.getString("LastSeenNobody", R.string.LastSeenNobody);
        } else {
            return LocaleController.formatString("LastSeenNobodyPlus", R.string.LastSeenNobodyPlus, plus);
        }
    }
    return "unknown";
}
 
Example 19
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static Dialog createMuteAlert(Context context, final long dialog_id)
{
    if (context == null)
    {
        return null;
    }

    BottomSheet.Builder builder = new BottomSheet.Builder(context);
    builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
    CharSequence[] items = new CharSequence[]{
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
            LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
            LocaleController.getString("MuteDisable", R.string.MuteDisable)
    };
    builder.setItems(items, (dialogInterface, i) ->
            {
                int untilTime = ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime();
                if (i == 0)
                {
                    untilTime += 60 * 60;
                }
                else if (i == 1)
                {
                    untilTime += 60 * 60 * 8;
                }
                else if (i == 2)
                {
                    untilTime += 60 * 60 * 48;
                }
                else if (i == 3)
                {
                    untilTime = Integer.MAX_VALUE;
                }

                SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
                SharedPreferences.Editor editor = preferences.edit();
                long flags;
                if (i == 3)
                {
                    editor.putInt("notify2_" + dialog_id, 2);
                    flags = 1;
                }
                else
                {
                    editor.putInt("notify2_" + dialog_id, 3);
                    editor.putInt("notifyuntil_" + dialog_id, untilTime);
                    flags = ((long) untilTime << 32) | 1;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).removeNotificationsForDialog(dialog_id);
                MessagesStorage.getInstance(UserConfig.selectedAccount).setDialogFlags(dialog_id, flags);
                editor.commit();
                TLRPC.TL_dialog dialog = MessagesController.getInstance(UserConfig.selectedAccount).dialogs_dict.get(dialog_id);
                if (dialog != null)
                {
                    dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                    dialog.notify_settings.mute_until = untilTime;
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).updateServerNotificationsSettings(dialog_id);
            }
    );
    return builder.create();
}
 
Example 20
Source File: PrivacySettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private String formatRulesString(int rulesType) {
    ArrayList<TLRPC.PrivacyRule> privacyRules = ContactsController.getInstance(currentAccount).getPrivacyRules(rulesType);
    if (privacyRules.size() == 0) {
        return LocaleController.getString("LastSeenNobody", R.string.LastSeenNobody);
    }
    int type = -1;
    int plus = 0;
    int minus = 0;
    for (int a = 0; a < privacyRules.size(); a++) {
        TLRPC.PrivacyRule rule = privacyRules.get(a);
        if (rule instanceof TLRPC.TL_privacyValueAllowUsers) {
            plus += rule.users.size();
        } else if (rule instanceof TLRPC.TL_privacyValueDisallowUsers) {
            minus += rule.users.size();
        } else if (rule instanceof TLRPC.TL_privacyValueAllowAll) {
            type = 0;
        } else if (rule instanceof TLRPC.TL_privacyValueDisallowAll) {
            type = 1;
        } else {
            type = 2;
        }
    }
    if (type == 0 || type == -1 && minus > 0) {
        if (minus == 0) {
            return LocaleController.getString("LastSeenEverybody", R.string.LastSeenEverybody);
        } else {
            return LocaleController.formatString("LastSeenEverybodyMinus", R.string.LastSeenEverybodyMinus, minus);
        }
    } else if (type == 2 || type == -1 && minus > 0 && plus > 0) {
        if (plus == 0 && minus == 0) {
            return LocaleController.getString("LastSeenContacts", R.string.LastSeenContacts);
        } else {
            if (plus != 0 && minus != 0) {
                return LocaleController.formatString("LastSeenContactsMinusPlus", R.string.LastSeenContactsMinusPlus, minus, plus);
            } else if (minus != 0) {
                return LocaleController.formatString("LastSeenContactsMinus", R.string.LastSeenContactsMinus, minus);
            } else {
                return LocaleController.formatString("LastSeenContactsPlus", R.string.LastSeenContactsPlus, plus);
            }
        }
    } else if (type == 1 || plus > 0) {
        if (plus == 0) {
            return LocaleController.getString("LastSeenNobody", R.string.LastSeenNobody);
        } else {
            return LocaleController.formatString("LastSeenNobodyPlus", R.string.LastSeenNobodyPlus, plus);
        }
    }
    return "unknown";
}