use of com.xabber.android.data.extension.capability.ClientInfo in project xabber-android by redsolution.
the class AttentionManager method sendAttention.
public void sendAttention(String account, String user) throws NetworkException {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
if (!(chat instanceof RegularChat)) {
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
}
String to = chat.getTo();
if (Jid.getResource(to) == null || "".equals(Jid.getResource(to))) {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null) {
to = null;
} else {
to = presence.getFrom();
}
}
if (to == null) {
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
}
ClientInfo clientInfo = CapabilitiesManager.getInstance().getClientInfo(account, to);
if (clientInfo == null)
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
if (!clientInfo.getFeatures().contains(Attention.NAMESPACE))
throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
Message message = new Message();
message.setTo(to);
message.setType(Message.Type.headline);
message.addExtension(new Attention());
ConnectionManager.getInstance().sendStanza(account, message);
chat.newAction(null, null, ChatAction.attention_called);
}
use of com.xabber.android.data.extension.capability.ClientInfo in project xabber-android by redsolution.
the class ContactVcardViewerFragment method fillResourceList.
private void fillResourceList(String account, String bareAddress, List<View> resourcesList) {
final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, bareAddress);
for (Presence presence : allPresences) {
String user = presence.getFrom();
ClientInfo clientInfo = CapabilitiesManager.getInstance().getClientInfo(account, user);
String client = "";
if (clientInfo == null) {
CapabilitiesManager.getInstance().request(account, user);
client = getString(R.string.please_wait);
} else if (clientInfo == CapabilitiesManager.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name != null) {
client = name;
}
String type = clientInfo.getType();
if (type != null) {
if (client.isEmpty()) {
client = type;
} else {
client = client + "/" + type;
}
}
}
int priorityValue = presence.getPriority();
String priorityString;
if (priorityValue == Integer.MIN_VALUE) {
priorityString = getString(R.string.account_priority) + ": " + getString(R.string.unknown);
} else {
priorityString = getString(R.string.account_priority) + ": " + priorityValue;
}
String label = "";
if (!client.isEmpty()) {
label = getString(R.string.contact_viewer_client) + ": " + client + ", ";
}
label += priorityString;
String resource = getString(R.string.account_resource) + ": " + Jid.getResource(user);
final StatusMode statusMode = StatusMode.createStatusMode(presence);
String status = presence.getStatus();
if (TextUtils.isEmpty(status)) {
status = getString(statusMode.getStringID());
}
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View resourceView = inflater.inflate(R.layout.contact_info_item, xmppItems, false);
((TextView) resourceView.findViewById(R.id.contact_info_item_secondary)).setText(label);
((TextView) resourceView.findViewById(R.id.contact_info_item_main)).setText(status);
((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_second_line)).setText(resource);
resourceView.findViewById(R.id.contact_info_item_secondary_second_line).setVisibility(View.VISIBLE);
ImageView statusIcon = (ImageView) resourceView.findViewById(R.id.contact_info_right_icon);
statusIcon.setVisibility(View.VISIBLE);
statusIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_status));
statusIcon.setImageLevel(statusMode.getStatusLevel());
resourcesList.add(resourceView);
}
}
use of com.xabber.android.data.extension.capability.ClientInfo in project xabber-android by redsolution.
the class ChatFragment method showResourceChoiceAlert.
public void showResourceChoiceAlert(final AccountJid account, final UserJid user, final boolean restartSession) {
final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
final List<Map<String, String>> items = new ArrayList<>();
for (Presence presence : allPresences) {
Jid fromJid = presence.getFrom();
ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
String client = "";
if (clientInfo == null) {
CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
} else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name != null) {
client = name;
}
String type = clientInfo.getType();
if (type != null) {
if (client.isEmpty()) {
client = type;
} else {
client = client + "/" + type;
}
}
}
Map<String, String> map = new HashMap<>();
if (!client.isEmpty()) {
map.put(ResourceAdapter.KEY_CLIENT, client);
}
Resourcepart resourceOrNull = fromJid.getResourceOrNull();
if (resourceOrNull != null) {
map.put(ResourceAdapter.KEY_RESOURCE, resourceOrNull.toString());
items.add(map);
}
}
final ResourceAdapter adapter = new ResourceAdapter(getActivity(), items);
adapter.setCheckedItem(checkedResource);
if (items.size() > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.otr_select_resource);
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
checkedResource = adapter.getCheckedItem();
}
});
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
checkedResource = adapter.getCheckedItem();
try {
AbstractChat chat = getChat();
if (chat instanceof RegularChat) {
((RegularChat) chat).setOTRresource(Resourcepart.from(items.get(checkedResource).get(ResourceAdapter.KEY_RESOURCE)));
if (restartSession)
restartEncryption(account, user);
else
startEncryption(account, user);
} else {
Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
}
} catch (XmppStringprepException e) {
e.printStackTrace();
Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
}
}
});
builder.setSingleChoiceItems(adapter, checkedResource, null).show();
} else {
Toast.makeText(getActivity(), R.string.otr_select_toast_resources_not_found, Toast.LENGTH_SHORT).show();
}
}
use of com.xabber.android.data.extension.capability.ClientInfo in project xabber-android by redsolution.
the class ContactVcardViewerFragment method fillResourceList.
private void fillResourceList(AccountJid account, Jid bareAddress, List<View> resourcesList) {
final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, bareAddress);
boolean isAccount = account.getFullJid().asBareJid().equals(user.getBareJid());
Resourcepart accountResource = null;
if (isAccount) {
// TODO: probably not the best way to get own resource
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem != null) {
accountResource = accountItem.getConnection().getConfiguration().getResource();
}
}
PresenceManager.sortPresencesByPriority(allPresences);
for (Presence presence : allPresences) {
Jid fromJid = presence.getFrom();
ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
String client = "";
if (clientInfo == null) {
client = getString(R.string.please_wait);
CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
} else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name != null) {
client = name;
}
String type = clientInfo.getType();
if (type != null) {
if (client.isEmpty()) {
client = type;
} else {
client = client + "/" + type;
}
}
}
int priorityValue = presence.getPriority();
String priorityString;
if (priorityValue == Integer.MIN_VALUE) {
priorityString = getString(R.string.account_priority) + ": " + getString(R.string.unknown);
} else {
priorityString = getString(R.string.account_priority) + ": " + priorityValue;
}
if (!client.isEmpty()) {
client = getString(R.string.contact_viewer_client) + ": " + client;
}
Resourcepart resourceOrNull = fromJid.getResourceOrNull();
String resource = getString(R.string.account_resource) + ": " + resourceOrNull;
final StatusMode statusMode = StatusMode.createStatusMode(presence);
String status = presence.getStatus();
if (TextUtils.isEmpty(status)) {
status = getString(statusMode.getStringID());
}
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View resourceView = inflater.inflate(R.layout.item_contact_info, xmppItems, false);
resourceView.findViewById(R.id.contact_info_item_secondary);
((TextView) resourceView.findViewById(R.id.contact_info_item_secondary)).setText(client);
((TextView) resourceView.findViewById(R.id.contact_info_item_main)).setText(status);
((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_second_line)).setText(resource);
resourceView.findViewById(R.id.contact_info_item_secondary_second_line).setVisibility(View.VISIBLE);
((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_third_line)).setText(priorityString);
resourceView.findViewById(R.id.contact_info_item_secondary_third_line).setVisibility(View.VISIBLE);
if (isAccount && resourceOrNull != null && resourceOrNull.equals(accountResource)) {
TextView thisDeviceIndicatorTextView = (TextView) resourceView.findViewById(R.id.contact_info_item_secondary_forth_line);
thisDeviceIndicatorTextView.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountSendButtonColor(account));
thisDeviceIndicatorTextView.setText(R.string.contact_viewer_this_device);
thisDeviceIndicatorTextView.setVisibility(View.VISIBLE);
}
ImageView statusIcon = (ImageView) resourceView.findViewById(R.id.contact_info_right_icon);
statusIcon.setVisibility(View.VISIBLE);
statusIcon.setImageResource(R.drawable.ic_status);
statusIcon.setImageLevel(statusMode.getStatusLevel());
resourcesList.add(resourceView);
}
}
use of com.xabber.android.data.extension.capability.ClientInfo in project xabber-android by redsolution.
the class AbstractContact method getClientSoftware.
public ClientSoftware getClientSoftware() {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null || !presence.isAvailable()) {
return ClientSoftware.unknown;
}
ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(presence.getFrom());
if (clientInfo == null) {
return ClientSoftware.unknown;
} else {
return clientInfo.getClientSoftware();
}
}
Aggregations