use extract account from intent method and final EXTRA_ACCOUNT variable

This commit is contained in:
Daniel Gultsch 2016-01-22 20:46:24 +01:00
parent a6c5430cdd
commit ba98fe4f86
13 changed files with 52 additions and 70 deletions

View File

@ -35,7 +35,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
@Override @Override
public void onBackendConnected() { public void onBackendConnected() {
for (final Account account : xmppConnectionService.getAccounts()) { for (final Account account : xmppConnectionService.getAccounts()) {
if (account.getJid().toString().equals(getIntent().getStringExtra("account"))) { if (account.getJid().toString().equals(getIntent().getStringExtra(EXTRA_ACCOUNT))) {
this.account = account; this.account = account;
break; break;
} }

View File

@ -50,14 +50,7 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
@Override @Override
void onBackendConnected() { void onBackendConnected() {
try { this.mAccount = extractAccount(getIntent());
final String jid = getIntent() == null ? null : getIntent().getStringExtra("account");
if (jid != null) {
this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(jid));
}
} catch (final InvalidJidException ignored) {
}
} }

View File

@ -113,11 +113,11 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
final Intent data = new Intent(); final Intent data = new Intent();
final ListItem mListItem = getListItems().get(position); final ListItem mListItem = getListItems().get(position);
data.putExtra("contact", mListItem.getJid().toString()); data.putExtra("contact", mListItem.getJid().toString());
String account = request.getStringExtra("account"); String account = request.getStringExtra(EXTRA_ACCOUNT);
if (account == null && mListItem instanceof Contact) { if (account == null && mListItem instanceof Contact) {
account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString(); account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
} }
data.putExtra("account", account); data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra("conversation", data.putExtra("conversation",
request.getStringExtra("conversation")); request.getStringExtra("conversation"));
data.putExtra("multiple", false); data.putExtra("multiple", false);
@ -181,7 +181,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
EnterJidDialog dialog = new EnterJidDialog( EnterJidDialog dialog = new EnterJidDialog(
this, mKnownHosts, mActivatedAccounts, this, mKnownHosts, mActivatedAccounts,
getString(R.string.enter_contact), getString(R.string.select), getString(R.string.enter_contact), getString(R.string.select),
null, getIntent().getStringExtra("account"), true null, getIntent().getStringExtra(EXTRA_ACCOUNT), true
); );
dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
@ -190,7 +190,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
final Intent request = getIntent(); final Intent request = getIntent();
final Intent data = new Intent(); final Intent data = new Intent();
data.putExtra("contact", contactJid.toString()); data.putExtra("contact", contactJid.toString());
data.putExtra("account", accountJid.toString()); data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
data.putExtra("conversation", data.putExtra("conversation",
request.getStringExtra("conversation")); request.getStringExtra("conversation"));
data.putExtra("multiple", false); data.putExtra("multiple", false);

View File

@ -190,7 +190,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) { if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
try { try {
this.accountJid = Jid.fromString(getIntent().getExtras().getString("account")); this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final InvalidJidException ignored) { } catch (final InvalidJidException ignored) {
} }
try { try {

View File

@ -778,7 +778,7 @@ public class ConversationActivity extends XmppActivity
Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class); Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString()); intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.scan_fingerprint: case R.id.scan_fingerprint:
intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT); intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
@ -1541,7 +1541,7 @@ public class ConversationActivity extends XmppActivity
axolotlService.createSessionsIfNeeded(mSelectedConversation); axolotlService.createSessionsIfNeeded(mSelectedConversation);
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class); Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString()); intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
intent.putExtra("account", mSelectedConversation.getAccount().getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString());
intent.putExtra("choice", attachmentChoice); intent.putExtra("choice", attachmentChoice);
intent.putExtra("has_no_trusted", hasNoTrustedKeys); intent.putExtra("has_no_trusted", hasNoTrustedKeys);
startActivityForResult(intent, requestCode); startActivityForResult(intent, requestCode);

View File

@ -748,7 +748,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
Intent intent = new Intent(activity, VerifyOTRActivity.class); Intent intent = new Intent(activity, VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString()); intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString()); intent.putExtra(VerifyOTRActivity.EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION); intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION);
startActivity(intent); startActivity(intent);
} }

View File

@ -283,7 +283,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
public void onClick(final View view) { public void onClick(final View view) {
if (mAccount != null) { if (mAccount != null) {
final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
startActivity(intent); startActivity(intent);
} }
} }
@ -304,7 +304,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else { } else {
intent = new Intent(getApplicationContext(), intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
intent.putExtra("setup", true); intent.putExtra("setup", true);
} }
startActivity(intent); startActivity(intent);
@ -552,7 +552,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_show_block_list: case R.id.action_show_block_list:
final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class); final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
showBlocklistIntent.putExtra("account", mAccount.getJid().toString()); showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
startActivity(showBlocklistIntent); startActivity(showBlocklistIntent);
break; break;
case R.id.action_server_info_show_more: case R.id.action_server_info_show_more:
@ -561,7 +561,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
break; break;
case R.id.action_change_password_on_server: case R.id.action_change_password_on_server:
final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class); final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
changePasswordIntent.putExtra("account", mAccount.getJid().toString()); changePasswordIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
startActivity(changePasswordIntent); startActivity(changePasswordIntent);
break; break;
case R.id.action_clear_devices: case R.id.action_clear_devices:

View File

@ -251,7 +251,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
private void publishAvatar(Account account) { private void publishAvatar(Account account) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", account.getJid().toString()); intent.putExtra(EXTRA_ACCOUNT, account.getJid().toString());
startActivity(intent); startActivity(intent);
} }

View File

@ -198,15 +198,8 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
if (getIntent() != null) { this.account = extractAccount(getIntent());
Jid jid; if (this.account != null) {
try {
jid = Jid.fromString(getIntent().getStringExtra("account"));
} catch (InvalidJidException e) {
jid = null;
}
if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid);
if (this.account.getXmppConnection() != null) { if (this.account.getXmppConnection() != null) {
this.support = this.account.getXmppConnection().getFeatures().pep(); this.support = this.account.getXmppConnection().getFeatures().pep();
} }
@ -244,8 +237,6 @@ public class PublishProfilePictureActivity extends XmppActivity {
} }
} }
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();

View File

@ -84,7 +84,7 @@ public class ShareWithActivity extends XmppActivity {
if (requestCode == REQUEST_START_NEW_CONVERSATION if (requestCode == REQUEST_START_NEW_CONVERSATION
&& resultCode == RESULT_OK) { && resultCode == RESULT_OK) {
share.contact = data.getStringExtra("contact"); share.contact = data.getStringExtra("contact");
share.account = data.getStringExtra("account"); share.account = data.getStringExtra(EXTRA_ACCOUNT);
} }
if (xmppConnectionServiceBound if (xmppConnectionServiceBound
&& share != null && share != null

View File

@ -83,7 +83,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trust_keys); setContentView(R.layout.activity_trust_keys);
try { try {
this.accountJid = Jid.fromString(getIntent().getExtras().getString("account")); this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final InvalidJidException ignored) { } catch (final InvalidJidException ignored) {
} }
try { try {

View File

@ -196,9 +196,8 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
protected boolean handleIntent(Intent intent) { protected boolean handleIntent(Intent intent) {
if (intent != null && intent.getAction().equals(ACTION_VERIFY_CONTACT)) { if (intent != null && intent.getAction().equals(ACTION_VERIFY_CONTACT)) {
try { this.mAccount = extractAccount(intent);
this.mAccount = this.xmppConnectionService.findAccountByJid(Jid.fromString(intent.getExtras().getString("account"))); if (this.mAccount == null) {
} catch (final InvalidJidException ignored) {
return false; return false;
} }
try { try {

View File

@ -95,7 +95,7 @@ public abstract class XmppActivity extends Activity {
protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103; protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103;
protected static final int REQUEST_BATTERY_OP = 0x13849ff; protected static final int REQUEST_BATTERY_OP = 0x13849ff;
public static final String ACCOUNT_EXTRA = "account"; public static final String EXTRA_ACCOUNT = "account";
public XmppConnectionService xmppConnectionService; public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false; public boolean xmppConnectionServiceBound = false;
@ -449,7 +449,7 @@ public abstract class XmppActivity extends Activity {
public void switchToContactDetails(Contact contact, String messageFingerprint) { public void switchToContactDetails(Contact contact, String messageFingerprint) {
Intent intent = new Intent(this, ContactDetailsActivity.class); Intent intent = new Intent(this, ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra("account", contact.getAccount().getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, contact.getAccount().getJid().toBareJid().toString());
intent.putExtra("contact", contact.getJid().toString()); intent.putExtra("contact", contact.getJid().toString());
intent.putExtra("fingerprint", messageFingerprint); intent.putExtra("fingerprint", messageFingerprint);
startActivity(intent); startActivity(intent);
@ -484,7 +484,7 @@ public abstract class XmppActivity extends Activity {
intent.putExtra("conversation", conversation.getUuid()); intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", true); intent.putExtra("multiple", true);
intent.putExtra("show_enter_jid", true); intent.putExtra("show_enter_jid", true);
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString()); intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION); startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION);
} }
@ -1061,8 +1061,7 @@ public abstract class XmppActivity extends Activity {
} }
protected Account extractAccount(Intent intent) { protected Account extractAccount(Intent intent) {
String jid = intent != null ? intent.getStringExtra(ACCOUNT_EXTRA) : null; String jid = intent != null ? intent.getStringExtra(EXTRA_ACCOUNT) : null;
Log.d(Config.LOGTAG,"jid: "+jid);
try { try {
return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null; return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null;
} catch (InvalidJidException e) { } catch (InvalidJidException e) {