use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class QuestionViewer method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing()) {
return;
}
Intent intent = getIntent();
account = QuestionViewer.getAccount(intent);
user = QuestionViewer.getUser(intent);
if (AccountManager.getInstance().getAccount(account) == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
if (intent.getBooleanExtra(EXTRA_FIELD_CANCEL, false)) {
try {
OTRManager.getInstance().abortSmp(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
finish();
return;
}
showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true);
answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
if (showQuestion) {
setContentView(R.layout.question_viewer);
questionView = (EditText) findViewById(R.id.question);
questionView.setEnabled(!answerRequest);
if (answerRequest) {
questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
} else {
findViewById(R.id.cancel).setVisibility(View.GONE);
}
} else {
setContentView(R.layout.secret_viewer);
}
findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView();
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class SSNManager method sendFeature.
private void sendFeature(String account, String user, String session, Feature feature) {
Message message = new Message(user, Message.Type.normal);
message.setThread(session);
message.addExtension(feature);
try {
ConnectionManager.getInstance().sendStanza(account, message);
} catch (NetworkException e) {
}
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class TimeManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
String account = ((AccountItem) connection).getAccount();
if (!(packet instanceof Time))
return;
Time time = (Time) packet;
if (time.getType() == Type.get) {
Time result = new Time();
result.setType(Type.result);
result.setPacketID(time.getPacketID());
result.setFrom(time.getTo());
result.setTo(time.getFrom());
Calendar calendar = Calendar.getInstance();
result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
result.setUtc(calendar.getTime());
try {
ConnectionManager.getInstance().sendStanza(account, result);
} catch (NetworkException e) {
}
}
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class VCardManager method onVCardReceived.
private void onVCardReceived(final String account, final String bareAddress, final VCard vCard) {
final StructuredName name;
if (vCard.getType() == Type.error) {
onVCardFailed(account, bareAddress);
if (names.containsKey(bareAddress)) {
return;
}
name = EMPTY_STRUCTURED_NAME;
} else {
for (OnVCardListener listener : Application.getInstance().getUIListeners(OnVCardListener.class)) {
listener.onVCardReceived(account, bareAddress, vCard);
}
String hash = vCard.getAvatarHash();
AvatarManager.getInstance().onAvatarReceived(bareAddress, hash, vCard.getAvatar());
name = new StructuredName(vCard.getNickName(), vCard.getField(VCardProperty.FN.name()), vCard.getFirstName(), vCard.getMiddleName(), vCard.getLastName());
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
try {
if (Jid.getBareAddress(account).equals(bareAddress)) {
PresenceManager.getInstance().resendPresence(account);
}
} catch (NetworkException e) {
e.printStackTrace();
}
}
});
}
names.put(bareAddress, name);
for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) {
if (rosterContact.getUser().equals(bareAddress)) {
for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
listener.onContactStructuredInfoChanged(rosterContact, name);
}
}
}
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
VCardTable.getInstance().write(bareAddress, name);
}
});
if (vCard.getFrom() == null) {
// account it self
AccountManager.getInstance().onAccountChanged(account);
} else {
RosterManager.getInstance().onContactChanged(account, bareAddress);
}
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class VCardManager method saveVCard.
public void saveVCard(final String account, final VCard vCard) {
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null) {
onVCardSaveFailed(account);
return;
}
final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(xmppConnection);
final Thread thread = new Thread("Save vCard for account " + account) {
@Override
public void run() {
boolean isSuccess = true;
xmppConnection.setPacketReplyTimeout(120000);
vCardSaveRequests.add(account);
try {
vCardManager.saveVCard(vCard);
String avatarHash = vCard.getAvatarHash();
if (avatarHash == null) {
avatarHash = AvatarManager.EMPTY_HASH;
}
PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException e) {
LogManager.w(this, "Error saving vCard: " + e.getMessage());
isSuccess = false;
}
vCardSaveRequests.remove(account);
xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
final boolean finalIsSuccess = isSuccess;
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalIsSuccess) {
onVCardSaveSuccess(account);
} else {
onVCardSaveFailed(account);
}
}
});
}
};
thread.start();
}
Aggregations