aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2015-08-11 20:30:11 +0200
committerlookshe <github@lookshe.org>2015-08-11 20:30:11 +0200
commit639babfdb5289a035e0a22bf607c068caefa5c99 (patch)
tree6a11aa6a189f3a5988d5d1e1c733d2027bc3494f /src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
parent1b5966ae3b1108c88a810d7d32a0aefa8812d11f (diff)
parent8fd688ca96005152be754eeba1be72c7c0aab9ad (diff)
Merge branch 'trz/rebase' into trz/rename
Conflicts: build.gradle src/main/java/de/thedevstack/conversationsplus/crypto/OtrEngine.java src/main/java/de/thedevstack/conversationsplus/entities/Account.java src/main/java/de/thedevstack/conversationsplus/entities/Contact.java src/main/java/de/thedevstack/conversationsplus/entities/Downloadable.java src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java src/main/java/de/thedevstack/conversationsplus/entities/DownloadablePlaceholder.java src/main/java/de/thedevstack/conversationsplus/entities/Message.java src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java src/main/java/de/thedevstack/conversationsplus/http/HttpConnection.java src/main/java/de/thedevstack/conversationsplus/http/HttpConnectionManager.java src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnectionManager.java src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleInbandTransport.java src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleSocks5Transport.java src/main/java/de/thedevstack/conversationsplus/xmpp/stanzas/MessagePacket.java src/main/java/eu/siacs/conversations/crypto/OtrEngine.java src/main/java/eu/siacs/conversations/crypto/OtrService.java src/main/java/eu/siacs/conversations/entities/DownloadablePlaceholder.java src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java src/main/java/eu/siacs/conversations/http/HttpConnection.java src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java src/main/res/layout/activity_about.xml
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java493
1 files changed, 308 insertions, 185 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index ea62a288..a30b3483 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -3,6 +3,7 @@ package de.thedevstack.conversationsplus.ui;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.PendingIntent;
+import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -36,7 +37,6 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
-import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -49,9 +49,9 @@ import de.thedevstack.conversationsplus.crypto.PgpEngine;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
-import de.thedevstack.conversationsplus.entities.Downloadable;
+import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
-import de.thedevstack.conversationsplus.entities.DownloadablePlaceholder;
+import de.thedevstack.conversationsplus.entities.TransferablePlaceholder;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.MucOptions;
import de.thedevstack.conversationsplus.entities.Presences;
@@ -62,8 +62,10 @@ import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureClicked;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import de.thedevstack.conversationsplus.utils.GeoHelper;
+import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import github.ankushsachdeva.emojicon.EmojiconEditText;
import github.ankushsachdeva.emojicon.EmojiconGridView;
import github.ankushsachdeva.emojicon.EmojiconsPopup;
import github.ankushsachdeva.emojicon.emoji.Emojicon;
@@ -126,16 +128,37 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
+ private int getIndexOf(String uuid, List<Message> messages) {
+ if (uuid == null) {
+ return 0;
+ }
+ for(int i = 0; i < messages.size(); ++i) {
+ if (uuid.equals(messages.get(i).getUuid())) {
+ return i;
+ } else {
+ Message next = messages.get(i);
+ while(next != null && next.wasMergedIntoPrevious()) {
+ if (uuid.equals(next.getUuid())) {
+ return i;
+ }
+ next = next.next();
+ }
+
+ }
+ }
+ return 0;
+ }
+
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
- int visibleItemCount, int totalItemCount) {
+ int visibleItemCount, int totalItemCount) {
synchronized (ConversationFragment.this.messageList) {
if (firstVisibleItem < 5 && messagesLoaded && messageList.size() > 0) {
long timestamp = ConversationFragment.this.messageList.get(0).getTimeSent();
messagesLoaded = false;
activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
@Override
- public void onMoreMessagesLoaded(final int count, Conversation conversation) {
+ public void onMoreMessagesLoaded(final int c, Conversation conversation) {
if (ConversationFragment.this.conversation != conversation) {
return;
}
@@ -143,29 +166,18 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void run() {
final int oldPosition = messagesView.getFirstVisiblePosition();
+ Message message = messageList.get(oldPosition);
+ String uuid = message != null ? message.getUuid() : null;
View v = messagesView.getChildAt(0);
final int pxOffset = (v == null) ? 0 : v.getTop();
ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
updateStatusMessages();
messageListAdapter.notifyDataSetChanged();
- if (count != 0) {
- final int newPosition = oldPosition + count;
- int offset = 0;
- try {
- Message tmpMessage = messageList.get(newPosition);
-
- while(tmpMessage.wasMergedIntoPrevious()) {
- offset++;
- tmpMessage = tmpMessage.prev();
- }
- } catch (final IndexOutOfBoundsException ignored) {
-
- }
- messagesView.setSelectionFromTop(newPosition - offset, pxOffset);
- messagesLoaded = true;
- if (messageLoaderToast != null) {
- messageLoaderToast.cancel();
- }
+ int pos = getIndexOf(uuid,messageList);
+ messagesView.setSelectionFromTop(pos, pxOffset);
+ messagesLoaded = true;
+ if (messageLoaderToast != null) {
+ messageLoaderToast.cancel();
}
}
});
@@ -183,7 +195,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (ConversationFragment.this.conversation != conversation) {
return;
}
- messageLoaderToast = Toast.makeText(activity,resId,Toast.LENGTH_LONG);
+ messageLoaderToast = Toast.makeText(activity, resId, Toast.LENGTH_LONG);
messageLoaderToast.show();
}
});
@@ -217,7 +229,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onClick(View v) {
- activity.verifyOtrSessionDialog(conversation,v);
+ activity.verifyOtrSessionDialog(conversation, v);
}
};
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>();
@@ -228,7 +240,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
InputMethodManager imm = (InputMethodManager) v.getContext()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
+ .getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
sendMessage();
return true;
@@ -241,15 +253,42 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onClick(View v) {
- sendMessage();
+ Object tag = v.getTag();
+ if (tag instanceof SendButtonAction) {
+ SendButtonAction action = (SendButtonAction) tag;
+ switch (action) {
+ case TAKE_PHOTO:
+ activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_TAKE_PHOTO);
+ break;
+ case SEND_LOCATION:
+ activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_LOCATION);
+ break;
+ case RECORD_VOICE:
+ activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_RECORD_VOICE);
+ break;
+ case CHOOSE_PICTURE:
+ activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_CHOOSE_IMAGE);
+ break;
+ case CANCEL:
+ if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
+ conversation.setNextCounterpart(null);
+ updateChatMsgHint();
+ updateSendButton();
+ }
+ break;
+ default:
+ sendMessage();
+ }
+ } else {
+ sendMessage();
+ }
}
};
private OnClickListener clickToMuc = new OnClickListener() {
@Override
public void onClick(View v) {
- Intent intent = new Intent(getActivity(),
- ConferenceDetailsActivity.class);
+ Intent intent = new Intent(getActivity(), ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
@@ -259,24 +298,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private Message selectedMessage;
private void sendMessage() {
- if (this.conversation == null) {
+ final String body = mEditMessage.getText().toString();
+ if (body.length() == 0 || this.conversation == null) {
return;
}
- if (mEditMessage.getText().length() < 1) {
- if (this.conversation.getMode() == Conversation.MODE_MULTI) {
- conversation.setNextCounterpart(null);
- updateChatMsgHint();
- }
- return;
- }
- Message message = new Message(conversation, mEditMessage.getText()
- .toString(), conversation.getNextEncryption(activity
- .forceEncryption()));
+ Message message = new Message(conversation, body, conversation.getNextEncryption(activity.forceEncryption()));
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_PRIVATE);
- conversation.setNextCounterpart(null);
}
}
if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_OTR) {
@@ -292,13 +322,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (conversation.getMode() == Conversation.MODE_MULTI
&& conversation.getNextCounterpart() != null) {
this.mEditMessage.setHint(getString(
- R.string.send_private_message_to,
- conversation.getNextCounterpart().getResourcepart()));
+ R.string.send_private_message_to,
+ conversation.getNextCounterpart().getResourcepart()));
} else {
switch (conversation.getNextEncryption(activity.forceEncryption())) {
case Message.ENCRYPTION_NONE:
mEditMessage
- .setHint(getString(R.string.send_plain_text_message));
+ .setHint(getString(R.string.send_plain_text_message));
break;
case Message.ENCRYPTION_OTR:
mEditMessage.setHint(getString(R.string.send_otr_message));
@@ -314,7 +344,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
private void setupIme() {
- if (((ConversationActivity)getActivity()).usingEnterKey()) {
+ if (((ConversationActivity) getActivity()).usingEnterKey()) {
mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
} else {
mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
@@ -323,9 +353,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public View onCreateView(final LayoutInflater inflater,
- ViewGroup container, Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.fragment_conversation,
- container, false);
+ ViewGroup container, Bundle savedInstanceState) {
+ final View view = inflater.inflate(R.layout.fragment_conversation, container, false);
+ view.setOnClickListener(null);
mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
setupIme();
mEditMessage.setOnClickListener(new OnClickListener() {
@@ -484,21 +514,21 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
});
messageListAdapter
- .setOnContactPictureLongClicked(new OnContactPictureLongClicked() {
-
- @Override
- public void onContactPictureLongClicked(Message message) {
- if (message.getStatus() <= Message.STATUS_RECEIVED) {
- if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
- if (message.getCounterpart() != null) {
- privateMessageWith(message.getCounterpart());
+ .setOnContactPictureLongClicked(new OnContactPictureLongClicked() {
+
+ @Override
+ public void onContactPictureLongClicked(Message message) {
+ if (message.getStatus() <= Message.STATUS_RECEIVED) {
+ if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
+ if (message.getCounterpart() != null) {
+ privateMessageWith(message.getCounterpart());
+ }
}
+ } else {
+ activity.showQrCode();
}
- } else {
- activity.showQrCode();
}
- }
- });
+ });
messagesView.setAdapter(messageListAdapter);
registerForContextMenu(messagesView);
@@ -508,7 +538,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
+ ContextMenuInfo menuInfo) {
synchronized (this.messageList) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
@@ -526,35 +556,37 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
- MenuItem downloadImage = menu.findItem(R.id.download_image);
+ MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
- if ((m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE)
- || m.getDownloadable() != null || GeoHelper.isGeoUri(m.getBody())) {
- copyText.setVisible(false);
+ if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
+ && m.getTransferable() == null
+ && !GeoHelper.isGeoUri(m.getBody())
+ && m.treatAsDownloadable() != Message.Decision.MUST) {
+ copyText.setVisible(true);
}
- if ((m.getType() == Message.TYPE_TEXT
- || m.getType() == Message.TYPE_PRIVATE
- || m.getDownloadable() != null)
- && (!GeoHelper.isGeoUri(m.getBody()))) {
- shareWith.setVisible(false);
+ if ((m.getType() != Message.TYPE_TEXT
+ && m.getType() != Message.TYPE_PRIVATE
+ && m.getTransferable() == null)
+ || (GeoHelper.isGeoUri(m.getBody()))) {
+ shareWith.setVisible(true);
}
- if (m.getStatus() != Message.STATUS_SEND_FAILED) {
- sendAgain.setVisible(false);
+ if (m.getStatus() == Message.STATUS_SEND_FAILED) {
+ sendAgain.setVisible(true);
+ }
+ if (m.hasFileOnRemoteHost()
+ || GeoHelper.isGeoUri(m.getBody())
+ || m.treatAsDownloadable() == Message.Decision.MUST) {
+ copyUrl.setVisible(true);
+ }
+ if (m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) {
+ downloadFile.setVisible(true);
+ downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
+ }
+ if ((m.getTransferable() != null && !(m.getTransferable() instanceof TransferablePlaceholder))
+ || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
+ || m.getStatus() == Message.STATUS_OFFERED))) {
+ cancelTransmission.setVisible(true);
}
- if (((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
- || m.getImageParams().url == null) && !GeoHelper.isGeoUri(m.getBody())) {
- copyUrl.setVisible(false);
- }
- if (m.getType() != Message.TYPE_TEXT
- || m.getDownloadable() != null
- || !m.bodyContainsDownloadable()) {
- downloadImage.setVisible(false);
- }
- if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
- || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
- || m.getStatus() == Message.STATUS_OFFERED)))) {
- cancelTransmission.setVisible(false);
- }
}
}
@@ -573,8 +605,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.copy_url:
copyUrl(selectedMessage);
return true;
- case R.id.download_image:
- downloadImage(selectedMessage);
+ case R.id.download_file:
+ downloadFile(selectedMessage);
return true;
case R.id.cancel_transmission:
cancelTransmission(selectedMessage);
@@ -595,19 +627,23 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
activity.xmppConnectionService.getFileBackend()
.getJingleFileUri(message));
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- String path = message.getRelativeFilePath();
- String mime = path == null ? null : URLConnection.guessContentTypeFromName(path);
+ String mime = message.getMimeType();
if (mime == null) {
mime = "image/webp";
}
shareIntent.setType(mime);
}
- activity.startActivity(Intent.createChooser(shareIntent,getText(R.string.share_with)));
+ try {
+ activity.startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
+ } catch (ActivityNotFoundException e) {
+ //This should happen only on faulty androids because normally chooser is always available
+ Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
+ }
}
private void copyText(Message message) {
if (activity.copyTextToClipboard(message.getMergedBody(),
- R.string.message_text)) {
+ R.string.message_text)) {
Toast.makeText(activity, R.string.message_copied_to_clipboard,
Toast.LENGTH_SHORT).show();
}
@@ -617,8 +653,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
if (!file.exists()) {
- Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
- message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED));
+ Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
return;
}
}
@@ -631,27 +667,30 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (GeoHelper.isGeoUri(message.getBody())) {
resId = R.string.location;
url = message.getBody();
+ } else if (message.hasFileOnRemoteHost()) {
+ resId = R.string.file_url;
+ url = message.getFileParams().url.toString();
} else {
- resId = R.string.image_url;
- url = message.getImageParams().url.toString();
+ url = message.getBody().trim();
+ resId = R.string.file_url;
}
if (activity.copyTextToClipboard(url, resId)) {
Toast.makeText(activity, R.string.url_copied_to_clipboard,
Toast.LENGTH_SHORT).show();
- }
+ }
}
- private void downloadImage(Message message) {
+ private void downloadFile(Message message) {
activity.xmppConnectionService.getHttpConnectionManager()
- .createNewConnection(message);
+ .createNewDownloadConnection(message);
}
private void cancelTransmission(Message message) {
- Downloadable downloadable = message.getDownloadable();
- if (downloadable!=null) {
- downloadable.cancel();
+ Transferable transferable = message.getTransferable();
+ if (transferable != null) {
+ transferable.cancel();
} else {
- activity.xmppConnectionService.markMessage(message,Message.STATUS_SEND_FAILED);
+ activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
}
}
@@ -659,6 +698,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
this.mEditMessage.setText("");
this.conversation.setNextCounterpart(counterpart);
updateChatMsgHint();
+ updateSendButton();
}
protected void highlightInConference(String nick) {
@@ -667,9 +707,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
mEditMessage.getText().insert(0, nick + ": ");
} else {
if (mEditMessage.getText().charAt(
- mEditMessage.getSelectionStart() - 1) != ' ') {
+ mEditMessage.getSelectionStart() - 1) != ' ') {
nick = " " + nick;
- }
+ }
mEditMessage.getText().insert(mEditMessage.getSelectionStart(),
nick + " ");
}
@@ -682,7 +722,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (this.conversation != null) {
final String msg = mEditMessage.getText().toString();
this.conversation.setNextMessage(msg);
- updateChatState(this.conversation,msg);
+ updateChatState(this.conversation, msg);
}
}
@@ -705,7 +745,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final String msg = mEditMessage.getText().toString();
this.conversation.setNextMessage(msg);
if (this.conversation != conversation) {
- updateChatState(this.conversation,msg);
+ updateChatState(this.conversation, msg);
}
this.conversation.trim();
}
@@ -751,7 +791,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onClick(View v) {
- final Contact contact = conversation == null ? null :conversation.getContact();
+ final Contact contact = conversation == null ? null : conversation.getContact();
if (contact != null) {
activity.xmppConnectionService.createContact(contact);
activity.switchToContactDetails(contact);
@@ -774,7 +814,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
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);
+ intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION);
startActivity(intent);
}
};
@@ -784,11 +824,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final Contact contact = conversation.getContact();
final int mode = conversation.getMode();
if (conversation.isBlocked()) {
- showSnackbar(R.string.contact_blocked, R.string.unblock,this.mUnblockClickListener);
+ 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);
+ showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener);
} else if (mode == Conversation.MODE_MULTI
- &&!conversation.getMucOptions().online()
+ && !conversation.getMucOptions().online()
&& account.getStatus() == Account.State.ONLINE) {
switch (conversation.getMucOptions().getError()) {
case MucOptions.ERROR_NICK_IN_USE:
@@ -812,18 +852,18 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
default:
break;
}
- } else if (askForPassphraseIntent != null ) {
- showSnackbar(R.string.openpgp_messages_found,R.string.decrypt, clickToDecryptListener);
+ } 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);
+ showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener);
} else if (mode == Conversation.MODE_SINGLE
- &&conversation.hasValidOtrSession()
+ && 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);
+ showSnackbar(R.string.notifications_disabled, R.string.enable, this.mUnmuteClickListener);
} else {
hideSnackbar();
}
@@ -837,31 +877,16 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
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);
for (final Message message : this.messageList) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message
- .getStatus() >= Message.STATUS_SEND)
- && message.getDownloadable() == null) {
+ .getStatus() >= Message.STATUS_SEND)
+ && message.getTransferable() == null) {
if (!mEncryptedMessages.contains(message)) {
mEncryptedMessages.add(message);
}
- }
+ }
}
decryptNext();
updateStatusMessages();
@@ -898,6 +923,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} catch (final NoSuchElementException ignored) {
}
+ askForPassphraseIntent = null;
activity.xmppConnectionService.updateMessage(message);
}
@@ -923,53 +949,149 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
updateChatMsgHint();
}
- public void updateSendButton() {
- Conversation c = this.conversation;
- if (Settings.SHOW_ONLINE_STATUS && c != null
- && c.getAccount().getStatus() == Account.State.ONLINE) {
- if (c.getMode() == Conversation.MODE_SINGLE) {
- switch (c.getContact().getMostAvailableStatus()) {
+ enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
+
+ private int getSendButtonImageResource(SendButtonAction action, int status) {
+ switch (action) {
+ case TEXT:
+ switch (status) {
case Presences.CHAT:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_online);
- break;
case Presences.ONLINE:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_online);
- break;
+ return R.drawable.ic_send_text_online;
case Presences.AWAY:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_away);
- break;
+ return R.drawable.ic_send_text_away;
case Presences.XA:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_away);
- break;
case Presences.DND:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_dnd);
- break;
+ return R.drawable.ic_send_text_dnd;
default:
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_offline);
- break;
+ return R.drawable.ic_send_text_offline;
+ }
+ case TAKE_PHOTO:
+ switch (status) {
+ case Presences.CHAT:
+ case Presences.ONLINE:
+ return R.drawable.ic_send_photo_online;
+ case Presences.AWAY:
+ return R.drawable.ic_send_photo_away;
+ case Presences.XA:
+ case Presences.DND:
+ return R.drawable.ic_send_photo_dnd;
+ default:
+ return R.drawable.ic_send_photo_offline;
+ }
+ case RECORD_VOICE:
+ switch (status) {
+ case Presences.CHAT:
+ case Presences.ONLINE:
+ return R.drawable.ic_send_voice_online;
+ case Presences.AWAY:
+ return R.drawable.ic_send_voice_away;
+ case Presences.XA:
+ case Presences.DND:
+ return R.drawable.ic_send_voice_dnd;
+ default:
+ return R.drawable.ic_send_voice_offline;
+ }
+ case SEND_LOCATION:
+ switch (status) {
+ case Presences.CHAT:
+ case Presences.ONLINE:
+ return R.drawable.ic_send_location_online;
+ case Presences.AWAY:
+ return R.drawable.ic_send_location_away;
+ case Presences.XA:
+ case Presences.DND:
+ return R.drawable.ic_send_location_dnd;
+ default:
+ return R.drawable.ic_send_location_offline;
+ }
+ case CANCEL:
+ switch (status) {
+ case Presences.CHAT:
+ case Presences.ONLINE:
+ return R.drawable.ic_send_cancel_online;
+ case Presences.AWAY:
+ return R.drawable.ic_send_cancel_away;
+ case Presences.XA:
+ case Presences.DND:
+ return R.drawable.ic_send_cancel_dnd;
+ default:
+ return R.drawable.ic_send_cancel_offline;
}
- } else if (c.getMode() == Conversation.MODE_MULTI) {
- if (c.getMucOptions().online()) {
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_online);
+ case CHOOSE_PICTURE:
+ switch (status) {
+ case Presences.CHAT:
+ case Presences.ONLINE:
+ return R.drawable.ic_send_picture_online;
+ case Presences.AWAY:
+ return R.drawable.ic_send_picture_away;
+ case Presences.XA:
+ case Presences.DND:
+ return R.drawable.ic_send_picture_dnd;
+ default:
+ return R.drawable.ic_send_picture_offline;
+ }
+ }
+ return R.drawable.ic_send_text_offline;
+ }
+
+ public void updateSendButton() {
+ final Conversation c = this.conversation;
+ final SendButtonAction action;
+ final int status;
+ final boolean empty = this.mEditMessage == null || this.mEditMessage.getText().length() == 0;
+ final boolean conference = c.getMode() == Conversation.MODE_MULTI;
+ if (conference && !c.getAccount().httpUploadAvailable()) {
+ if (empty && c.getNextCounterpart() != null) {
+ action = SendButtonAction.CANCEL;
+ } else {
+ action = SendButtonAction.TEXT;
+ }
+ } else {
+ if (empty) {
+ if (conference && c.getNextCounterpart() != null) {
+ action = SendButtonAction.CANCEL;
} else {
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_offline);
+ String setting = activity.getPreferences().getString("quick_action", "recent");
+ if (!setting.equals("none") && UIHelper.receivedLocationQuestion(conversation.getLatestMessage())) {
+ setting = "location";
+ } else if (setting.equals("recent")) {
+ setting = activity.getPreferences().getString("recently_used_quick_action", "text");
+ }
+ switch (setting) {
+ case "photo":
+ action = SendButtonAction.TAKE_PHOTO;
+ break;
+ case "location":
+ action = SendButtonAction.SEND_LOCATION;
+ break;
+ case "voice":
+ action = SendButtonAction.RECORD_VOICE;
+ break;
+ case "picture":
+ action = SendButtonAction.CHOOSE_PICTURE;
+ break;
+ default:
+ action = SendButtonAction.TEXT;
+ break;
+ }
}
} else {
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_offline);
+ action = SendButtonAction.TEXT;
+ }
+ }
+ if (activity.useSendButtonToIndicateStatus() && c != null
+ && c.getAccount().getStatus() == Account.State.ONLINE) {
+ if (c.getMode() == Conversation.MODE_SINGLE) {
+ status = c.getContact().getMostAvailableStatus();
+ } else {
+ status = c.getMucOptions().online() ? Presences.ONLINE : Presences.OFFLINE;
}
} else {
- this.mSendButton
- .setImageResource(R.drawable.ic_action_send_now_offline);
+ status = Presences.OFFLINE;
}
+ this.mSendButton.setTag(action);
+ this.mSendButton.setImageResource(getSendButtonImageResource(action, status));
}
protected void updateStatusMessages() {
@@ -997,12 +1119,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- protected void makeFingerprintWarning() {
-
- }
-
protected void showSnackbar(final int message, final int action,
- final OnClickListener clickListener) {
+ final OnClickListener clickListener) {
snackbar.setVisibility(View.VISIBLE);
snackbar.setOnClickListener(null);
snackbarMessage.setText(message);
@@ -1034,7 +1152,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void userInputRequried(PendingIntent pi,
- Contact contact) {
+ Contact contact) {
activity.runIntent(
pi,
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
@@ -1058,11 +1176,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onClick(DialogInterface dialog,
- int which) {
+ int which) {
conversation
- .setNextEncryption(Message.ENCRYPTION_NONE);
+ .setNextEncryption(Message.ENCRYPTION_NONE);
xmppService.databaseBackend
- .updateConversation(conversation);
+ .updateConversation(conversation);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message);
messageSent();
@@ -1073,9 +1191,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (conversation.getMucOptions().pgpKeysInUse()) {
if (!conversation.getMucOptions().everybodyHasKeys()) {
Toast warning = Toast
- .makeText(getActivity(),
- R.string.missing_public_keys,
- Toast.LENGTH_LONG);
+ .makeText(getActivity(),
+ R.string.missing_public_keys,
+ Toast.LENGTH_LONG);
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
warning.show();
}
@@ -1087,12 +1205,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onClick(DialogInterface dialog,
- int which) {
+ int which) {
conversation
- .setNextEncryption(Message.ENCRYPTION_NONE);
+ .setNextEncryption(Message.ENCRYPTION_NONE);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.databaseBackend
- .updateConversation(conversation);
+ .updateConversation(conversation);
xmppService.sendMessage(message);
messageSent();
}
@@ -1105,7 +1223,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
public void showNoPGPKeyDialog(boolean plural,
- DialogInterface.OnClickListener listener) {
+ DialogInterface.OnClickListener listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIconAttribute(android.R.attr.alertDialogIcon);
if (plural) {
@@ -1137,6 +1255,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
public void appendText(String text) {
+ if (text == null) {
+ return;
+ }
String previous = this.mEditMessage.getText().toString();
if (previous.length() != 0 && !previous.endsWith(" ")) {
text = " " + text;
@@ -1160,6 +1281,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.COMPOSING)) {
activity.xmppConnectionService.sendChatState(conversation);
}
+ updateSendButton();
}
@Override
@@ -1176,6 +1298,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
activity.xmppConnectionService.sendChatState(conversation);
}
+ updateSendButton();
}
private void changeEmojiKeyboardIcon(ImageView iconToBeChanged, int drawableResourceId){