use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ContactListActivity method onResume.
@Override
protected void onResume() {
super.onResume();
if (!AccountManager.getInstance().checkAccounts() && XabberAccountManager.getInstance().getAccount() == null) {
startActivity(TutorialActivity.createIntent(this));
finish();
return;
}
rebuildAccountToggle();
setStatusBarColor();
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
if (action != null) {
switch(action) {
case ContactListActivity.ACTION_ROOM_INVITE:
case Intent.ACTION_SEND:
case Intent.ACTION_SEND_MULTIPLE:
case ChatActivity.ACTION_FORWARD:
case Intent.ACTION_CREATE_SHORTCUT:
if (Intent.ACTION_SEND.equals(action)) {
sendText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
}
Toast.makeText(this, getString(R.string.select_contact), Toast.LENGTH_LONG).show();
break;
case Intent.ACTION_VIEW:
{
action = null;
Uri data = getIntent().getData();
if (data != null && "xmpp".equals(data.getScheme())) {
XMPPUri xmppUri;
try {
xmppUri = XMPPUri.parse(data);
} catch (IllegalArgumentException e) {
xmppUri = null;
}
if (xmppUri != null && "message".equals(xmppUri.getQueryType())) {
ArrayList<String> texts = xmppUri.getValues("body");
String text = null;
if (texts != null && !texts.isEmpty()) {
text = texts.get(0);
}
UserJid user = null;
try {
user = UserJid.from(xmppUri.getPath());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
if (user != null) {
openChat(user, text);
}
}
}
break;
}
case Intent.ACTION_SENDTO:
{
action = null;
Uri data = getIntent().getData();
if (data != null) {
String path = data.getPath();
if (path != null && path.startsWith("/")) {
try {
UserJid user = UserJid.from(path.substring(1));
openChat(user, null);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
break;
}
case ContactListActivity.ACTION_MUC_PRIVATE_CHAT_INVITE:
action = null;
showMucPrivateChatDialog();
break;
case ContactListActivity.ACTION_CONTACT_SUBSCRIPTION:
action = null;
showContactSubscriptionDialog();
break;
case ContactListActivity.ACTION_INCOMING_MUC_INVITE:
action = null;
showMucInviteDialog();
break;
}
}
if (Application.getInstance().doNotify()) {
if (!SettingsManager.isTranslationSuggested()) {
Locale currentLocale = getResources().getConfiguration().locale;
if (!currentLocale.getLanguage().equals("en") && !getResources().getBoolean(R.bool.is_translated)) {
new TranslationDialog().show(getFragmentManager(), "TRANSLATION_DIALOG");
}
}
}
showPassDialogs();
// showcase
if (!SettingsManager.contactShowcaseSuggested()) {
showShowcase(true);
}
// update crowdfunding info
CrowdfundingManager.getInstance().onLoad();
// remove all message notifications
MessageNotificationManager.getInstance().removeAllMessageNotifications();
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ContactListActivity method showMucPrivateChatDialog.
private void showMucPrivateChatDialog() {
Intent intent = getIntent();
AccountJid account = getRoomInviteAccount(intent);
UserJid user = getRoomInviteUser(intent);
if (account != null && user != null) {
MucPrivateChatInvitationDialog.newInstance(account, user).show(getFragmentManager(), MucPrivateChatInvitationDialog.class.getName());
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class OccupantListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(R.layout.item_occupant, parent, false);
} else {
view = convertView;
}
final Occupant occupant = (Occupant) getItem(position);
final ImageView avatarView = (ImageView) view.findViewById(R.id.ivAvatar);
avatarView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
try {
intent = ContactActivity.createIntent(activity, account, UserJid.from(JidCreate.domainFullFrom(room.asDomainBareJid(), occupant.getNickname())));
activity.startActivity(intent);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
});
final ImageView affilationView = (ImageView) view.findViewById(R.id.affilation);
final TextView nameView = (TextView) view.findViewById(R.id.name);
final TextView statusTextView = (TextView) view.findViewById(R.id.status);
final ImageView statusModeView = (ImageView) view.findViewById(R.id.ivStatus);
// avatar
Resourcepart nickname = occupant.getNickname();
if (nickname != null && MUCManager.getInstance().getNickname(account, room).equals(nickname)) {
avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
String nick = occupant.getJid().getResourceOrEmpty().toString();
UserJid userJid = null;
try {
userJid = UserJid.from(occupant.getJid());
avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
avatarView.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
}
}
affilationView.setImageLevel(occupant.getAffiliation().ordinal());
nameView.setText(occupant.getNickname());
String status;
if (occupant.getRole() == MUCRole.moderator)
status = activity.getString(R.string.muc_role_moderator);
else if (occupant.getRole() == MUCRole.participant)
status = activity.getString(R.string.muc_role_participant);
else
status = activity.getString(R.string.muc_role_visitor);
String statusText = occupant.getStatusText();
if (statusText != null && !statusText.isEmpty())
status = status + " • " + statusText;
statusTextView.setText(status);
statusModeView.setImageLevel(occupant.getStatusMode().getStatusLevel());
return view;
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ContactAddFragment method addContact.
@Override
public void addContact() {
final AccountJid account = (AccountJid) accountView.getSelectedItem();
if (account == null || getAccount() == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
return;
}
String contactString = userView.getText().toString();
contactString = contactString.trim();
if (contactString.contains(" ")) {
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (TextUtils.isEmpty(contactString)) {
userView.setError(getString(R.string.EMPTY_USER_NAME));
return;
}
final UserJid user;
try {
EntityBareJid entityFullJid = JidCreate.entityBareFrom(contactString);
user = UserJid.from(entityFullJid);
} catch (XmppStringprepException | UserJid.UserJidCreateException e) {
e.printStackTrace();
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (listenerActivity != null)
listenerActivity.showProgress(true);
final String name = nameView.getText().toString();
final ArrayList<String> groups = getSelected();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
try {
RosterManager.getInstance().createContact(account, user, name, groups);
PresenceManager.getInstance().requestSubscription(account, user);
} catch (SmackException.NotLoggedInException | SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
stopAddContactProcess(false);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
stopAddContactProcess(false);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
stopAddContactProcess(false);
} catch (NetworkException e) {
Application.getInstance().onError(e);
stopAddContactProcess(false);
} catch (InterruptedException e) {
LogManager.exception(this, e);
stopAddContactProcess(false);
}
stopAddContactProcess(true);
}
});
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ForwardedVH method bind.
public void bind(MessageItem messageItem, MessagesAdapter.MessageExtraData extraData, String accountJid) {
super.bind(messageItem, extraData);
// hide STATUS ICONS
statusIcon.setVisibility(View.GONE);
// setup MESSAGE AUTHOR
UserJid jid = null;
try {
jid = UserJid.from(messageItem.getOriginalFrom());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
}
String author = RosterManager.getDisplayAuthorName(messageItem);
if (extraData.getGroupchatUser() != null)
author = extraData.getGroupchatUser().getNickname();
if (author != null && !author.isEmpty()) {
messageHeader.setText(author);
messageHeader.setTextColor(ColorManager.changeColor(ColorGenerator.MATERIAL.getColor(author), 0.8f));
messageHeader.setVisibility(View.VISIBLE);
} else
messageHeader.setVisibility(View.GONE);
// setup FORWARDED
Context context = extraData.getContext();
boolean haveForwarded = messageItem.haveForwardedMessages();
if (haveForwarded) {
forwardLayout.setVisibility(View.VISIBLE);
tvForwardedCount.setText(String.format(extraData.getContext().getResources().getString(R.string.forwarded_messages_count), messageItem.getForwardedIds().size()));
tvForwardedCount.setPaintFlags(tvForwardedCount.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
forwardLayout.setBackgroundColor(ColorManager.getColorWithAlpha(R.color.forwarded_background_color, 0.2f));
forwardLeftBorder.setBackgroundColor(extraData.getAccountMainColor());
} else
forwardLayout.setVisibility(View.GONE);
// setup BACKGROUND
Drawable balloonDrawable = context.getResources().getDrawable(haveForwarded ? R.drawable.fwd : R.drawable.msg);
Drawable shadowDrawable = context.getResources().getDrawable(haveForwarded ? R.drawable.fwd_shadow : R.drawable.msg_shadow);
shadowDrawable.setColorFilter(context.getResources().getColor(R.color.black), PorterDuff.Mode.MULTIPLY);
messageBalloon.setBackgroundDrawable(balloonDrawable);
messageShadow.setBackgroundDrawable(shadowDrawable);
// setup BACKGROUND COLOR
if (jid != null && !accountJid.equals(jid.getBareJid().toString()))
setUpMessageBalloonBackground(messageBalloon, extraData.getColorStateList());
else {
TypedValue typedValue = new TypedValue();
extraData.getContext().getTheme().resolveAttribute(R.attr.message_background, typedValue, true);
setUpMessageBalloonBackground(messageBalloon, extraData.getContext().getResources().getColorStateList(typedValue.resourceId));
}
}
Aggregations