use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class NavigationDrawerAccountAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
AccountManager accountManager = AccountManager.getInstance();
if (convertView == null) {
view = getActivity().getLayoutInflater().inflate(R.layout.contact_list_drawer_account_item, parent, false);
} else {
view = convertView;
}
AccountJid account = getItem(position);
((ImageView) view.findViewById(R.id.color)).setImageDrawable(new ColorDrawable((ColorManager.getInstance().getAccountPainter().getAccountMainColor(account))));
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
TextView accountName = (TextView) view.findViewById(R.id.name);
try {
accountName.setText(RosterManager.getInstance().getBestContact(account, UserJid.from(accountManager.getVerboseName(account))).getName());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
accountName.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountTextColor(account));
((TextView) view.findViewById(R.id.account_jid)).setText(accountManager.getVerboseName(account));
AccountItem accountItem = accountManager.getAccount(account);
ConnectionState state;
if (accountItem == null) {
state = ConnectionState.offline;
} else {
state = accountItem.getState();
}
((TextView) view.findViewById(R.id.status)).setText(getActivity().getString(state.getStringId()));
return view;
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class ContactListGroupUtils method addContact.
/**
* Adds contact to specified group.
*/
public static void addContact(AbstractContact abstractContact, String group, boolean online, Map<AccountJid, AccountConfiguration> accounts, Map<String, GroupConfiguration> groups, List<AbstractContact> contacts, boolean showAccounts, boolean showGroups) {
if (showAccounts) {
final AccountJid account = abstractContact.getAccount();
final AccountConfiguration accountConfiguration;
accountConfiguration = accounts.get(account);
if (accountConfiguration == null) {
return;
}
if (showGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(accountConfiguration, group);
// if (accountConfiguration.isExpanded()) {
// groupConfiguration.setNotEmpty();
// if (groupConfiguration.isExpanded()) {
// groupConfiguration.addAbstractContact(abstractContact);
// }
// }
groupConfiguration.setNotEmpty();
groupConfiguration.addAbstractContact(abstractContact);
groupConfiguration.increment(online);
} else {
// if (accountConfiguration.isExpanded()) {
// accountConfiguration.addAbstractContact(abstractContact);
// }
accountConfiguration.addAbstractContact(abstractContact);
}
accountConfiguration.increment(online);
} else {
if (showGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(groups, group);
groupConfiguration.setNotEmpty();
// if (groupConfiguration.isExpanded()) {
// groupConfiguration.addAbstractContact(abstractContact);
// }
groupConfiguration.addAbstractContact(abstractContact);
groupConfiguration.increment(online);
} else {
contacts.add(abstractContact);
}
}
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class AccountAddFragment method addAccount.
public void addAccount() {
if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
OrbotInstallerDialog.newInstance().show(getFragmentManager(), OrbotInstallerDialog.class.getName());
return;
}
if (createAccountCheckBox.isChecked() && !passwordView.getText().toString().contentEquals(passwordConfirmEditText.getText().toString())) {
Toast.makeText(getActivity(), getString(R.string.CONFIRM_PASSWORD), Toast.LENGTH_LONG).show();
return;
}
AccountJid account;
try {
account = AccountManager.getInstance().addAccount(userView.getText().toString().trim(), passwordView.getText().toString(), "", false, storePasswordView.isChecked(), chkSync.isChecked(), useOrbotView.isChecked(), createAccountCheckBox.isChecked(), true);
} catch (NetworkException e) {
Application.getInstance().onError(e);
return;
}
// update remote settings
if (chkSync.isChecked())
XabberAccountManager.getInstance().updateSettingsWithSaveLastAccount(account);
getActivity().setResult(Activity.RESULT_OK, AccountAddActivity.createAuthenticatorResult(account));
startActivity(AccountActivity.createIntent(getActivity(), account));
getActivity().finish();
}
use of com.xabber.android.data.entity.AccountJid 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 {
RegularChat chat = (RegularChat) getChat();
if (chat != null) {
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.entity.AccountJid in project xabber-android by redsolution.
the class AttentionManager method sendAttention.
public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
if (!(chat instanceof RegularChat)) {
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
}
Jid to = chat.getTo();
if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
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);
}
if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.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 AttentionExtension());
StanzaSender.sendStanza(account, message);
chat.newAction(null, null, ChatAction.attention_called);
}
Aggregations