Java Code Examples for org.telegram.messenger.ContactsController#formatName()

The following examples show how to use org.telegram.messenger.ContactsController#formatName() . 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: ChannelAdminLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private String getMessageContent(MessageObject messageObject, int previousUid, boolean name) {
    String str = "";
    if (name) {
        if (previousUid != messageObject.messageOwner.from_id) {
            if (messageObject.messageOwner.from_id > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id);
                if (user != null) {
                    str = ContactsController.formatName(user.first_name, user.last_name) + ":\n";
                }
            } else if (messageObject.messageOwner.from_id < 0) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-messageObject.messageOwner.from_id);
                if (chat != null) {
                    str = chat.title + ":\n";
                }
            }
        }
    }
    if (messageObject.type == 0 && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else {
        str += messageObject.messageText;
    }
    return str;
}
 
Example 2
Source File: ChannelAdminLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private String getMessageContent(MessageObject messageObject, int previousUid, boolean name) {
    String str = "";
    if (name) {
        if (previousUid != messageObject.messageOwner.from_id) {
            if (messageObject.messageOwner.from_id > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id);
                if (user != null) {
                    str = ContactsController.formatName(user.first_name, user.last_name) + ":\n";
                }
            } else if (messageObject.messageOwner.from_id < 0) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-messageObject.messageOwner.from_id);
                if (chat != null) {
                    str = chat.title + ":\n";
                }
            }
        }
    }
    if (messageObject.type == 0 && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else {
        str += messageObject.messageText;
    }
    return str;
}
 
Example 3
Source File: ChannelAdminLogActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private String getMessageContent(MessageObject messageObject, int previousUid, boolean name) {
    String str = "";
    if (name) {
        if (previousUid != messageObject.messageOwner.from_id) {
            if (messageObject.messageOwner.from_id > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id);
                if (user != null) {
                    str = ContactsController.formatName(user.first_name, user.last_name) + ":\n";
                }
            } else if (messageObject.messageOwner.from_id < 0) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-messageObject.messageOwner.from_id);
                if (chat != null) {
                    str = chat.title + ":\n";
                }
            }
        }
    }
    if (messageObject.type == 0 && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else {
        str += messageObject.messageText;
    }
    return str;
}
 
Example 4
Source File: ChannelAdminLogActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private String getMessageContent(MessageObject messageObject, int previousUid, boolean name) {
    String str = "";
    if (name) {
        if (previousUid != messageObject.messageOwner.from_id) {
            if (messageObject.messageOwner.from_id > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id);
                if (user != null) {
                    str = ContactsController.formatName(user.first_name, user.last_name) + ":\n";
                }
            } else if (messageObject.messageOwner.from_id < 0) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-messageObject.messageOwner.from_id);
                if (chat != null) {
                    str = chat.title + ":\n";
                }
            }
        }
    }
    if (messageObject.type == 0 && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.message != null) {
        str += messageObject.messageOwner.message;
    } else {
        str += messageObject.messageText;
    }
    return str;
}
 
Example 5
Source File: DialogsSearchAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
    HintDialogCell cell = (HintDialogCell) holder.itemView;

    TLRPC.TL_topPeer peer = DataQuery.getInstance(currentAccount).hints.get(position);
    TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
    TLRPC.Chat chat = null;
    TLRPC.User user = null;
    int did = 0;
    if (peer.peer.user_id != 0)
    {
        did = peer.peer.user_id;
        user = MessagesController.getInstance(currentAccount).getUser(peer.peer.user_id);
    }
    else if (peer.peer.channel_id != 0)
    {
        did = -peer.peer.channel_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.channel_id);
    }
    else if (peer.peer.chat_id != 0)
    {
        did = -peer.peer.chat_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.chat_id);
    }
    cell.setTag(did);
    String name = "";
    if (user != null)
    {
        name = ContactsController.formatName(user.first_name, user.last_name);
    }
    else if (chat != null)
    {
        name = chat.title;
    }
    cell.setDialog(did, true, name);
}
 
Example 6
Source File: DialogsSearchAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
    HintDialogCell cell = (HintDialogCell) holder.itemView;

    TLRPC.TL_topPeer peer = DataQuery.getInstance(currentAccount).hints.get(position);
    TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
    TLRPC.Chat chat = null;
    TLRPC.User user = null;
    int did = 0;
    if (peer.peer.user_id != 0)
    {
        did = peer.peer.user_id;
        user = MessagesController.getInstance(currentAccount).getUser(peer.peer.user_id);
    }
    else if (peer.peer.channel_id != 0)
    {
        did = -peer.peer.channel_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.channel_id);
    }
    else if (peer.peer.chat_id != 0)
    {
        did = -peer.peer.chat_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.chat_id);
    }
    cell.setTag(did);
    String name = "";
    if (user != null)
    {
        name = ContactsController.formatName(user.first_name, user.last_name);
    }
    else if (chat != null)
    {
        name = chat.title;
    }
    cell.setDialog(did, true, name);
}
 
Example 7
Source File: PrivacyControlActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public MessageCell(Context context) {
    super(context);

    setWillNotDraw(false);
    setClipToPadding(false);

    shadowDrawable = Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow);
    setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11));

    int date = (int) (System.currentTimeMillis() / 1000) - 60 * 60;

    TLRPC.User currentUser = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());

    TLRPC.Message message = new TLRPC.TL_message();
    message.message = LocaleController.getString("PrivacyForwardsMessageLine", R.string.PrivacyForwardsMessageLine);
    message.date = date + 60;
    message.dialog_id = 1;
    message.flags = 257 + TLRPC.MESSAGE_FLAG_FWD;
    message.from_id = 0;
    message.id = 1;
    message.fwd_from = new TLRPC.TL_messageFwdHeader();
    message.fwd_from.from_name = ContactsController.formatName(currentUser.first_name, currentUser.last_name);
    message.media = new TLRPC.TL_messageMediaEmpty();
    message.out = false;
    message.to_id = new TLRPC.TL_peerUser();
    message.to_id.user_id = UserConfig.getInstance(currentAccount).getClientUserId();
    messageObject = new MessageObject(currentAccount, message, true);
    messageObject.eventId = 1;
    messageObject.resetLayout();

    cell = new ChatMessageCell(context);
    cell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() {

    });
    cell.isChat = false;
    cell.setFullyDraw(true);
    cell.setMessageObject(messageObject, null, false, false);
    addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    hintView = new HintView(context, 1, true);
    addView(hintView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
}
 
Example 8
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog alertDialog = builder.create();
    fragment.showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
 
Example 9
Source File: PrivacyControlActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public MessageCell(Context context) {
    super(context);

    setWillNotDraw(false);
    setClipToPadding(false);

    shadowDrawable = Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow);
    setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11));

    int date = (int) (System.currentTimeMillis() / 1000) - 60 * 60;

    TLRPC.User currentUser = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());

    TLRPC.Message message = new TLRPC.TL_message();
    message.message = LocaleController.getString("PrivacyForwardsMessageLine", R.string.PrivacyForwardsMessageLine);
    message.date = date + 60;
    message.dialog_id = 1;
    message.flags = 257 + TLRPC.MESSAGE_FLAG_FWD;
    message.from_id = 0;
    message.id = 1;
    message.fwd_from = new TLRPC.TL_messageFwdHeader();
    message.fwd_from.from_name = ContactsController.formatName(currentUser.first_name, currentUser.last_name);
    message.media = new TLRPC.TL_messageMediaEmpty();
    message.out = false;
    message.to_id = new TLRPC.TL_peerUser();
    message.to_id.user_id = UserConfig.getInstance(currentAccount).getClientUserId();
    messageObject = new MessageObject(currentAccount, message, true);
    messageObject.eventId = 1;
    messageObject.resetLayout();

    cell = new ChatMessageCell(context);
    cell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() {

    });
    cell.isChat = false;
    cell.setFullyDraw(true);
    cell.setMessageObject(messageObject, null, false, false);
    addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    hintView = new HintView(context, 1, true);
    addView(hintView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
}
 
Example 10
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog alertDialog = builder.create();
    fragment.showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}