added snackbar to indicate smp. more error handling in verify activity

This commit is contained in:
iNPUTmice 2014-11-10 22:03:23 +01:00
parent 8740b55d37
commit dc98b3dbd5
5 changed files with 158 additions and 113 deletions

View file

@ -417,6 +417,10 @@ public class Conversation extends AbstractEntity {
} }
} }
public boolean smpRequested() {
return smp().status == Smp.STATUS_CONTACT_REQUESTED;
}
public void setNextMessage(String message) { public void setNextMessage(String message) {
this.nextMessage = message; this.nextMessage = message;
} }

View file

@ -35,7 +35,6 @@ import net.java.otr4j.session.SessionStatus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
@ -53,7 +52,6 @@ import eu.siacs.conversations.ui.XmppActivity.OnValueEdited;
import eu.siacs.conversations.ui.adapter.MessageAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
public class ConversationFragment extends Fragment { public class ConversationFragment extends Fragment {
@ -146,6 +144,19 @@ public class ConversationFragment extends Fragment {
} }
} }
}; };
protected OnClickListener clickToVerify = new OnClickListener() {
@Override
public void onClick(View v) {
if (conversation.getOtrFingerprint() != null) {
Intent intent = new Intent(getActivity(), VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
startActivity(intent);
}
}
};
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>();
private boolean mDecryptJobRunning = false; private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() { private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@ -505,33 +516,9 @@ public class ConversationFragment extends Fragment {
activity.switchToContactDetails(contact); activity.switchToContactDetails(contact);
} }
}); });
} } else if (conversation.getMode() == Conversation.MODE_SINGLE) {
for (Message message : this.conversation.getMessages()) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message
.getStatus() >= Message.STATUS_SEND)
&& message.getDownloadable() == null) {
if (!mEncryptedMessages.contains(message)) {
mEncryptedMessages.add(message);
}
}
}
decryptNext();
this.messageList.clear();
if (this.conversation.getMessages().size() == 0) {
messagesLoaded = false;
} else {
this.messageList.addAll(this.conversation.getMessages());
messagesLoaded = true;
updateStatusMessages();
}
this.messageListAdapter.notifyDataSetChanged();
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (messageList.size() >= 1) {
makeFingerprintWarning(); makeFingerprintWarning();
} } else if (!conversation.getMucOptions().online()
} else {
if (!conversation.getMucOptions().online()
&& conversation.getAccount().getStatus() == Account.STATUS_ONLINE) { && conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
int error = conversation.getMucOptions().getError(); int error = conversation.getMucOptions().getError();
switch (error) { switch (error) {
@ -563,7 +550,26 @@ public class ConversationFragment extends Fragment {
break; break;
} }
} }
for (Message message : this.conversation.getMessages()) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message
.getStatus() >= Message.STATUS_SEND)
&& message.getDownloadable() == null) {
if (!mEncryptedMessages.contains(message)) {
mEncryptedMessages.add(message);
} }
}
}
decryptNext();
this.messageList.clear();
if (this.conversation.getMessages().size() == 0) {
messagesLoaded = false;
} else {
this.messageList.addAll(this.conversation.getMessages());
messagesLoaded = true;
updateStatusMessages();
}
this.messageListAdapter.notifyDataSetChanged();
updateChatMsgHint(); updateChatMsgHint();
if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) { if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) {
activity.xmppConnectionService.markRead(conversation, true); activity.xmppConnectionService.markRead(conversation, true);
@ -680,24 +686,11 @@ public class ConversationFragment extends Fragment {
} }
protected void makeFingerprintWarning() { protected void makeFingerprintWarning() {
if (conversation.hasValidOtrSession() if (conversation.smpRequested()) {
&& (!conversation.isMuted()) showSnackbar(R.string.smp_requested, R.string.verify, clickToVerify);
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) } else if (conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
&& (!conversation.isOtrFingerprintVerified())) { && (!conversation.isOtrFingerprintVerified())) {
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
new OnClickListener() {
@Override
public void onClick(View v) {
if (conversation.getOtrFingerprint() != null) {
Intent intent = new Intent(getActivity(),VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact",conversation.getContact().getJid().toBareJid().toString());
intent.putExtra("account",conversation.getAccount().getJid().toBareJid().toString());
startActivity(intent);
}
}
});
} }
} }

View file

@ -7,6 +7,7 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -27,6 +28,9 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
public static final String ACTION_VERIFY_CONTACT = "verify_contact"; public static final String ACTION_VERIFY_CONTACT = "verify_contact";
private RelativeLayout mVerificationAreaOne;
private RelativeLayout mVerificationAreaTwo;
private TextView mErrorNoSession;
private TextView mRemoteJid; private TextView mRemoteJid;
private TextView mRemoteFingerprint; private TextView mRemoteFingerprint;
private TextView mYourFingerprint; private TextView mYourFingerprint;
@ -38,6 +42,16 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
private TextView mStatusMessage; private TextView mStatusMessage;
private Account mAccount; private Account mAccount;
private Conversation mConversation; private Conversation mConversation;
private View.OnClickListener mVerifyFingerprintListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
mConversation.verifyOtrFingerprint();
finish();
}
};
private View.OnClickListener mCreateSharedSecretListener = new View.OnClickListener() { private View.OnClickListener mCreateSharedSecretListener = new View.OnClickListener() {
@Override @Override
public void onClick(final View view) { public void onClick(final View view) {
@ -53,6 +67,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
@Override @Override
public void onClick(View view) { public void onClick(View view) {
abortSmp(); abortSmp();
updateView();
} }
}; };
private View.OnClickListener mRespondSharedSecretListener = new View.OnClickListener() { private View.OnClickListener mRespondSharedSecretListener = new View.OnClickListener() {
@ -103,6 +118,8 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
try { try {
session.abortSmp(); session.abortSmp();
mConversation.smp().status = Conversation.Smp.STATUS_NONE; mConversation.smp().status = Conversation.Smp.STATUS_NONE;
mConversation.smp().hint = null;
mConversation.smp().secret = null;
return true; return true;
} catch (OtrException e) { } catch (OtrException e) {
return false; return false;
@ -156,11 +173,20 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
} }
protected void updateView() { protected void updateView() {
if (this.mConversation.hasValidOtrSession()) {
this.mVerificationAreaOne.setVisibility(View.VISIBLE);
this.mVerificationAreaTwo.setVisibility(View.VISIBLE);
this.mErrorNoSession.setVisibility(View.GONE);
this.mYourFingerprint.setText(this.mAccount.getOtrFingerprint(xmppConnectionService)); this.mYourFingerprint.setText(this.mAccount.getOtrFingerprint(xmppConnectionService));
this.mRemoteFingerprint.setText(this.mConversation.getOtrFingerprint()); this.mRemoteFingerprint.setText(this.mConversation.getOtrFingerprint());
this.mRemoteJid.setText(this.mConversation.getContact().getJid().toBareJid().toString()); this.mRemoteJid.setText(this.mConversation.getContact().getJid().toBareJid().toString());
Conversation.Smp smp = mConversation.smp(); Conversation.Smp smp = mConversation.smp();
Session session = mConversation.getOtrSession(); Session session = mConversation.getOtrSession();
if (mConversation.isOtrFingerprintVerified()) {
deactivateButton(mButtonVerifyFingerprint, R.string.verified);
} else {
activateButton(mButtonVerifyFingerprint, R.string.verify, mVerifyFingerprintListener);
}
if (smp.status == Conversation.Smp.STATUS_NONE) { if (smp.status == Conversation.Smp.STATUS_NONE) {
activateButton(mButtonSharedSecretPositive, R.string.create, mCreateSharedSecretListener); activateButton(mButtonSharedSecretPositive, R.string.create, mCreateSharedSecretListener);
deactivateButton(mButtonSharedSecretNegative, R.string.cancel); deactivateButton(mButtonSharedSecretNegative, R.string.cancel);
@ -197,13 +223,18 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
deactivateButton(mButtonSharedSecretNegative, R.string.cancel); deactivateButton(mButtonSharedSecretNegative, R.string.cancel);
activateButton(mButtonSharedSecretPositive, R.string.finish, mFinishListener); activateButton(mButtonSharedSecretPositive, R.string.finish, mFinishListener);
} else if (session != null && session.isSmpInProgress()) { } else if (session != null && session.isSmpInProgress()) {
deactivateButton(mButtonSharedSecretPositive,R.string.in_progress); deactivateButton(mButtonSharedSecretPositive, R.string.in_progress);
activateButton(mButtonSharedSecretNegative,R.string.cancel,mCancelSharedSecretListener); activateButton(mButtonSharedSecretNegative, R.string.cancel, mCancelSharedSecretListener);
this.mSharedSecretHint.setVisibility(View.VISIBLE); this.mSharedSecretHint.setVisibility(View.VISIBLE);
this.mSharedSecretSecret.setVisibility(View.VISIBLE); this.mSharedSecretSecret.setVisibility(View.VISIBLE);
this.mSharedSecretHint.setFocusable(false); this.mSharedSecretHint.setFocusable(false);
this.mSharedSecretSecret.setFocusable(false); this.mSharedSecretSecret.setFocusable(false);
} }
} else {
this.mVerificationAreaOne.setVisibility(View.GONE);
this.mVerificationAreaTwo.setVisibility(View.GONE);
this.mErrorNoSession.setVisibility(View.VISIBLE);
}
} }
protected void activateButton(Button button, int text, View.OnClickListener listener) { protected void activateButton(Button button, int text, View.OnClickListener listener) {
@ -233,6 +264,9 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
this.mSharedSecretSecret = (EditText) findViewById(R.id.shared_secret_secret); this.mSharedSecretSecret = (EditText) findViewById(R.id.shared_secret_secret);
this.mSharedSecretHint = (EditText) findViewById(R.id.shared_secret_hint); this.mSharedSecretHint = (EditText) findViewById(R.id.shared_secret_hint);
this.mStatusMessage= (TextView) findViewById(R.id.status_message); this.mStatusMessage= (TextView) findViewById(R.id.status_message);
this.mVerificationAreaOne = (RelativeLayout) findViewById(R.id.verification_area_one);
this.mVerificationAreaTwo = (RelativeLayout) findViewById(R.id.verification_area_two);
this.mErrorNoSession = (TextView) findViewById(R.id.error_no_session);
} }
@Override @Override

View file

@ -8,7 +8,18 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/error_no_session"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_otr_session_found"
android:layout_gravity="center_horizontal"
android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody"
/>
<RelativeLayout <RelativeLayout
android:id="@+id/verification_area_one"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/infocard_border" android:background="@drawable/infocard_border"
@ -90,6 +101,7 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/verification_area_two"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"

View file

@ -326,4 +326,6 @@
<string name="try_again">Try again</string>; <string name="try_again">Try again</string>;
<string name="finish">Finish</string> <string name="finish">Finish</string>
<string name="verified">Verified!</string> <string name="verified">Verified!</string>
<string name="smp_requested">Contact requested SMP verification</string>
<string name="no_otr_session_found">No valid OTR session has been found!</string>
</resources> </resources>