diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
5 files changed, 54 insertions, 34 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java index bf33c35d9..9cc0a4ddf 100644 --- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java +++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java @@ -15,6 +15,7 @@ import android.widget.Toast; import de.pixart.messenger.R; import de.pixart.messenger.entities.Blockable; +import de.pixart.messenger.entities.Conversation; public final class BlockContactDialog { public static void show(final XmppActivity xmppActivity, @@ -37,7 +38,8 @@ public final class BlockContactDialog { value = blockable.getJid().toDomainJid().toString(); spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value)); } else { - builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact); + int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact; + builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction); value = blockable.getJid().toBareJid().toString(); spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value)); } diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 6270e4721..b0fd4cd79 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -49,6 +49,7 @@ import de.pixart.messenger.entities.ListItem; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.utils.CryptoHelper; +import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; @@ -516,7 +517,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp lastseen.setVisibility(View.VISIBLE); lastseen.setText(R.string.contact_blocked); } else { - if (showLastSeen && contact.getLastseen() > 0) { + if (showLastSeen + && contact.getLastseen() > 0 + && contact.getPresences().allOrNonSupport(Namespace.IDLE)) { lastseen.setVisibility(View.VISIBLE); lastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen())); } else { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index efffb1d32..784f2e3ce 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -2016,9 +2016,12 @@ public class ConversationActivity extends XmppActivity public void success(Message message) { message.setEncryption(Message.ENCRYPTION_DECRYPTED); xmppConnectionService.sendMessage(message); - if (mConversationFragment != null) { - mConversationFragment.messageSent(); - } + runOnUiThread(new Runnable() { + @Override + public void run() { + mConversationFragment.messageSent(); + } + }); } @Override @@ -2026,15 +2029,13 @@ public class ConversationActivity extends XmppActivity runOnUiThread(new Runnable() { @Override public void run() { + mConversationFragment.doneSendingPgpMessage(); Toast.makeText(ConversationActivity.this, R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT ).show(); } }); - if (mConversationFragment != null) { - mConversationFragment.doneSendingPgpMessage(); - } } }); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index b52c94753..fc735785c 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -9,10 +9,8 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender.SendIntentException; -import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; import android.support.v13.view.inputmethod.InputConnectionCompat; import android.support.v13.view.inputmethod.InputContentInfoCompat; import android.text.Editable; @@ -36,6 +34,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ImageButton; import android.widget.ListView; +import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; @@ -55,6 +54,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; +import de.pixart.messenger.entities.Blockable; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.DownloadableFile; @@ -355,8 +355,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa case CANCEL: if (conversation != null) { if (conversation.setCorrectingMessage(null)) { - mEditMessage.getEditableText().clear(); - mEditMessage.getEditableText().append(conversation.getDraftMessage()); + mEditMessage.setText(""); + mEditMessage.append(conversation.getDraftMessage()); conversation.setDraftMessage(null); } else if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.setNextCounterpart(null); @@ -848,8 +848,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa Transferable transferable = message.getTransferable(); if (transferable != null) { transferable.cancel(); - } else { - activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); } } @@ -864,7 +862,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) { activity.xmppConnectionService.sendChatState(conversation); } - this.mEditMessage.getEditableText().clear(); + this.mEditMessage.setText(""); this.conversation.setNextCounterpart(counterpart); updateChatMsgHint(); updateSendButton(); @@ -877,8 +875,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa this.conversation.setCorrectingMessage(message); final Editable editable = mEditMessage.getText(); this.conversation.setDraftMessage(editable.toString()); - this.mEditMessage.getEditableText().clear(); - this.mEditMessage.getEditableText().append(message.getBody()); + this.mEditMessage.setText(""); + this.mEditMessage.append(message.getBody()); } @@ -992,8 +990,30 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private OnClickListener mBlockClickListener = new OnClickListener() { @Override - public void onClick(final View v) { - BlockContactDialog.show(activity, conversation); + public void onClick(final View view) { + final Jid jid = conversation.getJid(); + if (jid.isDomainJid()) { + BlockContactDialog.show(activity, conversation); + } else { + PopupMenu popupMenu = new PopupMenu(activity, view); + popupMenu.inflate(R.menu.block); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + Blockable blockable; + switch (menuItem.getItemId()) { + case R.id.block_domain: + blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid()); + break; + default: + blockable = conversation; + } + BlockContactDialog.show(activity, blockable); + return true; + } + }); + popupMenu.show(); + } } }; @@ -1036,6 +1056,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private void updateSnackBar(final Conversation conversation) { final Account account = conversation.getAccount(); + final XmppConnection connection = account.getXmppConnection(); final Contact contact = conversation.getContact(); final int mode = conversation.getMode(); if (account.getStatus() == Account.State.DISABLED) { @@ -1091,7 +1112,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!conversation.isOtrFingerprintVerified())) { showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify); - } else if (conversation.countMessages() != 0 + } else if (connection != null + && connection.getFeatures().blocking() + && conversation.countMessages() != 0 && !conversation.isBlocked() && conversation.isWithStranger()) { showSnackbar(R.string.received_message_from_stranger, R.string.block, mBlockClickListener); @@ -1122,10 +1145,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } protected void messageSent() { - Editable editable = mEditMessage.getEditableText(); - editable.clear(); + mEditMessage.setText(""); if (conversation.setCorrectingMessage(null)) { - editable.append(conversation.getDraftMessage()); + mEditMessage.append(conversation.getDraftMessage()); conversation.setDraftMessage(null); } updateChatMsgHint(); @@ -1519,7 +1541,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa @Override public void onTypingStarted() { - final boolean broadcastLastActivity = broadcastLastActivity(); + final boolean broadcastLastActivity = activity.xmppConnectionService.broadcastLastActivity(); Account.State status = conversation.getAccount().getStatus(); if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.COMPOSING)) { activity.xmppConnectionService.sendChatState(conversation); @@ -1531,15 +1553,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa updateSendButton(); } - public boolean broadcastLastActivity() { - return getPreferences().getBoolean("last_activity", true); - } - - public SharedPreferences getPreferences() { - return PreferenceManager - .getDefaultSharedPreferences(getActivity().getApplicationContext()); - } - @Override public void onTypingStopped() { Account.State status = conversation.getAccount().getStatus(); diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 6624266f7..61cf0a4af 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -41,6 +41,7 @@ public class SettingsActivity extends XmppActivity implements public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence"; public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv"; public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion"; + public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; private SettingsFragment mSettingsFragment; @@ -231,7 +232,7 @@ public class SettingsActivity extends XmppActivity implements "allow_message_correction", TREAT_VIBRATE_AS_SILENT, MANUALLY_CHANGE_PRESENCE, - "last_activity"); + BROADCAST_LAST_ACTIVITY); if (name.equals("resource")) { String resource = preferences.getString("resource", "mobile") .toLowerCase(Locale.US); |