refactored how snackbar is displayed
This commit is contained in:
parent
ecbceae88b
commit
e1e09d5cba
|
@ -99,7 +99,6 @@ public class ConversationFragment extends Fragment {
|
||||||
protected ListView messagesView;
|
protected ListView messagesView;
|
||||||
final protected List<Message> messageList = new ArrayList<>();
|
final protected List<Message> messageList = new ArrayList<>();
|
||||||
protected MessageAdapter messageListAdapter;
|
protected MessageAdapter messageListAdapter;
|
||||||
protected Contact contact;
|
|
||||||
private EditMessage mEditMessage;
|
private EditMessage mEditMessage;
|
||||||
private ImageButton mSendButton;
|
private ImageButton mSendButton;
|
||||||
private RelativeLayout snackbar;
|
private RelativeLayout snackbar;
|
||||||
|
@ -196,6 +195,7 @@ public class ConversationFragment extends Fragment {
|
||||||
askForPassphraseIntent,
|
askForPassphraseIntent,
|
||||||
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
||||||
0, 0);
|
0, 0);
|
||||||
|
askForPassphraseIntent = null;
|
||||||
} catch (SendIntentException e) {
|
} catch (SendIntentException e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -585,18 +585,7 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMessages() {
|
private OnClickListener mUnblockClickListener = new OnClickListener() {
|
||||||
synchronized (this.messageList) {
|
|
||||||
if (getView() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hideSnackbar();
|
|
||||||
final ConversationActivity activity = (ConversationActivity) getActivity();
|
|
||||||
if (this.conversation != null) {
|
|
||||||
final Contact contact = this.conversation.getContact();
|
|
||||||
if (this.conversation.isBlocked()) {
|
|
||||||
showSnackbar(R.string.contact_blocked, R.string.unblock,
|
|
||||||
new OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
v.post(new Runnable() {
|
v.post(new Runnable() {
|
||||||
|
@ -606,67 +595,117 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (conversation.isDomainBlocked()) {
|
if (conversation.isDomainBlocked()) {
|
||||||
BlockContactDialog.show(getActivity(), ((ConversationActivity) getActivity()).xmppConnectionService, conversation);
|
BlockContactDialog.show(activity, activity.xmppConnectionService, conversation);
|
||||||
} else {
|
} else {
|
||||||
((ConversationActivity) getActivity()).unblockConversation(conversation);
|
activity.unblockConversation(conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
} else if (!contact.showInRoster()
|
|
||||||
&& contact
|
private OnClickListener mAddBackClickListener = new OnClickListener() {
|
||||||
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
||||||
showSnackbar(R.string.contact_added_you, R.string.add_back,
|
|
||||||
new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
activity.xmppConnectionService
|
final Contact contact = conversation == null ? null :conversation.getContact();
|
||||||
.createContact(contact);
|
if (contact != null) {
|
||||||
|
activity.xmppConnectionService.createContact(contact);
|
||||||
activity.switchToContactDetails(contact);
|
activity.switchToContactDetails(contact);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
||||||
makeFingerprintWarning();
|
|
||||||
} else if (!conversation.getMucOptions().online()
|
|
||||||
&& conversation.getAccount().getStatus() == Account.State.ONLINE) {
|
|
||||||
int error = conversation.getMucOptions().getError();
|
|
||||||
switch (error) {
|
|
||||||
case MucOptions.ERROR_NICK_IN_USE:
|
|
||||||
showSnackbar(R.string.nick_in_use, R.string.edit,
|
|
||||||
clickToMuc);
|
|
||||||
break;
|
|
||||||
case MucOptions.ERROR_UNKNOWN:
|
|
||||||
showSnackbar(R.string.conference_not_found,
|
|
||||||
R.string.leave, leaveMuc);
|
|
||||||
break;
|
|
||||||
case MucOptions.ERROR_PASSWORD_REQUIRED:
|
|
||||||
showSnackbar(R.string.conference_requires_password,
|
|
||||||
R.string.enter_password, enterPassword);
|
|
||||||
break;
|
|
||||||
case MucOptions.ERROR_BANNED:
|
|
||||||
showSnackbar(R.string.conference_banned,
|
|
||||||
R.string.leave, leaveMuc);
|
|
||||||
break;
|
|
||||||
case MucOptions.ERROR_MEMBERS_ONLY:
|
|
||||||
showSnackbar(R.string.conference_members_only,
|
|
||||||
R.string.leave, leaveMuc);
|
|
||||||
break;
|
|
||||||
case MucOptions.KICKED_FROM_ROOM:
|
|
||||||
showSnackbar(R.string.conference_kicked, R.string.join,
|
|
||||||
joinMuc);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if (this.conversation.isMuted()) {
|
};
|
||||||
showSnackbar(R.string.notifications_disabled, R.string.enable,
|
|
||||||
new OnClickListener() {
|
private OnClickListener mUnmuteClickListener = new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
activity.unmuteConversation(conversation);
|
activity.unmuteConversation(conversation);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
private OnClickListener mAnswerSmpClickListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
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("mode",VerifyOTRActivity.MODE_ANSWER_QUESTION);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void updateSnackBar(final Conversation conversation) {
|
||||||
|
final Account account = conversation.getAccount();
|
||||||
|
final Contact contact = conversation.getContact();
|
||||||
|
final int mode = conversation.getMode();
|
||||||
|
if (conversation.isBlocked()) {
|
||||||
|
showSnackbar(R.string.contact_blocked, R.string.unblock,this.mUnblockClickListener);
|
||||||
|
} else if (!contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
||||||
|
showSnackbar(R.string.contact_added_you, R.string.add_back,this.mAddBackClickListener);
|
||||||
|
} else if (mode == Conversation.MODE_MULTI
|
||||||
|
&&!conversation.getMucOptions().online()
|
||||||
|
&& account.getStatus() == Account.State.ONLINE) {
|
||||||
|
switch (conversation.getMucOptions().getError()) {
|
||||||
|
case MucOptions.ERROR_NICK_IN_USE:
|
||||||
|
showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
|
||||||
|
break;
|
||||||
|
case MucOptions.ERROR_UNKNOWN:
|
||||||
|
showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc);
|
||||||
|
break;
|
||||||
|
case MucOptions.ERROR_PASSWORD_REQUIRED:
|
||||||
|
showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
|
||||||
|
break;
|
||||||
|
case MucOptions.ERROR_BANNED:
|
||||||
|
showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
|
||||||
|
break;
|
||||||
|
case MucOptions.ERROR_MEMBERS_ONLY:
|
||||||
|
showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
|
||||||
|
break;
|
||||||
|
case MucOptions.KICKED_FROM_ROOM:
|
||||||
|
showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (askForPassphraseIntent != null ) {
|
||||||
|
showSnackbar(R.string.openpgp_messages_found,R.string.decrypt, clickToDecryptListener);
|
||||||
|
} else if (mode == Conversation.MODE_SINGLE
|
||||||
|
&& conversation.smpRequested()) {
|
||||||
|
showSnackbar(R.string.smp_requested, R.string.verify,this.mAnswerSmpClickListener);
|
||||||
|
} else if (mode == Conversation.MODE_SINGLE
|
||||||
|
&&conversation.hasValidOtrSession()
|
||||||
|
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
|
||||||
|
&& (!conversation.isOtrFingerprintVerified())) {
|
||||||
|
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
|
||||||
|
} else if (conversation.isMuted()) {
|
||||||
|
showSnackbar(R.string.notifications_disabled, R.string.enable,this.mUnmuteClickListener);
|
||||||
|
} else {
|
||||||
|
hideSnackbar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMessages() {
|
||||||
|
synchronized (this.messageList) {
|
||||||
|
if (getView() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
||||||
|
if (this.conversation != null) {
|
||||||
|
updateSnackBar(this.conversation);
|
||||||
|
final Contact contact = this.conversation.getContact();
|
||||||
|
if (this.conversation.isBlocked()) {
|
||||||
|
|
||||||
|
} else if (!contact.showInRoster()
|
||||||
|
&& contact
|
||||||
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
||||||
|
|
||||||
|
} else if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
|
makeFingerprintWarning();
|
||||||
|
} else if (!conversation.getMucOptions().online()
|
||||||
|
&& conversation.getAccount().getStatus() == Account.State.ONLINE) {
|
||||||
|
|
||||||
|
} else if (this.conversation.isMuted()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
||||||
for (final Message message : this.messageList) {
|
for (final Message message : this.messageList) {
|
||||||
|
@ -703,8 +742,7 @@ public class ConversationFragment extends Fragment {
|
||||||
public void userInputRequried(PendingIntent pi, Message message) {
|
public void userInputRequried(PendingIntent pi, Message message) {
|
||||||
mDecryptJobRunning = false;
|
mDecryptJobRunning = false;
|
||||||
askForPassphraseIntent = pi.getIntentSender();
|
askForPassphraseIntent = pi.getIntentSender();
|
||||||
showSnackbar(R.string.openpgp_messages_found,
|
updateSnackBar(conversation);
|
||||||
R.string.decrypt, clickToDecryptListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -807,22 +845,7 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void makeFingerprintWarning() {
|
protected void makeFingerprintWarning() {
|
||||||
if (conversation.smpRequested()) {
|
|
||||||
showSnackbar(R.string.smp_requested, R.string.verify, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
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("mode",VerifyOTRActivity.MODE_ANSWER_QUESTION);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
|
|
||||||
&& (!conversation.isOtrFingerprintVerified())) {
|
|
||||||
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showSnackbar(final int message, final int action,
|
protected void showSnackbar(final int message, final int action,
|
||||||
|
|
Loading…
Reference in New Issue