diff options
author | Christian S <christian@pix-art.de> | 2015-10-17 19:35:02 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-10-17 19:35:02 +0200 |
commit | 5f77d4d1242e7ef64a3895492a9fe8f9bc38c78f (patch) | |
tree | f3cdf3e3ed60dd9aaae8bd2337019fa69cf027f1 /src/main/java/eu/siacs/conversations/ui | |
parent | 5dc0b7df6a81a6dee2baf468ed3442527fe730de (diff) | |
parent | 3c6c424d31be3e21d1bebd6288646f1cbc6881d9 (diff) |
copy commits
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
4 files changed, 70 insertions, 42 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index c610d2c89..aff50502c 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -35,6 +35,7 @@ import java.util.List; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; +import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.ListItem; @@ -479,7 +480,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd } @Override - public void onKeyStatusUpdated() { + public void onKeyStatusUpdated(AxolotlService.FetchStatus report) { refreshUi(); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 3a52cf36c..16ccceb28 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -489,7 +489,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa || m.treatAsDownloadable() == Message.Decision.MUST) { copyUrl.setVisible(true); } - if (m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) { + if ((m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) + || (m.isFileOrImage() && m.getTransferable() instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){ downloadFile.setVisible(true); downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m))); } diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 2ab60800d..1712a717c 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -708,7 +708,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } @Override - public void onKeyStatusUpdated() { + public void onKeyStatusUpdated(AxolotlService.FetchStatus report) { refreshUi(); } diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index ab3130748..4bd0d42da 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -8,6 +8,7 @@ import android.widget.Button; import android.widget.CompoundButton; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import org.whispersystems.libaxolotl.IdentityKey; @@ -16,10 +17,10 @@ import java.util.Map; import java.util.Set; import eu.siacs.conversations.R; +import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; -import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -27,11 +28,9 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdated { private Jid accountJid; private Jid contactJid; - private boolean hasOtherTrustedKeys = false; - private boolean hasPendingFetches = false; - private boolean hasNoTrustedKeys = true; private Contact contact; + private Account mAccount; private TextView keyErrorMessage; private LinearLayout keyErrorMessageCard; private TextView ownKeysTitle; @@ -50,10 +49,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate @Override public void onClick(View v) { commitTrusts(); - Intent data = new Intent(); - data.putExtra("choice", getIntent().getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID)); - setResult(RESULT_OK, data); - finish(); + finishOk(); } }; @@ -92,7 +88,6 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact")); } catch (final InvalidJidException ignored) { } - hasNoTrustedKeys = getIntent().getBooleanExtra("has_no_trusted", false); keyErrorMessageCard = (LinearLayout) findViewById(R.id.key_error_message_card); keyErrorMessage = (TextView) findViewById(R.id.key_error_message); @@ -157,11 +152,11 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate foreignKeysTitle.setText(contactJid.toString()); foreignKeysCard.setVisibility(View.VISIBLE); } - if(hasPendingFetches) { + if(hasPendingKeyFetches()) { setFetching(); lock(); } else { - if (!hasForeignKeys && !hasOtherTrustedKeys) { + if (!hasForeignKeys && hasNoOtherTrustedKeys()) { keyErrorMessageCard.setVisibility(View.VISIBLE); keyErrorMessage.setText(R.string.error_no_keys_to_trust); ownKeys.removeAllViews(); ownKeysCard.setVisibility(View.GONE); @@ -172,12 +167,14 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate } } - private void getFingerprints(final Account account) { - Set<IdentityKey> ownKeysSet = account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED); - Set<IdentityKey> foreignKeysSet = account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, contact); - if (hasNoTrustedKeys) { - ownKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED)); - foreignKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, contact)); + private boolean reloadFingerprints() { + ownKeysToTrust.clear(); + foreignKeysToTrust.clear(); + AxolotlService service = this.mAccount.getAxolotlService(); + Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED); + Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, contact); + if (hasNoOtherTrustedKeys() && ownKeysSet.size() == 0) { + foreignKeysSet.addAll(service.getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, contact)); } for(final IdentityKey identityKey : ownKeysSet) { if(!ownKeysToTrust.containsKey(identityKey)) { @@ -189,39 +186,68 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate foreignKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false); } } + return ownKeysSet.size() + foreignKeysSet.size() > 0; } @Override public void onBackendConnected() { if ((accountJid != null) && (contactJid != null)) { - final Account account = xmppConnectionService - .findAccountByJid(accountJid); - if (account == null) { + this.mAccount = xmppConnectionService.findAccountByJid(accountJid); + if (this.mAccount == null) { return; } - this.contact = account.getRoster().getContact(contactJid); - ownKeysToTrust.clear(); - foreignKeysToTrust.clear(); - getFingerprints(account); - - if(account.getAxolotlService().getNumTrustedKeys(contact) > 0) { - hasOtherTrustedKeys = true; - } - Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false); - if(account.getAxolotlService().hasPendingKeyFetches(conversation)) { - hasPendingFetches = true; - } - + this.contact = this.mAccount.getRoster().getContact(contactJid); + reloadFingerprints(); populateView(); } } + private boolean hasNoOtherTrustedKeys() { + return mAccount == null || mAccount.getAxolotlService().getNumTrustedKeys(contact) == 0; + } + + private boolean hasPendingKeyFetches() { + return mAccount != null && contact != null && mAccount.getAxolotlService().hasPendingKeyFetches(mAccount,contact); + } + + @Override - public void onKeyStatusUpdated() { - final Account account = xmppConnectionService.findAccountByJid(accountJid); - hasPendingFetches = false; - getFingerprints(account); - refreshUi(); + public void onKeyStatusUpdated(final AxolotlService.FetchStatus report) { + if (report != null) { + runOnUiThread(new Runnable() { + @Override + public void run() { + switch (report) { + case ERROR: + Toast.makeText(TrustKeysActivity.this,R.string.error_fetching_omemo_key,Toast.LENGTH_SHORT).show(); + break; + case SUCCESS_VERIFIED: + Toast.makeText(TrustKeysActivity.this,R.string.verified_omemo_key_with_certificate,Toast.LENGTH_LONG).show(); + break; + } + } + }); + + } + boolean keysToTrust = reloadFingerprints(); + if (keysToTrust || hasPendingKeyFetches() || hasNoOtherTrustedKeys()) { + refreshUi(); + } else { + runOnUiThread(new Runnable() { + @Override + public void run() { + finishOk(); + } + }); + + } + } + + private void finishOk() { + Intent data = new Intent(); + data.putExtra("choice", getIntent().getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID)); + setResult(RESULT_OK, data); + finish(); } private void commitTrusts() { @@ -248,7 +274,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate } private void lockOrUnlockAsNeeded() { - if (!hasOtherTrustedKeys && !foreignKeysToTrust.values().contains(true)){ + if (hasNoOtherTrustedKeys() && !foreignKeysToTrust.values().contains(true)){ lock(); } else { unlock(); |