diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
6 files changed, 84 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 2c98e4e7c..eb9ccb6bd 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -825,7 +825,7 @@ public class ConversationActivity extends XmppActivity conversation.setNextEncryption(Message.ENCRYPTION_PGP); item.setChecked(true); } else { - announcePgp(conversation.getAccount(), conversation); + announcePgp(conversation.getAccount(), conversation, onOpenPGPKeyPublished); } } else { showInstallPgpDialog(); @@ -1284,7 +1284,7 @@ public class ConversationActivity extends XmppActivity // associate selected PGP keyId with the account mSelectedConversation.getAccount().setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID)); // we need to announce the key as described in XEP-027 - announcePgp(mSelectedConversation.getAccount(), null); + announcePgp(mSelectedConversation.getAccount(), null, onOpenPGPKeyPublished); } else { choosePgpSignId(mSelectedConversation.getAccount()); } @@ -1294,7 +1294,7 @@ public class ConversationActivity extends XmppActivity } } else if (requestCode == REQUEST_ANNOUNCE_PGP) { if (xmppConnectionServiceBound) { - announcePgp(mSelectedConversation.getAccount(), mSelectedConversation); + announcePgp(mSelectedConversation.getAccount(), mSelectedConversation, onOpenPGPKeyPublished); this.mPostponedActivityResult = null; } else { this.mPostponedActivityResult = new Pair<>(requestCode, data); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 23b68e3b0..0b4608ba6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1188,7 +1188,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa return; } if (conversation.getAccount().getPgpSignature() == null) { - activity.announcePgp(conversation.getAccount(), conversation); + activity.announcePgp(conversation.getAccount(), conversation, activity.onOpenPGPKeyPublished); return; } if (conversation.getMode() == Conversation.MODE_SINGLE) { diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java index 4b8702798..2d29c521e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -328,7 +328,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda private void publishOpenPGPPublicKey(Account account) { if (ManageAccountActivity.this.hasPgp()) { - choosePgpSignId(selectedAccount); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } else { this.showInstallPgpDialog(); } @@ -360,12 +360,12 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda if (requestCode == REQUEST_CHOOSE_PGP_ID) { if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) { selectedAccount.setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID)); - announcePgp(selectedAccount, null); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } else { choosePgpSignId(selectedAccount); } } else if (requestCode == REQUEST_ANNOUNCE_PGP) { - announcePgp(selectedAccount, null); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } this.mPostponedActivityResult = null; } else { diff --git a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java index 5fe9c5d8c..effd30bf5 100644 --- a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java @@ -1,7 +1,9 @@ package eu.siacs.conversations.ui; +import android.content.Intent; import android.os.Bundle; import android.os.Handler; +import android.util.Pair; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -18,6 +20,8 @@ import android.widget.TextView; import android.util.Log; +import org.openintents.openpgp.util.OpenPgpApi; + import java.util.List; import java.util.concurrent.RunnableFuture; import java.util.concurrent.atomic.AtomicBoolean; @@ -42,6 +46,14 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis protected Spinner mShowSpinner; protected CheckBox mAllAccounts; protected LinearLayout mTemplatesView; + private Pair<Integer, Intent> mPostponedActivityResult; + + private Runnable onPresenceChanged = new Runnable() { + @Override + public void run() { + finish(); + } + }; protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,16 +95,37 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { + if (xmppConnectionServiceBound && mAccount != null) { + if (requestCode == REQUEST_ANNOUNCE_PGP) { + announcePgp(mAccount, null, onPresenceChanged); + } + this.mPostponedActivityResult = null; + } else { + this.mPostponedActivityResult = new Pair<>(requestCode, data); + } + } + } + private void executeChangePresence() { Presence.Status status = getStatusFromSpinner(); boolean allAccounts = mAllAccounts.isChecked(); String statusMessage = mStatusMessage.getText().toString().trim(); - if (allAccounts) { + if (allAccounts && noAccountUsesPgp()) { xmppConnectionService.changeStatus(status, statusMessage); + finish(); } else if (mAccount != null) { - xmppConnectionService.changeStatus(mAccount, status, statusMessage); + if (mAccount.getPgpId() == 0) { + xmppConnectionService.changeStatus(mAccount, status, statusMessage, true); + finish(); + } else { + xmppConnectionService.changeStatus(mAccount, status, statusMessage, false); + announcePgp(mAccount, null, onPresenceChanged); + } } - finish(); } private Presence.Status getStatusFromSpinner() { @@ -145,6 +178,12 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis mStatusMessage.append(message); } mTemplates = xmppConnectionService.databaseBackend.getPresenceTemplates(); + if (this.mPostponedActivityResult != null) { + this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); + } + boolean e = noAccountUsesPgp(); + mAllAccounts.setEnabled(e); + mAllAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor()); } redrawTemplates(); } diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 6eef7eb3a..cd843b259 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -187,6 +187,9 @@ public class SettingsActivity extends XmppActivity implements || name.equals("manually_change_presence")) { xmppConnectionService.toggleScreenEventReceiver(); } + if (name.equals("manually_change_presence") && !noAccountUsesPgp()) { + Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show(); + } xmppConnectionService.refreshAllPresences(); } } else if (name.equals("dont_trust_system_cas")) { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index bb9016131..b58fa6c23 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -68,6 +68,7 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.RunnableFuture; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -118,6 +119,13 @@ public abstract class XmppActivity extends Activity { protected int mTheme; protected boolean mUsingEnterKey = false; + protected Runnable onOpenPGPKeyPublished = new Runnable() { + @Override + public void run() { + Toast.makeText(XmppActivity.this,R.string.openpgp_has_been_published, Toast.LENGTH_SHORT).show(); + } + }; + private long mLastUiRefresh = 0; private Handler mRefreshUiHandler = new Handler(); private Runnable mRefreshUiRunnable = new Runnable() { @@ -489,18 +497,23 @@ public abstract class XmppActivity extends Activity { startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION); } - protected void announcePgp(Account account, final Conversation conversation) { - if (account.getPgpId() == -1) { + protected void announcePgp(Account account, final Conversation conversation, final Runnable onSuccess) { + if (account.getPgpId() == 0) { choosePgpSignId(account); } else { - xmppConnectionService.getPgpEngine().generateSignature(account, "", new UiCallback<Account>() { + String status = null; + if (manuallyChangePresence()) { + status = account.getPresenceStatusMessage(); + } + if (status == null) { + status = ""; + } + xmppConnectionService.getPgpEngine().generateSignature(account, status, new UiCallback<Account>() { @Override - public void userInputRequried(PendingIntent pi, - Account account) { + public void userInputRequried(PendingIntent pi, Account account) { try { - startIntentSenderForResult(pi.getIntentSender(), - REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); } catch (final SendIntentException ignored) { } } @@ -513,6 +526,9 @@ public abstract class XmppActivity extends Activity { conversation.setNextEncryption(Message.ENCRYPTION_PGP); xmppConnectionService.databaseBackend.updateConversation(conversation); } + if (onSuccess != null) { + runOnUiThread(onSuccess); + } } @Override @@ -523,6 +539,15 @@ public abstract class XmppActivity extends Activity { } } + protected boolean noAccountUsesPgp() { + for(Account account : xmppConnectionService.getAccounts()) { + if (account.getPgpId() != 0) { + return false; + } + } + return true; + } + @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) protected void setListItemBackgroundOnView(View view) { |