2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2014-05-01 20:33:49 +00:00
|
|
|
import org.openintents.openpgp.OpenPgpError;
|
|
|
|
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.ui.EditAccount.EditAccountListener;
|
2014-03-07 13:24:33 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnTLSExceptionReceived;
|
2014-03-12 21:31:50 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-01-28 22:15:30 +00:00
|
|
|
import android.app.Activity;
|
2014-02-04 20:44:16 +00:00
|
|
|
import android.app.AlertDialog;
|
2014-05-01 20:33:49 +00:00
|
|
|
import android.app.PendingIntent;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.content.Context;
|
2014-02-04 21:26:46 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface.OnClickListener;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.content.Intent;
|
2014-02-27 23:22:56 +00:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.os.Bundle;
|
2014-03-12 21:31:50 +00:00
|
|
|
import android.os.SystemClock;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.util.Log;
|
2014-02-04 20:44:16 +00:00
|
|
|
import android.view.ActionMode;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
2014-02-04 20:44:16 +00:00
|
|
|
import android.view.MenuInflater;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
2014-02-04 20:44:16 +00:00
|
|
|
import android.widget.AdapterView.OnItemLongClickListener;
|
2014-01-28 18:21:54 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2014-03-06 02:30:03 +00:00
|
|
|
public class ManageAccountActivity extends XmppActivity {
|
2014-02-27 23:22:56 +00:00
|
|
|
|
2014-02-04 20:44:16 +00:00
|
|
|
protected boolean isActionMode = false;
|
|
|
|
protected ActionMode actionMode;
|
|
|
|
protected Account selectedAccountForActionMode = null;
|
2014-03-07 13:24:33 +00:00
|
|
|
protected ManageAccountActivity activity = this;
|
2014-02-04 20:44:16 +00:00
|
|
|
|
2014-04-01 21:16:19 +00:00
|
|
|
protected boolean firstrun = true;
|
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
protected List<Account> accountList = new ArrayList<Account>();
|
|
|
|
protected ListView accountListView;
|
|
|
|
protected ArrayAdapter<Account> accountListViewAdapter;
|
2014-02-04 14:09:50 +00:00
|
|
|
protected OnAccountListChangedListener accountChanged = new OnAccountListChangedListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAccountListChangedListener() {
|
|
|
|
accountList.clear();
|
|
|
|
accountList.addAll(xmppConnectionService.getAccounts());
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
accountListViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2014-03-07 13:24:33 +00:00
|
|
|
|
|
|
|
protected OnTLSExceptionReceived tlsExceptionReceived = new OnTLSExceptionReceived() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTLSExceptionReceived(final String fingerprint, final Account account) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
2014-05-15 23:13:07 +00:00
|
|
|
builder.setTitle(getString(R.string.account_status_error));
|
2014-03-07 13:24:33 +00:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
|
|
View view = (View) getLayoutInflater().inflate(R.layout.cert_warning, null);
|
|
|
|
TextView sha = (TextView) view.findViewById(R.id.sha);
|
|
|
|
TextView hint = (TextView) view.findViewById(R.id.hint);
|
|
|
|
StringBuilder humanReadableSha = new StringBuilder();
|
|
|
|
humanReadableSha.append(fingerprint);
|
2014-03-07 19:22:26 +00:00
|
|
|
for(int i = 2; i < 59; i += 3) {
|
|
|
|
if ((i==14)||(i==29)||(i==44)) {
|
|
|
|
humanReadableSha.insert(i, "\n");
|
|
|
|
} else {
|
|
|
|
humanReadableSha.insert(i, ":");
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:24:33 +00:00
|
|
|
}
|
2014-03-07 19:22:26 +00:00
|
|
|
hint.setText(getString(R.string.untrusted_cert_hint,account.getServer()));
|
2014-03-07 13:24:33 +00:00
|
|
|
sha.setText(humanReadableSha.toString());
|
|
|
|
builder.setView(view);
|
2014-05-15 23:13:07 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.certif_no_trust), null);
|
|
|
|
builder.setPositiveButton(getString(R.string.certif_trust), new OnClickListener() {
|
2014-03-07 13:24:33 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
account.setSSLCertFingerprint(fingerprint);
|
|
|
|
activity.xmppConnectionService.updateAccount(account);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
setContentView(R.layout.manage_accounts);
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
accountListView = (ListView) findViewById(R.id.account_list);
|
2014-02-04 14:09:50 +00:00
|
|
|
accountListViewAdapter = new ArrayAdapter<Account>(
|
|
|
|
getApplicationContext(), R.layout.account_row, this.accountList) {
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
2014-02-04 14:09:50 +00:00
|
|
|
Account account = getItem(position);
|
2014-01-28 18:21:54 +00:00
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = (View) inflater.inflate(R.layout.account_row, null);
|
|
|
|
}
|
2014-02-04 14:09:50 +00:00
|
|
|
((TextView) view.findViewById(R.id.account_jid))
|
|
|
|
.setText(account.getJid());
|
|
|
|
TextView statusView = (TextView) view
|
|
|
|
.findViewById(R.id.account_status);
|
|
|
|
switch (account.getStatus()) {
|
2014-02-04 20:44:16 +00:00
|
|
|
case Account.STATUS_DISABLED:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_disabled));
|
2014-02-04 20:44:16 +00:00
|
|
|
statusView.setTextColor(0xFF1da9da);
|
|
|
|
break;
|
2014-02-04 14:09:50 +00:00
|
|
|
case Account.STATUS_ONLINE:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_online));
|
2014-02-04 14:09:50 +00:00
|
|
|
statusView.setTextColor(0xFF83b600);
|
|
|
|
break;
|
2014-03-06 02:57:29 +00:00
|
|
|
case Account.STATUS_CONNECTING:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_connecting));
|
2014-03-06 02:57:29 +00:00
|
|
|
statusView.setTextColor(0xFF1da9da);
|
|
|
|
break;
|
2014-02-04 14:09:50 +00:00
|
|
|
case Account.STATUS_OFFLINE:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_offline));
|
2014-02-04 14:09:50 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
|
|
|
case Account.STATUS_UNAUTHORIZED:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_unauthorized));
|
2014-02-04 14:09:50 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
|
|
|
case Account.STATUS_SERVER_NOT_FOUND:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_not_found));
|
2014-02-04 14:09:50 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
2014-03-06 02:57:29 +00:00
|
|
|
case Account.STATUS_NO_INTERNET:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_no_internet));
|
2014-03-06 02:57:29 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
2014-03-06 14:11:56 +00:00
|
|
|
case Account.STATUS_SERVER_REQUIRES_TLS:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_requires_tls));
|
2014-03-06 14:11:56 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
2014-03-07 13:24:33 +00:00
|
|
|
case Account.STATUS_TLS_ERROR:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_error));
|
2014-03-07 13:24:33 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
2014-03-13 16:29:22 +00:00
|
|
|
case Account.STATUS_REGISTRATION_FAILED:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_regis_fail));
|
2014-03-13 16:29:22 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
|
|
|
case Account.STATUS_REGISTRATION_CONFLICT:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_regis_conflict));
|
2014-03-13 16:29:22 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
|
|
|
case Account.STATUS_REGISTRATION_SUCCESSFULL:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_regis_success));
|
2014-03-13 16:29:22 +00:00
|
|
|
statusView.setTextColor(0xFF83b600);
|
|
|
|
break;
|
2014-03-14 17:56:52 +00:00
|
|
|
case Account.STATUS_REGISTRATION_NOT_SUPPORTED:
|
2014-05-15 23:13:07 +00:00
|
|
|
statusView.setText(getString(R.string.account_status_regis_not_sup));
|
2014-03-14 17:56:52 +00:00
|
|
|
statusView.setTextColor(0xFFe92727);
|
|
|
|
break;
|
2014-02-04 14:09:50 +00:00
|
|
|
default:
|
2014-03-13 16:29:22 +00:00
|
|
|
statusView.setText("");
|
2014-02-04 14:09:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
};
|
2014-03-06 02:30:03 +00:00
|
|
|
final XmppActivity activity = this;
|
2014-01-28 18:21:54 +00:00
|
|
|
accountListView.setAdapter(this.accountListViewAdapter);
|
|
|
|
accountListView.setOnItemClickListener(new OnItemClickListener() {
|
|
|
|
|
|
|
|
@Override
|
2014-02-04 14:09:50 +00:00
|
|
|
public void onItemClick(AdapterView<?> arg0, View view,
|
|
|
|
int position, long arg3) {
|
2014-02-04 20:44:16 +00:00
|
|
|
if (!isActionMode) {
|
2014-03-07 13:24:33 +00:00
|
|
|
Account account = accountList.get(position);
|
2014-03-13 16:29:22 +00:00
|
|
|
if ((account.getStatus() == Account.STATUS_OFFLINE)||(account.getStatus() == Account.STATUS_TLS_ERROR)) {
|
2014-03-12 21:31:50 +00:00
|
|
|
activity.xmppConnectionService.reconnectAccount(accountList.get(position),true);
|
2014-03-07 13:24:33 +00:00
|
|
|
} else if (account.getStatus() == Account.STATUS_ONLINE) {
|
2014-03-15 14:13:35 +00:00
|
|
|
activity.startActivity(new Intent(activity.getApplicationContext(),ContactsActivity.class));
|
2014-04-01 21:16:19 +00:00
|
|
|
} else if (account.getStatus() != Account.STATUS_DISABLED) {
|
2014-03-13 03:21:59 +00:00
|
|
|
editAccount(account);
|
2014-03-07 13:24:33 +00:00
|
|
|
}
|
2014-02-04 20:44:16 +00:00
|
|
|
} else {
|
|
|
|
selectedAccountForActionMode = accountList.get(position);
|
|
|
|
actionMode.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
accountListView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
2014-01-28 18:21:54 +00:00
|
|
|
|
2014-02-04 20:44:16 +00:00
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View view,
|
|
|
|
int position, long arg3) {
|
|
|
|
if (!isActionMode) {
|
|
|
|
accountListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
|
|
|
accountListView.setItemChecked(position,true);
|
|
|
|
selectedAccountForActionMode = accountList.get(position);
|
2014-03-06 02:30:03 +00:00
|
|
|
actionMode = activity.startActionMode((new ActionMode.Callback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
if (selectedAccountForActionMode.isOptionSet(Account.OPTION_DISABLED)) {
|
2014-03-07 13:24:33 +00:00
|
|
|
menu.findItem(R.id.mgmt_account_enable).setVisible(true);
|
|
|
|
menu.findItem(R.id.mgmt_account_disable).setVisible(false);
|
2014-03-06 02:30:03 +00:00
|
|
|
} else {
|
2014-03-07 13:24:33 +00:00
|
|
|
menu.findItem(R.id.mgmt_account_disable).setVisible(true);
|
|
|
|
menu.findItem(R.id.mgmt_account_enable).setVisible(false);
|
2014-03-06 02:30:03 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
MenuInflater inflater = mode.getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.manageaccounts_context, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
|
2014-03-07 13:24:33 +00:00
|
|
|
if (item.getItemId()==R.id.mgmt_account_edit) {
|
2014-03-13 03:21:59 +00:00
|
|
|
editAccount(selectedAccountForActionMode);
|
2014-03-07 13:24:33 +00:00
|
|
|
} else if (item.getItemId()==R.id.mgmt_account_disable) {
|
2014-03-06 02:30:03 +00:00
|
|
|
selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, true);
|
|
|
|
xmppConnectionService.updateAccount(selectedAccountForActionMode);
|
|
|
|
mode.finish();
|
2014-03-07 13:24:33 +00:00
|
|
|
} else if (item.getItemId()==R.id.mgmt_account_enable) {
|
2014-03-06 02:30:03 +00:00
|
|
|
selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
xmppConnectionService.updateAccount(selectedAccountForActionMode);
|
|
|
|
mode.finish();
|
2014-03-07 13:24:33 +00:00
|
|
|
} else if (item.getItemId()==R.id.mgmt_account_delete) {
|
2014-03-06 02:30:03 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
2014-05-23 22:17:42 +00:00
|
|
|
builder.setTitle(getString(R.string.mgmt_account_are_you_sure));
|
2014-03-06 02:30:03 +00:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
2014-05-23 22:17:42 +00:00
|
|
|
builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text));
|
|
|
|
builder.setPositiveButton(getString(R.string.delete), new OnClickListener() {
|
2014-03-06 02:30:03 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
xmppConnectionService.deleteAccount(selectedAccountForActionMode);
|
|
|
|
selectedAccountForActionMode = null;
|
|
|
|
mode.finish();
|
|
|
|
}
|
|
|
|
});
|
2014-05-23 22:17:42 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel),null);
|
2014-03-06 02:30:03 +00:00
|
|
|
builder.create().show();
|
2014-03-07 13:24:33 +00:00
|
|
|
} else if (item.getItemId()==R.id.mgmt_account_announce_pgp) {
|
2014-03-06 02:30:03 +00:00
|
|
|
if (activity.hasPgp()) {
|
|
|
|
mode.finish();
|
2014-05-08 14:52:19 +00:00
|
|
|
announcePgp(selectedAccountForActionMode,null);
|
2014-03-06 02:30:03 +00:00
|
|
|
}
|
2014-03-14 20:36:38 +00:00
|
|
|
} else if (item.getItemId() == R.id.mgmt_otr_key) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
builder.setTitle("OTR Fingerprint");
|
|
|
|
String fingerprintTxt = selectedAccountForActionMode.getOtrFingerprint(getApplicationContext());
|
|
|
|
View view = (View) getLayoutInflater().inflate(R.layout.otr_fingerprint, null);
|
|
|
|
if (fingerprintTxt!=null) {
|
|
|
|
TextView fingerprint = (TextView) view.findViewById(R.id.otr_fingerprint);
|
2014-05-08 17:03:32 +00:00
|
|
|
TextView noFingerprintView = (TextView) view.findViewById(R.id.otr_no_fingerprint);
|
2014-03-14 20:36:38 +00:00
|
|
|
fingerprint.setText(fingerprintTxt);
|
2014-05-08 17:03:32 +00:00
|
|
|
fingerprint.setVisibility(View.VISIBLE);
|
|
|
|
noFingerprintView.setVisibility(View.GONE);
|
2014-03-14 20:36:38 +00:00
|
|
|
}
|
|
|
|
builder.setView(view);
|
2014-05-23 22:17:42 +00:00
|
|
|
builder.setPositiveButton(getString(R.string.done), null);
|
2014-03-14 20:36:38 +00:00
|
|
|
builder.create().show();
|
2014-03-12 21:31:50 +00:00
|
|
|
} else if (item.getItemId() == R.id.mgmt_account_info) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
builder.setTitle(getString(R.string.account_info));
|
|
|
|
if (selectedAccountForActionMode.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
XmppConnection xmpp = selectedAccountForActionMode.getXmppConnection();
|
|
|
|
long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000;
|
|
|
|
long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000;
|
2014-03-13 20:37:27 +00:00
|
|
|
long connectionAgeHours = connectionAge / 60;
|
|
|
|
long sessionAgeHours = sessionAge / 60;
|
2014-03-12 21:31:50 +00:00
|
|
|
View view = (View) getLayoutInflater().inflate(R.layout.server_info, null);
|
|
|
|
TextView connection = (TextView) view.findViewById(R.id.connection);
|
|
|
|
TextView session = (TextView) view.findViewById(R.id.session);
|
|
|
|
TextView pcks_sent = (TextView) view.findViewById(R.id.pcks_sent);
|
|
|
|
TextView pcks_received = (TextView) view.findViewById(R.id.pcks_received);
|
2014-03-13 16:29:22 +00:00
|
|
|
TextView carbon = (TextView) view.findViewById(R.id.carbon);
|
|
|
|
TextView stream = (TextView) view.findViewById(R.id.stream);
|
|
|
|
TextView roster = (TextView) view.findViewById(R.id.roster);
|
2014-03-19 15:16:40 +00:00
|
|
|
TextView presences = (TextView) view.findViewById(R.id.number_presences);
|
|
|
|
presences.setText(selectedAccountForActionMode.countPresences()+"");
|
2014-03-12 21:31:50 +00:00
|
|
|
pcks_received.setText(""+xmpp.getReceivedStanzas());
|
|
|
|
pcks_sent.setText(""+xmpp.getSentStanzas());
|
2014-03-13 20:37:27 +00:00
|
|
|
if (connectionAgeHours >= 2) {
|
2014-05-29 16:17:21 +00:00
|
|
|
connection.setText(connectionAgeHours+" " + getString(R.string.hours));
|
2014-03-13 20:37:27 +00:00
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
connection.setText(connectionAge+" " + getString(R.string.mins));
|
2014-03-13 20:37:27 +00:00
|
|
|
}
|
2014-03-13 16:29:22 +00:00
|
|
|
if (xmpp.hasFeatureStreamManagment()) {
|
2014-03-13 20:37:27 +00:00
|
|
|
if (sessionAgeHours >= 2) {
|
2014-05-29 16:17:21 +00:00
|
|
|
session.setText(sessionAgeHours+" " + getString(R.string.hours));
|
2014-03-13 20:37:27 +00:00
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
session.setText(sessionAge+" " + getString(R.string.mins));
|
2014-03-13 20:37:27 +00:00
|
|
|
}
|
2014-05-29 16:17:21 +00:00
|
|
|
stream.setText(getString(R.string.yes));
|
2014-03-13 16:29:22 +00:00
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
stream.setText(getString(R.string.no));
|
2014-03-13 20:37:27 +00:00
|
|
|
session.setText(connection.getText());
|
2014-03-13 16:29:22 +00:00
|
|
|
}
|
|
|
|
if (xmpp.hasFeaturesCarbon()) {
|
2014-05-29 16:17:21 +00:00
|
|
|
carbon.setText(getString(R.string.yes));
|
2014-03-13 16:29:22 +00:00
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
carbon.setText(getString(R.string.no));
|
2014-03-13 16:29:22 +00:00
|
|
|
}
|
|
|
|
if (xmpp.hasFeatureRosterManagment()) {
|
2014-05-29 16:17:21 +00:00
|
|
|
roster.setText(getString(R.string.yes));
|
2014-03-13 16:29:22 +00:00
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
roster.setText(getString(R.string.no));
|
2014-03-13 16:29:22 +00:00
|
|
|
}
|
2014-03-12 21:31:50 +00:00
|
|
|
builder.setView(view);
|
|
|
|
} else {
|
2014-05-29 16:17:21 +00:00
|
|
|
builder.setMessage(getString(R.string.mgmt_account_account_offline));
|
2014-03-12 21:31:50 +00:00
|
|
|
}
|
2014-05-29 16:17:21 +00:00
|
|
|
builder.setPositiveButton(getString(R.string.hide), null);
|
2014-03-12 21:31:50 +00:00
|
|
|
builder.create().show();
|
2014-03-06 02:30:03 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-13 03:21:59 +00:00
|
|
|
|
|
|
|
|
2014-03-06 02:30:03 +00:00
|
|
|
}));
|
2014-02-04 20:44:16 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-01 20:33:49 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
2014-02-04 14:09:50 +00:00
|
|
|
protected void onStop() {
|
2014-01-28 18:21:54 +00:00
|
|
|
if (xmppConnectionServiceBound) {
|
2014-02-04 14:09:50 +00:00
|
|
|
xmppConnectionService.removeOnAccountListChangedListener();
|
2014-03-07 13:24:33 +00:00
|
|
|
xmppConnectionService.removeOnTLSExceptionReceivedListener();
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2014-02-05 21:33:39 +00:00
|
|
|
super.onStop();
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
2014-02-04 14:09:50 +00:00
|
|
|
xmppConnectionService.setOnAccountListChangedListener(accountChanged);
|
2014-03-07 13:24:33 +00:00
|
|
|
xmppConnectionService.setOnTLSExceptionReceivedListener(tlsExceptionReceived);
|
2014-01-28 18:21:54 +00:00
|
|
|
this.accountList.clear();
|
|
|
|
this.accountList.addAll(xmppConnectionService.getAccounts());
|
|
|
|
accountListViewAdapter.notifyDataSetChanged();
|
2014-04-01 21:16:19 +00:00
|
|
|
if ((this.accountList.size() == 0)&&(this.firstrun)) {
|
2014-01-28 22:15:30 +00:00
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
2014-05-31 03:18:50 +00:00
|
|
|
getActionBar().setHomeButtonEnabled(false);
|
2014-01-28 22:15:30 +00:00
|
|
|
addAccount();
|
2014-04-01 21:16:19 +00:00
|
|
|
this.firstrun = false;
|
2014-01-28 22:15:30 +00:00
|
|
|
}
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.manageaccounts, menu);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 18:21:54 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_add_account:
|
2014-01-28 22:15:30 +00:00
|
|
|
addAccount();
|
2014-01-28 18:21:54 +00:00
|
|
|
break;
|
2014-05-31 03:41:44 +00:00
|
|
|
case android.R.id.home:
|
|
|
|
if (xmppConnectionService.getConversations().size() == 0) {
|
|
|
|
startActivity(new Intent(getApplicationContext(),
|
|
|
|
ContactsActivity.class));
|
|
|
|
}
|
|
|
|
break;
|
2014-01-28 18:21:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2014-01-28 22:15:30 +00:00
|
|
|
|
2014-03-13 03:21:59 +00:00
|
|
|
private void editAccount(Account account) {
|
|
|
|
EditAccount dialog = new EditAccount();
|
|
|
|
dialog.setAccount(account);
|
|
|
|
dialog.setEditAccountListener(new EditAccountListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAccountEdited(Account account) {
|
|
|
|
xmppConnectionService.updateAccount(account);
|
2014-03-13 16:29:22 +00:00
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
}
|
2014-03-13 03:21:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show(getFragmentManager(), "edit_account");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-28 22:15:30 +00:00
|
|
|
protected void addAccount() {
|
|
|
|
final Activity activity = this;
|
|
|
|
EditAccount dialog = new EditAccount();
|
|
|
|
dialog.setEditAccountListener(new EditAccountListener() {
|
2014-02-04 14:09:50 +00:00
|
|
|
|
2014-01-28 22:15:30 +00:00
|
|
|
@Override
|
|
|
|
public void onAccountEdited(Account account) {
|
|
|
|
xmppConnectionService.createAccount(account);
|
|
|
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
2014-05-31 03:18:50 +00:00
|
|
|
activity.getActionBar().setHomeButtonEnabled(true);
|
2014-01-28 22:15:30 +00:00
|
|
|
}
|
|
|
|
});
|
2014-02-04 14:09:50 +00:00
|
|
|
dialog.show(getFragmentManager(), "add_account");
|
2014-01-28 22:15:30 +00:00
|
|
|
}
|
2014-02-04 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeStarted(ActionMode mode) {
|
|
|
|
super.onActionModeStarted(mode);
|
|
|
|
this.isActionMode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeFinished(ActionMode mode) {
|
|
|
|
super.onActionModeFinished(mode);
|
|
|
|
this.isActionMode = false;
|
|
|
|
accountListView.clearChoices();
|
|
|
|
accountListView.requestLayout();
|
|
|
|
accountListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
accountListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-02-27 23:22:56 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
2014-05-08 14:52:19 +00:00
|
|
|
announcePgp(selectedAccountForActionMode,null);
|
|
|
|
}
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|