From 6e3e1d310aafddd9ddf9fc09c23df2d13f760dfd Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 9 Jul 2014 21:45:03 +0200 Subject: unified warnings/error msgs --- .../conversations/ui/ConversationActivity.java | 2 +- .../conversations/ui/ConversationFragment.java | 54 ++++++++++------------ src/eu/siacs/conversations/utils/UIHelper.java | 2 +- 3 files changed, 26 insertions(+), 32 deletions(-) (limited to 'src/eu/siacs') diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 03ced289..c11e1d65 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -768,7 +768,7 @@ public class ConversationActivity extends XmppActivity { ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() .findFragmentByTag("conversation"); if (selectedFragment != null) { - selectedFragment.hidePgpPassphraseBox(); + selectedFragment.hideSnackbar(); } } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { attachImageToConversation(getSelectedConversation(), diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 300b6c4c..01bab773 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -48,6 +48,7 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -68,6 +69,9 @@ public class ConversationFragment extends Fragment { private EditText chatMsg; private String pastedText = null; + private RelativeLayout snackbar; + private TextView snackbarMessage; + private TextView snackbarAction; protected Bitmap selfBitmap; @@ -109,10 +113,7 @@ public class ConversationFragment extends Fragment { } } }; - - private LinearLayout pgpInfo; - private LinearLayout mucError; - private TextView mucErrorText; + private OnClickListener clickToMuc = new OnClickListener() { @Override @@ -152,10 +153,6 @@ public class ConversationFragment extends Fragment { private ConversationActivity activity; - public void hidePgpPassphraseBox() { - pgpInfo.setVisibility(View.GONE); - } - public void updateChatMsgHint() { switch (conversation.getNextEncryption()) { case Message.ENCRYPTION_NONE: @@ -191,11 +188,9 @@ public class ConversationFragment extends Fragment { .findViewById(R.id.textSendButton); sendButton.setOnClickListener(this.sendMsgListener); - pgpInfo = (LinearLayout) view.findViewById(R.id.pgp_keyentry); - pgpInfo.setOnClickListener(clickToDecryptListener); - mucError = (LinearLayout) view.findViewById(R.id.muc_error); - mucError.setOnClickListener(clickToMuc); - mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg); + snackbar = (RelativeLayout) view.findViewById(R.id.snackbar); + snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message); + snackbarAction = (TextView) view.findViewById(R.id.snackbar_action); messagesView = (ListView) view.findViewById(R.id.messages_view); messagesView.setOnScrollListener(mOnScrollListener); @@ -688,7 +683,7 @@ public class ConversationFragment extends Fragment { @Override public void userInputRequried(PendingIntent pi, Message message) { askForPassphraseIntent = pi.getIntentSender(); - pgpInfo.setVisibility(View.VISIBLE); + showSnackbar(R.string.openpgp_messages_found,R.string.decrypt,clickToDecryptListener); } @Override @@ -704,8 +699,6 @@ public class ConversationFragment extends Fragment { // updateMessages(); } }); - } else { - pgpInfo.setVisibility(View.GONE); } } @@ -742,12 +735,10 @@ public class ConversationFragment extends Fragment { } } else { if (conversation.getMucOptions().getError() != 0) { - mucError.setVisibility(View.VISIBLE); + showSnackbar(R.string.nick_in_use, R.string.edit,clickToMuc); if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) { - mucErrorText.setText(getString(R.string.nick_in_use)); + showSnackbar(R.string.nick_in_use, R.string.edit,clickToMuc); } - } else { - mucError.setVisibility(View.GONE); } } getActivity().invalidateOptionsMenu(); @@ -795,34 +786,37 @@ public class ConversationFragment extends Fragment { } protected void makeFingerprintWarning(int latestEncryption) { - final LinearLayout fingerprintWarning = (LinearLayout) getView() - .findViewById(R.id.new_fingerprint); Set knownFingerprints = conversation.getContact() .getOtrFingerprints(); if ((latestEncryption == Message.ENCRYPTION_OTR) && (conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!knownFingerprints .contains(conversation.getOtrFingerprint())))) { - fingerprintWarning.setVisibility(View.VISIBLE); - TextView fingerprint = (TextView) getView().findViewById( - R.id.otr_fingerprint); - fingerprint.setText(conversation.getOtrFingerprint()); - fingerprintWarning.setOnClickListener(new OnClickListener() { + showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, new OnClickListener() { @Override public void onClick(View v) { if (conversation.getOtrFingerprint() != null) { AlertDialog dialog = UIHelper.getVerifyFingerprintDialog( (ConversationActivity) getActivity(), conversation, - fingerprintWarning); + snackbar); dialog.show(); } } }); - } else { - fingerprintWarning.setVisibility(View.GONE); } } + + protected void showSnackbar(int message, int action, OnClickListener clickListener) { + snackbar.setVisibility(View.VISIBLE); + snackbarMessage.setText(message); + snackbarAction.setText(action); + snackbarAction.setOnClickListener(clickListener); + } + + protected void hideSnackbar() { + snackbar.setVisibility(View.GONE); + } protected void sendPlainTextMessage(Message message) { ConversationActivity activity = (ConversationActivity) getActivity(); diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index ddd5e1be..7f24943f 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -492,7 +492,7 @@ public class UIHelper { public static AlertDialog getVerifyFingerprintDialog( final ConversationActivity activity, - final Conversation conversation, final LinearLayout msg) { + final Conversation conversation, final View msg) { final Contact contact = conversation.getContact(); final Account account = conversation.getAccount(); -- cgit v1.2.3