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
public void onBackendConnected() {
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;
break;
}

View File

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

View File

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

View File

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

View File

@ -778,7 +778,7 @@ public class ConversationActivity extends XmppActivity
Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
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()) {
case R.id.scan_fingerprint:
intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
@ -1541,7 +1541,7 @@ public class ConversationActivity extends XmppActivity
axolotlService.createSessionsIfNeeded(mSelectedConversation);
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
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("has_no_trusted", hasNoTrustedKeys);
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.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
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);
startActivity(intent);
}

View File

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

View File

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

View File

@ -198,52 +198,43 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override
protected void onBackendConnected() {
if (getIntent() != null) {
Jid jid;
try {
jid = Jid.fromString(getIntent().getStringExtra("account"));
} catch (InvalidJidException e) {
jid = null;
this.account = extractAccount(getIntent());
if (this.account != null) {
if (this.account.getXmppConnection() != null) {
this.support = this.account.getXmppConnection().getFeatures().pep();
}
if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid);
if (this.account.getXmppConnection() != null) {
this.support = this.account.getXmppConnection().getFeatures().pep();
}
if (this.avatarUri == null) {
if (this.account.getAvatar() != null
|| this.defaultUri == null) {
this.avatar.setImageBitmap(avatarService().get(account, getPixel(192)));
if (this.defaultUri != null) {
this.avatar
.setOnLongClickListener(this.backToDefaultListener);
} else {
this.secondaryHint.setVisibility(View.INVISIBLE);
}
if (!support) {
this.hintOrWarning
.setTextColor(getWarningTextColor());
this.hintOrWarning
.setText(R.string.error_publish_avatar_no_server_support);
}
if (this.avatarUri == null) {
if (this.account.getAvatar() != null
|| this.defaultUri == null) {
this.avatar.setImageBitmap(avatarService().get(account, getPixel(192)));
if (this.defaultUri != null) {
this.avatar
.setOnLongClickListener(this.backToDefaultListener);
} else {
this.avatarUri = this.defaultUri;
loadImageIntoPreview(this.defaultUri);
this.secondaryHint.setVisibility(View.INVISIBLE);
}
if (!support) {
this.hintOrWarning
.setTextColor(getWarningTextColor());
this.hintOrWarning
.setText(R.string.error_publish_avatar_no_server_support);
}
} else {
loadImageIntoPreview(avatarUri);
this.avatarUri = this.defaultUri;
loadImageIntoPreview(this.defaultUri);
this.secondaryHint.setVisibility(View.INVISIBLE);
}
String account;
if (Config.DOMAIN_LOCK != null) {
account = this.account.getJid().getLocalpart();
} else {
account = this.account.getJid().toBareJid().toString();
}
this.accountTextView.setText(account);
} else {
loadImageIntoPreview(avatarUri);
}
String account;
if (Config.DOMAIN_LOCK != null) {
account = this.account.getJid().getLocalpart();
} else {
account = this.account.getJid().toBareJid().toString();
}
this.accountTextView.setText(account);
}
}
@Override

View File

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

View File

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

View File

@ -196,9 +196,8 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
protected boolean handleIntent(Intent intent) {
if (intent != null && intent.getAction().equals(ACTION_VERIFY_CONTACT)) {
try {
this.mAccount = this.xmppConnectionService.findAccountByJid(Jid.fromString(intent.getExtras().getString("account")));
} catch (final InvalidJidException ignored) {
this.mAccount = extractAccount(intent);
if (this.mAccount == null) {
return false;
}
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_BATTERY_OP = 0x13849ff;
public static final String ACCOUNT_EXTRA = "account";
public static final String EXTRA_ACCOUNT = "account";
public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false;
@ -449,7 +449,7 @@ public abstract class XmppActivity extends Activity {
public void switchToContactDetails(Contact contact, String messageFingerprint) {
Intent intent = new Intent(this, ContactDetailsActivity.class);
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("fingerprint", messageFingerprint);
startActivity(intent);
@ -484,7 +484,7 @@ public abstract class XmppActivity extends Activity {
intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", 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);
}
@ -1061,8 +1061,7 @@ public abstract class XmppActivity extends Activity {
}
protected Account extractAccount(Intent intent) {
String jid = intent != null ? intent.getStringExtra(ACCOUNT_EXTRA) : null;
Log.d(Config.LOGTAG,"jid: "+jid);
String jid = intent != null ? intent.getStringExtra(EXTRA_ACCOUNT) : null;
try {
return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null;
} catch (InvalidJidException e) {