moved add/edit account from dialog into seperate activity

This commit is contained in:
iNPUTmice 2014-08-15 17:31:24 +02:00
parent f7c747ef4b
commit 32c3dd4f4a
13 changed files with 521 additions and 255 deletions

View File

@ -54,8 +54,7 @@
android:name="eu.siacs.conversations.ui.StartConversationActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_start_conversation"
android:logo="@drawable/ic_activity"
android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" >
android:logo="@drawable/ic_activity" >
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
@ -67,17 +66,20 @@
</activity>
<activity
android:name="eu.siacs.conversations.ui.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" >
android:label="@string/title_activity_settings" >
</activity>
<activity android:name="eu.siacs.conversations.ui.ChooseContactActivity"
android:label="@string/title_activity_choose_contact">
<activity
android:name="eu.siacs.conversations.ui.ChooseContactActivity"
android:label="@string/title_activity_choose_contact" >
</activity>
<activity
android:name="eu.siacs.conversations.ui.ManageAccountActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_manage_accounts"
android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" >
android:label="@string/title_activity_manage_accounts" >
</activity>
<activity
android:name="eu.siacs.conversations.ui.EditAccountActivity"
android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
<activity
android:name="eu.siacs.conversations.ui.ConferenceDetailsActivity"
@ -89,7 +91,7 @@
android:label="@string/title_activity_contact_details"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
<activity
android:name="eu.siacs.conversations.ui.PublishProfilePictureActivity"
android:label="@string/publish_avatar"
android:windowSoftInputMode="stateHidden" >

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primarybackground" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_settings_jabber_id"
android:textSize="14sp"
android:textColor="@color/primarytext"/>
<AutoCompleteTextView
android:id="@+id/account_jid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_settings_example_jabber_id"
android:inputType="textEmailAddress"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/account_settings_password"
android:textSize="14sp"
android:textColor="@color/primarytext"/>
<EditText
android:id="@+id/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword" />
<CheckBox
android:id="@+id/account_register_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/register_account"
android:textSize="14sp"
android:textColor="@color/primarytext"/>
<TextView
android:id="@+id/account_confirm_password_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_settings_confirm_password"
android:textSize="14sp"
android:textColor="@color/primarytext"
android:visibility="gone" />
<EditText
android:id="@+id/account_password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/confirm_password"
android:inputType="textPassword"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/cancel_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
android:textColor="@color/primarytext" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="@color/divider" />
<Button
android:id="@+id/save_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:text="@string/save"
android:textColor="@color/secondarytext" />
</LinearLayout>
</RelativeLayout>

View File

@ -281,4 +281,7 @@
<string name="private_message">in private</string>
<string name="private_message_to">in private to %s</string>
<string name="send_private_message_to">Send private message to %s</string>
<string name="connect">Connect</string>
<string name="account_already_exists">This account does already exist</string>
<string name="next">Next</string>
</resources>

View File

@ -45,8 +45,6 @@ public class Account extends AbstractEntity{
public static final int STATUS_UNAUTHORIZED = 3;
public static final int STATUS_SERVER_NOT_FOUND = 5;
public static final int STATUS_SERVER_REQUIRES_TLS = 6;
public static final int STATUS_REGISTRATION_FAILED = 7;
public static final int STATUS_REGISTRATION_CONFLICT = 8;
public static final int STATUS_REGISTRATION_SUCCESSFULL = 9;
@ -146,6 +144,11 @@ public class Account extends AbstractEntity{
}
}
public boolean errorStatus() {
int s = getStatus();
return (s == STATUS_OFFLINE || s == STATUS_SERVER_NOT_FOUND || s == STATUS_UNAUTHORIZED);
}
public boolean hasErrorStatus() {
return getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
}

View File

@ -42,9 +42,11 @@ public class IqGenerator extends AbstractGenerator {
protected IqPacket retrieve(String node, Element item) {
IqPacket packet = new IqPacket(IqPacket.TYPE_GET);
Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub");
Element items = pubsub.addChild("items");
items.setAttribute("node", node);
items.addChild(item);
Element items = pubsub.addChild("items");
items.setAttribute("node", node);
if (item!=null) {
items.addChild(item);
}
return packet;
}
@ -76,4 +78,12 @@ public class IqGenerator extends AbstractGenerator {
packet.setTo(avatar.owner);
return packet;
}
public IqPacket retrieveAvatarMetaData(String to) {
IqPacket packet = retrieve("urn:xmpp:avatar:metadata", null);
if (to!=null) {
packet.setTo(to);
}
return packet;
}
}

View File

@ -112,6 +112,7 @@ public class XmppConnectionService extends Service {
private OnConversationUpdate mOnConversationUpdate = null;
private int convChangedListenerCount = 0;
private OnAccountUpdate mOnAccountUpdate = null;
private int accountChangedListenerCount = 0;
private OnRosterUpdate mOnRosterUpdate = null;
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@ -924,10 +925,14 @@ public class XmppConnectionService extends Service {
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
this.mOnAccountUpdate = listener;
this.accountChangedListenerCount++;
}
public void removeOnAccountListChangedListener() {
this.mOnAccountUpdate = null;
this.accountChangedListenerCount--;
if (this.accountChangedListenerCount == 0) {
this.mOnAccountUpdate = null;
}
}
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
@ -1234,7 +1239,11 @@ public class XmppConnectionService extends Service {
}
}
public void fetchAvatar(Account account, final Avatar avatar) {
public void fetchAvatar(Account account, Avatar avatar) {
fetchAvatar(account, avatar, null);
}
public void fetchAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
Log.d(LOGTAG,account.getJid()+": retrieving avatar for "+avatar.owner);
IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@ -1250,8 +1259,44 @@ public class XmppConnectionService extends Service {
Contact contact = account.getRoster().getContact(avatar.owner);
contact.setAvatar(avatar.getFilename());
}
if (callback!=null) {
callback.success(avatar);
}
return;
}
}
if (callback!=null) {
callback.error(0, null);
}
}
});
}
public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE_RESULT) {
Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
if (pubsub!=null) {
Element items = pubsub.findChild("items");
if (items!=null) {
Avatar avatar = Avatar.parseMetadata(items);
if (avatar!=null) {
avatar.owner = account.getJid();
if (fileBackend.isAvatarCached(avatar)) {
callback.success(avatar);
} else {
fetchAvatar(account, avatar,callback);
}
return;
}
}
}
}
callback.error(0, null);
}
});
}

View File

@ -0,0 +1,300 @@
package eu.siacs.conversations.ui;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.CompoundButton.OnCheckedChangeListener;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.utils.Validator;
import eu.siacs.conversations.xmpp.pep.Avatar;
public class EditAccountActivity extends XmppActivity {
private AutoCompleteTextView mAccountJid;
private EditText mPassword;
private EditText mPasswordConfirm;
private CheckBox mRegisterNew;
private Button mCancelButton;
private Button mSaveButton;
private String jidToEdit;
private Account mAccount;
private Avatar mAvatar = null;
private boolean mUserInputIsValid = false;
private boolean mFetchingAvatar = false;
private boolean mFinishedInitialSetup = false;
private OnClickListener mSaveButtonClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (mAccount != null && mFinishedInitialSetup) {
Intent intent;
if (mAvatar!=null) {
intent = new Intent(getApplicationContext(), StartConversationActivity.class);
} else {
intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid());
}
startActivity(intent);
finish();
return;
} else if (mAccount != null && mAccount.errorStatus()
&& !mUserInputIsValid) {
xmppConnectionService.reconnectAccount(mAccount, true);
return;
}
boolean registerNewAccount = mRegisterNew.isChecked();
String[] jidParts = mAccountJid.getText().toString().split("@");
String username = jidParts[0];
String server;
if (jidParts.length >= 2) {
server = jidParts[1];
} else {
server = "";
}
String password = mPassword.getText().toString();
String passwordConfirm = mPasswordConfirm.getText().toString();
if (registerNewAccount) {
if (!password.equals(passwordConfirm)) {
mPasswordConfirm
.setError(getString(R.string.passwords_do_not_match));
return;
}
}
if (mAccount != null) {
mAccount.setPassword(password);
mAccount.setUsername(username);
mAccount.setServer(server);
mAccount.setOption(Account.OPTION_REGISTER, mRegisterNew.isChecked());
xmppConnectionService.updateAccount(mAccount);
} else {
if (xmppConnectionService.findAccountByJid(mAccountJid.getText().toString())!=null) {
mAccountJid.setError(getString(R.string.account_already_exists));
return;
}
mAccount = new Account(username, server, password);
mAccount.setOption(Account.OPTION_USETLS, true);
mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
if (registerNewAccount) {
mAccount.setOption(Account.OPTION_REGISTER, true);
}
xmppConnectionService.createAccount(mAccount);
}
if (jidToEdit != null) {
finish();
} else {
mUserInputIsValid = false;
updateSaveButton();
updateAccountInformation();
}
}
};
private OnClickListener mCancelButtonClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
};
private TextWatcher mTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (Validator.isValidJid(mAccountJid.getText().toString())) {
mUserInputIsValid = inputDataDiffersFromAccount();
} else {
mUserInputIsValid = false;
}
updateSaveButton();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
private OnAccountUpdate mOnAccountUpdateListener = new OnAccountUpdate() {
@Override
public void onAccountUpdate() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (jidToEdit==null && mAccount!=null && mAccount.getStatus() == Account.STATUS_ONLINE) {
if (!mFetchingAvatar) {
mFetchingAvatar = true;
xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback);
}
} else {
updateSaveButton();
}
}
});
}
};
private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
@Override
public void userInputRequried(PendingIntent pi, Avatar avatar) {
finishInitialSetup(avatar);
}
@Override
public void success(Avatar avatar) {
finishInitialSetup(avatar);
}
@Override
public void error(int errorCode, Avatar avatar) {
finishInitialSetup(avatar);
}
};
protected void finishInitialSetup(Avatar avatar) {
this.mFinishedInitialSetup = true;
this.mAvatar = avatar;
runOnUiThread(new Runnable() {
@Override
public void run() {
updateSaveButton();
}
});
}
protected boolean inputDataDiffersFromAccount() {
if (mAccount == null) {
return true;
} else {
return (!mAccount.getJid().equals(mAccountJid.getText().toString()))
|| (!mAccount.getPassword().equals(
mPassword.getText().toString()) || mAccount
.isOptionSet(Account.OPTION_REGISTER) != mRegisterNew
.isChecked());
}
}
protected void updateSaveButton() {
if (mAccount != null && mFinishedInitialSetup) {
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
this.mSaveButton.setText(R.string.next);
} else if (mAccount != null
&& mAccount.getStatus() == Account.STATUS_CONNECTING
&& !mUserInputIsValid) {
this.mSaveButton.setEnabled(false);
this.mSaveButton.setTextColor(getSecondaryTextColor());
this.mSaveButton.setText(R.string.account_status_connecting);
} else if (mAccount != null && mAccount.errorStatus()
&& !mUserInputIsValid) {
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
this.mSaveButton.setText(R.string.connect);
} else if (mUserInputIsValid) {
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
} else {
this.mSaveButton.setEnabled(false);
this.mSaveButton.setTextColor(getSecondaryTextColor());
this.mSaveButton.setText(R.string.save);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_account);
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
this.mPassword = (EditText) findViewById(R.id.account_password);
this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
this.mSaveButton = (Button) findViewById(R.id.save_button);
this.mCancelButton = (Button) findViewById(R.id.cancel_button);
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
this.mRegisterNew
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
mPasswordConfirm.setVisibility(View.VISIBLE);
} else {
mPasswordConfirm.setVisibility(View.GONE);
}
mUserInputIsValid = inputDataDiffersFromAccount();
updateSaveButton();
}
});
this.mAccountJid.addTextChangedListener(this.mTextWatcher);
this.mPassword.addTextChangedListener(this.mTextWatcher);
}
@Override
protected void onStart() {
super.onStart();
if (getIntent() != null) {
this.jidToEdit = getIntent().getStringExtra("jid");
if (this.jidToEdit != null) {
this.mRegisterNew.setVisibility(View.GONE);
getActionBar().setTitle(R.string.mgmt_account_edit);
} else {
getActionBar().setTitle(R.string.action_add_account);
}
}
}
@Override
protected void onBackendConnected() {
this.xmppConnectionService
.setOnAccountListChangedListener(this.mOnAccountUpdateListener);
this.mAccountJid.setAdapter(null);
if (this.jidToEdit != null) {
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
updateAccountInformation();
} else if (this.xmppConnectionService.getAccounts().size() == 0) {
getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
this.mCancelButton.setEnabled(false);
}
this.mAccountJid.setAdapter(new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1, xmppConnectionService
.getKnownHosts()));
updateSaveButton();
}
private void updateAccountInformation() {
this.mAccountJid.setText(this.mAccount.getJid());
this.mPassword.setText(this.mAccount.getPassword());
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
this.mRegisterNew.setVisibility(View.VISIBLE);
this.mRegisterNew.setChecked(true);
this.mPasswordConfirm.setText(this.mAccount.getPassword());
} else {
this.mRegisterNew.setVisibility(View.GONE);
this.mRegisterNew.setChecked(false);
}
}
}

View File

@ -1,157 +0,0 @@
package eu.siacs.conversations.ui;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.utils.Validator;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
public class EditAccountDialog extends DialogFragment {
protected Account account;
protected AutoCompleteTextView mAccountJid;
public void setAccount(Account account) {
this.account = account;
}
public interface EditAccountListener {
public void onAccountEdited(Account account);
}
protected EditAccountListener listener = null;
private KnownHostsAdapter mKnownHostsAdapter;
public void setEditAccountListener(EditAccountListener listener) {
this.listener = listener;
}
public void setKnownHosts(List<String> hosts, Context context) {
this.mKnownHostsAdapter = new KnownHostsAdapter(context, android.R.layout.simple_list_item_1, hosts);
if (this.mAccountJid != null) {
this.mAccountJid.setAdapter(this.mKnownHostsAdapter);
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.edit_account_dialog, null);
mAccountJid = (AutoCompleteTextView) view.findViewById(R.id.account_jid);
if (this.mKnownHostsAdapter!=null) {
mAccountJid.setAdapter(this.mKnownHostsAdapter);
}
final TextView confirmPwDesc = (TextView) view
.findViewById(R.id.account_confirm_password_desc);
final EditText password = (EditText) view
.findViewById(R.id.account_password);
final EditText passwordConfirm = (EditText) view
.findViewById(R.id.account_password_confirm2);
final CheckBox registerAccount = (CheckBox) view
.findViewById(R.id.edit_account_register_new);
if (account != null) {
mAccountJid.setText(account.getJid());
password.setText(account.getPassword());
if (account.isOptionSet(Account.OPTION_REGISTER)) {
registerAccount.setChecked(true);
passwordConfirm.setVisibility(View.VISIBLE);
passwordConfirm.setText(account.getPassword());
} else {
registerAccount.setVisibility(View.GONE);
}
}
builder.setTitle(R.string.account_settings);
registerAccount
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
passwordConfirm.setVisibility(View.VISIBLE);
confirmPwDesc.setVisibility(View.VISIBLE);
} else {
passwordConfirm.setVisibility(View.GONE);
confirmPwDesc.setVisibility(View.GONE);
}
}
});
builder.setView(view);
builder.setNeutralButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.save), null);
return builder.create();
}
@Override
public void onStart() {
super.onStart();
final AlertDialog d = (AlertDialog) getDialog();
Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText jidEdit = (EditText) d.findViewById(R.id.account_jid);
String jid = jidEdit.getText().toString();
EditText passwordEdit = (EditText) d
.findViewById(R.id.account_password);
EditText passwordConfirmEdit = (EditText) d.findViewById(R.id.account_password_confirm2);
String password = passwordEdit.getText().toString();
String passwordConfirm = passwordConfirmEdit.getText().toString();
CheckBox register = (CheckBox) d.findViewById(R.id.edit_account_register_new);
String username;
String server;
if (Validator.isValidJid(jid)) {
String[] parts = jid.split("@");
username = parts[0];
server = parts[1];
} else {
jidEdit.setError(getString(R.string.invalid_jid));
return;
}
if (register.isChecked()) {
if (!passwordConfirm.equals(password)) {
passwordConfirmEdit.setError(getString(R.string.passwords_do_not_match));
return;
}
}
if (account != null) {
account.setPassword(password);
account.setUsername(username);
account.setServer(server);
} else {
account = new Account(username, server, password);
account.setOption(Account.OPTION_USETLS, true);
account.setOption(Account.OPTION_USECOMPRESSION, true);
}
account.setOption(Account.OPTION_REGISTER, register.isChecked());
if (listener != null) {
listener.onAccountEdited(account);
d.dismiss();
}
}
});
}
}

View File

@ -6,7 +6,6 @@ import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.ui.EditAccountDialog.EditAccountListener;
import eu.siacs.conversations.ui.adapter.AccountAdapter;
import eu.siacs.conversations.xmpp.XmppConnection;
import android.app.Activity;
@ -236,17 +235,7 @@ public class ManageAccountActivity extends XmppActivity {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
if (!isActionMode) {
Account account = accountList.get(position);
if (account.getStatus() == Account.STATUS_OFFLINE) {
activity.xmppConnectionService.reconnectAccount(
accountList.get(position), true);
} else if (account.getStatus() == Account.STATUS_ONLINE) {
activity.startActivity(new Intent(activity
.getApplicationContext(),
StartConversationActivity.class));
} else if (account.getStatus() != Account.STATUS_DISABLED) {
editAccount(account);
}
editAccount(accountList.get(position));
} else {
selectedAccountForActionMode = accountList.get(position);
actionMode.invalidate();
@ -292,7 +281,6 @@ public class ManageAccountActivity extends XmppActivity {
if ((this.accountList.size() == 0) && (this.firstrun)) {
getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false);
addAccount();
this.firstrun = false;
}
}
@ -307,7 +295,7 @@ public class ManageAccountActivity extends XmppActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_account:
addAccount();
startActivity(new Intent(getApplicationContext(), EditAccountActivity.class));
break;
default:
break;
@ -337,37 +325,9 @@ public class ManageAccountActivity extends XmppActivity {
}
private void editAccount(Account account) {
EditAccountDialog dialog = new EditAccountDialog();
dialog.setAccount(account);
dialog.setEditAccountListener(new EditAccountListener() {
@Override
public void onAccountEdited(Account account) {
xmppConnectionService.updateAccount(account);
if (actionMode != null) {
actionMode.finish();
}
}
});
dialog.show(getFragmentManager(), "edit_account");
dialog.setKnownHosts(xmppConnectionService.getKnownHosts(), this);
}
protected void addAccount() {
final Activity activity = this;
EditAccountDialog dialog = new EditAccountDialog();
dialog.setEditAccountListener(new EditAccountListener() {
@Override
public void onAccountEdited(Account account) {
xmppConnectionService.createAccount(account);
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
activity.getActionBar().setHomeButtonEnabled(true);
}
});
dialog.show(getFragmentManager(), "add_account");
dialog.setKnownHosts(xmppConnectionService.getKnownHosts(), this);
Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid());
startActivity(intent);
}
@Override

View File

@ -133,17 +133,6 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
super.onOptionsItemSelected(menuItem);
switch (menuItem.getItemId()) {
case android.R.id.home:
finish();
break;
}
return true;
}
@Override
protected void onBackendConnected() {
if (getIntent() != null) {

View File

@ -154,6 +154,9 @@ public abstract class XmppActivity extends Activity {
case R.id.action_accounts:
startActivity(new Intent(this, ManageAccountActivity.class));
break;
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
@ -203,8 +206,9 @@ public abstract class XmppActivity extends Activity {
}
protected void inviteToConversation(Conversation conversation) {
Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
intent.putExtra("conversation",conversation.getUuid());
Intent intent = new Intent(getApplicationContext(),
ChooseContactActivity.class);
intent.putExtra("conversation", conversation.getUuid());
startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION);
}
@ -218,7 +222,8 @@ public abstract class XmppActivity extends Activity {
try {
startIntentSenderForResult(pi.getIntentSender(),
REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {}
} catch (SendIntentException e) {
}
}
@Override
@ -279,9 +284,11 @@ public abstract class XmppActivity extends Activity {
builder.create().show();
}
protected void quickEdit(final String previousValue, final OnValueEdited callback) {
protected void quickEdit(final String previousValue,
final OnValueEdited callback) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = (View) getLayoutInflater().inflate(R.layout.quickedit, null);
View view = (View) getLayoutInflater()
.inflate(R.layout.quickedit, null);
final EditText editor = (EditText) view.findViewById(R.id.editor);
editor.setText(previousValue);
builder.setView(view);
@ -354,14 +361,17 @@ public abstract class XmppActivity extends Activity {
protected void onActivityResult(int requestCode, int resultCode,
final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_INVITE_TO_CONVERSATION && resultCode == RESULT_OK) {
if (requestCode == REQUEST_INVITE_TO_CONVERSATION
&& resultCode == RESULT_OK) {
String contactJid = data.getStringExtra("contact");
String conversationUuid = data.getStringExtra("conversation");
Conversation conversation = xmppConnectionService.findConversationByUuid(conversationUuid);
Conversation conversation = xmppConnectionService
.findConversationByUuid(conversationUuid);
if (conversation.getMode() == Conversation.MODE_MULTI) {
xmppConnectionService.invite(conversation, contactJid);
}
Log.d("xmppService","inviting "+contactJid+" to "+conversation.getName(true));
Log.d("xmppService", "inviting " + contactJid + " to "
+ conversation.getName(true));
}
}

View File

@ -221,11 +221,6 @@ public class XmppConnection implements Runnable {
processStreamError(nextTag);
} else if (nextTag.isStart("features")) {
processStreamFeatures(nextTag);
if ((streamFeatures.getChildren().size() == 1)
&& (streamFeatures.hasChild("starttls"))
&& (!account.isOptionSet(Account.OPTION_USETLS))) {
changeStatus(Account.STATUS_SERVER_REQUIRES_TLS);
}
} else if (nextTag.isStart("proceed")) {
switchOverToTls(nextTag);
} else if (nextTag.isStart("compressed")) {

View File

@ -25,6 +25,7 @@ public class Avatar {
return sha1sum;
}
}
public static Avatar parseMetadata(Element items) {
Element item = items.findChild("item");
if (item==null) {