2012-07-20 02:23:49 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2013-04-26 18:23:43 +00:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
2012-09-12 01:23:19 +00:00
|
|
|
import android.provider.Contacts.Intents;
|
|
|
|
import android.provider.ContactsContract.QuickContact;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.text.format.DateUtils;
|
2012-07-20 02:23:49 +00:00
|
|
|
import android.util.AttributeSet;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2013-10-13 12:45:04 +00:00
|
|
|
import android.webkit.MimeTypeMap;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-10-23 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
2012-12-31 00:42:33 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
2012-07-20 02:23:49 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
2012-10-28 23:04:24 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
|
2012-07-20 02:23:49 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
2013-06-28 23:56:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Emoji;
|
2013-04-26 18:23:43 +00:00
|
|
|
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
|
|
|
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* A view that displays an individual conversation item within a conversation
|
|
|
|
* thread. Used by ComposeMessageActivity's ListActivity via a ConversationAdapter.
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ConversationItem extends LinearLayout {
|
|
|
|
|
|
|
|
private Handler failedIconHandler;
|
|
|
|
private MessageRecord messageRecord;
|
|
|
|
private MasterSecret masterSecret;
|
2013-05-05 19:51:36 +00:00
|
|
|
private boolean groupThread;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-07-20 02:23:49 +00:00
|
|
|
private TextView bodyText;
|
|
|
|
private TextView dateText;
|
2012-10-29 23:51:42 +00:00
|
|
|
private TextView groupStatusText;
|
2012-07-20 02:23:49 +00:00
|
|
|
private ImageView secureImage;
|
|
|
|
private ImageView failedImage;
|
|
|
|
private ImageView keyImage;
|
|
|
|
private ImageView contactPhoto;
|
2013-01-07 05:38:36 +00:00
|
|
|
private ImageView deliveredImage;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
private View mmsContainer;
|
2012-07-20 02:23:49 +00:00
|
|
|
private ImageView mmsThumbnail;
|
|
|
|
private Button mmsDownloadButton;
|
|
|
|
private TextView mmsDownloadingLabel;
|
2013-04-26 18:23:43 +00:00
|
|
|
private ListenableFutureTask<SlideDeck> slideDeck;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-09-16 07:55:01 +00:00
|
|
|
private final FailedIconClickListener failedIconClickListener = new FailedIconClickListener();
|
|
|
|
private final MmsDownloadClickListener mmsDownloadClickListener = new MmsDownloadClickListener();
|
|
|
|
private final MmsPreferencesClickListener mmsPreferencesClickListener = new MmsPreferencesClickListener();
|
|
|
|
private final ClickListener clickListener = new ClickListener();
|
|
|
|
private final Handler handler = new Handler();
|
2011-12-20 18:20:44 +00:00
|
|
|
private final Context context;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public ConversationItem(Context context) {
|
|
|
|
super(context);
|
2012-07-20 02:23:49 +00:00
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
this.bodyText = (TextView) findViewById(R.id.conversation_item_body);
|
|
|
|
this.dateText = (TextView) findViewById(R.id.conversation_item_date);
|
2012-10-29 23:51:42 +00:00
|
|
|
this.groupStatusText = (TextView) findViewById(R.id.group_message_status);
|
2011-12-20 18:20:44 +00:00
|
|
|
this.secureImage = (ImageView)findViewById(R.id.sms_secure_indicator);
|
|
|
|
this.failedImage = (ImageView)findViewById(R.id.sms_failed_indicator);
|
|
|
|
this.keyImage = (ImageView)findViewById(R.id.key_exchange_indicator);
|
2013-06-21 18:56:59 +00:00
|
|
|
this.mmsContainer = (View) findViewById(R.id.mms_view);
|
2011-12-20 18:20:44 +00:00
|
|
|
this.mmsThumbnail = (ImageView)findViewById(R.id.image_view);
|
|
|
|
this.mmsDownloadButton = (Button) findViewById(R.id.mms_download_button);
|
|
|
|
this.mmsDownloadingLabel = (TextView) findViewById(R.id.mms_label_downloading);
|
|
|
|
this.contactPhoto = (ImageView)findViewById(R.id.contact_photo);
|
2013-01-07 05:38:36 +00:00
|
|
|
this.deliveredImage = (ImageView)findViewById(R.id.delivered_indicator);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
setOnClickListener(clickListener);
|
|
|
|
this.failedImage.setOnClickListener(failedIconClickListener);
|
|
|
|
this.mmsDownloadButton.setOnClickListener(mmsDownloadClickListener);
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-05-05 19:51:36 +00:00
|
|
|
public void set(MasterSecret masterSecret, MessageRecord messageRecord,
|
|
|
|
Handler failedIconHandler, boolean groupThread)
|
2011-12-20 18:20:44 +00:00
|
|
|
{
|
|
|
|
this.messageRecord = messageRecord;
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.failedIconHandler = failedIconHandler;
|
2013-05-05 19:51:36 +00:00
|
|
|
this.groupThread = groupThread;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
setBodyText(messageRecord);
|
|
|
|
setStatusIcons(messageRecord);
|
|
|
|
setContactPhoto(messageRecord);
|
2012-10-29 23:51:42 +00:00
|
|
|
setGroupMessageStatus(messageRecord);
|
2012-10-28 23:04:24 +00:00
|
|
|
setEvents(messageRecord);
|
|
|
|
|
|
|
|
if (messageRecord instanceof NotificationMmsMessageRecord) {
|
|
|
|
setNotificationMmsAttributes((NotificationMmsMessageRecord)messageRecord);
|
|
|
|
} else if (messageRecord instanceof MediaMmsMessageRecord) {
|
|
|
|
setMediaMmsAttributes((MediaMmsMessageRecord)messageRecord);
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-04-26 18:23:43 +00:00
|
|
|
public void unbind() {
|
|
|
|
if (slideDeck != null)
|
|
|
|
slideDeck.setListener(null);
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public MessageRecord getMessageRecord() {
|
|
|
|
return messageRecord;
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
public void setHandler(Handler failedIconHandler) {
|
|
|
|
this.failedIconHandler = failedIconHandler;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
/// MessageRecord Attribute Parsers
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
private void setBodyText(MessageRecord messageRecord) {
|
2013-06-28 23:56:30 +00:00
|
|
|
bodyText.setText(Emoji.getInstance(context).emojify(messageRecord.getDisplayBody(), Emoji.EMOJI_LARGE),
|
2013-09-16 07:55:01 +00:00
|
|
|
TextView.BufferType.SPANNABLE);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
private void setContactPhoto(MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.isOutgoing()) {
|
|
|
|
setContactPhotoForUserIdentity();
|
|
|
|
} else {
|
|
|
|
setContactPhotoForRecipient(messageRecord.getIndividualRecipient());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setStatusIcons(MessageRecord messageRecord) {
|
|
|
|
failedImage.setVisibility(messageRecord.isFailed() ? View.VISIBLE : View.GONE);
|
|
|
|
secureImage.setVisibility(messageRecord.isSecure() ? View.VISIBLE : View.GONE);
|
|
|
|
keyImage.setVisibility(messageRecord.isKeyExchange() ? View.VISIBLE : View.GONE);
|
2013-01-07 05:38:36 +00:00
|
|
|
deliveredImage.setVisibility(!messageRecord.isKeyExchange() && messageRecord.isDelivered() ? View.VISIBLE : View.GONE);
|
2012-10-28 23:04:24 +00:00
|
|
|
|
|
|
|
mmsThumbnail.setVisibility(View.GONE);
|
|
|
|
mmsDownloadButton.setVisibility(View.GONE);
|
|
|
|
mmsDownloadingLabel.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (messageRecord.isFailed()) dateText.setText(R.string.ConversationItem_error_sending_message);
|
|
|
|
else if (messageRecord.isPending()) dateText.setText(R.string.ConversationItem_sending);
|
|
|
|
else dateText.setText(DateUtils.getRelativeTimeSpanString(getContext(),
|
2013-01-06 21:13:14 +00:00
|
|
|
(messageRecord.isOutgoing() ?
|
|
|
|
messageRecord.getDateSent() :
|
|
|
|
messageRecord.getDateReceived()),
|
2012-10-28 23:04:24 +00:00
|
|
|
false));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setEvents(MessageRecord messageRecord) {
|
|
|
|
setClickable(messageRecord.isKeyExchange() && !messageRecord.isOutgoing());
|
|
|
|
|
|
|
|
if (!messageRecord.isOutgoing() && messageRecord.getRecipients().isSingleRecipient()) {
|
|
|
|
checkForAutoInitiate(messageRecord.getIndividualRecipient(),
|
2013-09-16 07:55:01 +00:00
|
|
|
messageRecord.getBody().getBody(),
|
|
|
|
messageRecord.getThreadId());
|
2012-10-28 23:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-29 23:51:42 +00:00
|
|
|
private void setGroupMessageStatus(MessageRecord messageRecord) {
|
2013-05-05 19:51:36 +00:00
|
|
|
if (groupThread && !messageRecord.isOutgoing()) {
|
|
|
|
this.groupStatusText.setText(messageRecord.getIndividualRecipient().toShortString());
|
|
|
|
this.groupStatusText.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
2012-10-29 23:51:42 +00:00
|
|
|
this.groupStatusText.setVisibility(View.GONE);
|
2013-05-05 19:51:36 +00:00
|
|
|
}
|
2012-10-29 23:51:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
private void setNotificationMmsAttributes(NotificationMmsMessageRecord messageRecord) {
|
2012-09-20 02:56:04 +00:00
|
|
|
String messageSize = String.format(getContext()
|
|
|
|
.getString(R.string.ConversationItem_message_size_d_kb),
|
2012-09-08 03:03:23 +00:00
|
|
|
messageRecord.getMessageSize());
|
2012-09-20 02:56:04 +00:00
|
|
|
String expires = String.format(getContext()
|
|
|
|
.getString(R.string.ConversationItem_expires_s),
|
2012-09-08 03:03:23 +00:00
|
|
|
DateUtils.getRelativeTimeSpanString(getContext(),
|
|
|
|
messageRecord.getExpiration(),
|
|
|
|
false));
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
dateText.setText(messageSize + "\n" + expires);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
if (MmsDatabase.Status.isDisplayDownloadButton(messageRecord.getStatus())) {
|
2011-12-20 18:20:44 +00:00
|
|
|
mmsDownloadButton.setVisibility(View.VISIBLE);
|
|
|
|
mmsDownloadingLabel.setVisibility(View.GONE);
|
|
|
|
} else {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
mmsDownloadingLabel.setText(MmsDatabase.Status.getLabelForStatus(context, messageRecord.getStatus()));
|
2011-12-20 18:20:44 +00:00
|
|
|
mmsDownloadButton.setVisibility(View.GONE);
|
|
|
|
mmsDownloadingLabel.setVisibility(View.VISIBLE);
|
2013-09-16 07:55:01 +00:00
|
|
|
|
|
|
|
if (MmsDatabase.Status.isHardError(messageRecord.getStatus()) && !messageRecord.isOutgoing())
|
|
|
|
setOnClickListener(mmsDownloadClickListener);
|
|
|
|
else if (MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE == messageRecord.getStatus() && !messageRecord.isOutgoing())
|
|
|
|
setOnClickListener(mmsPreferencesClickListener);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
private void setMediaMmsAttributes(MediaMmsMessageRecord messageRecord) {
|
2013-04-26 18:23:43 +00:00
|
|
|
if (messageRecord.getPartCount() > 0) {
|
|
|
|
mmsThumbnail.setVisibility(View.VISIBLE);
|
2013-06-21 18:56:59 +00:00
|
|
|
mmsContainer.setVisibility(View.VISIBLE);
|
2013-04-26 18:23:43 +00:00
|
|
|
mmsThumbnail.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
|
2013-05-05 19:51:36 +00:00
|
|
|
} else {
|
|
|
|
mmsThumbnail.setVisibility(View.GONE);
|
2013-06-21 18:56:59 +00:00
|
|
|
mmsContainer.setVisibility(View.GONE);
|
2013-04-26 18:23:43 +00:00
|
|
|
}
|
2012-10-28 23:04:24 +00:00
|
|
|
|
2013-04-26 18:23:43 +00:00
|
|
|
slideDeck = messageRecord.getSlideDeck();
|
|
|
|
slideDeck.setListener(new FutureTaskListener<SlideDeck>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(final SlideDeck result) {
|
|
|
|
if (result == null)
|
2012-10-28 23:04:24 +00:00
|
|
|
return;
|
2013-04-26 18:23:43 +00:00
|
|
|
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
for (Slide slide : result.getSlides()) {
|
|
|
|
if (slide.hasImage()) {
|
|
|
|
slide.setThumbnailOn(mmsThumbnail);
|
|
|
|
// mmsThumbnail.setImageBitmap(slide.getThumbnail());
|
|
|
|
mmsThumbnail.setOnClickListener(new ThumbnailClickListener(slide));
|
|
|
|
mmsThumbnail.setOnLongClickListener(new ThumbnailSaveListener(slide));
|
|
|
|
mmsThumbnail.setVisibility(View.VISIBLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mmsThumbnail.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 18:23:43 +00:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable error) {}
|
|
|
|
});
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
/// Helper Methods
|
|
|
|
|
|
|
|
private void checkForAutoInitiate(Recipient recipient, String body, long threadId) {
|
2013-05-06 02:13:33 +00:00
|
|
|
if (!groupThread &&
|
|
|
|
AutoInitiateActivity.isValidAutoInitiateSituation(context, masterSecret, recipient,
|
2012-10-28 23:04:24 +00:00
|
|
|
body, threadId))
|
|
|
|
{
|
|
|
|
AutoInitiateActivity.exemptThread(context, threadId);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setClass(context, AutoInitiateActivity.class);
|
2012-10-28 23:04:24 +00:00
|
|
|
intent.putExtra("threadId", threadId);
|
2011-12-20 18:20:44 +00:00
|
|
|
intent.putExtra("masterSecret", masterSecret);
|
2012-10-28 23:04:24 +00:00
|
|
|
intent.putExtra("recipient", recipient);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void setContactPhotoForUserIdentity() {
|
2012-12-24 16:40:37 +00:00
|
|
|
Uri uri = ContactIdentityManager.getInstance(context).getSelfIdentityUri();
|
|
|
|
contactPhoto.setImageBitmap(ContactPhotoFactory.getLocalUserContactPhoto(context, uri));
|
2011-12-20 18:20:44 +00:00
|
|
|
contactPhoto.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
private void setContactPhotoForRecipient(final Recipient recipient) {
|
|
|
|
contactPhoto.setImageBitmap(recipient.getContactPhoto());
|
|
|
|
contactPhoto.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (recipient.getContactUri() != null) {
|
|
|
|
QuickContact.showQuickContact(context, contactPhoto, recipient.getContactUri(), QuickContact.MODE_LARGE, null);
|
|
|
|
} else {
|
2013-09-16 07:55:01 +00:00
|
|
|
Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null));
|
2012-10-28 23:04:24 +00:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-08-04 00:34:09 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
contactPhoto.setVisibility(View.VISIBLE);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-28 23:04:24 +00:00
|
|
|
/// Event handlers
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void handleKeyExchangeClicked() {
|
|
|
|
Intent intent = new Intent(context, ReceiveKeyActivity.class);
|
2013-04-26 01:59:49 +00:00
|
|
|
intent.putExtra("recipient", messageRecord.getIndividualRecipient());
|
2013-04-30 18:14:01 +00:00
|
|
|
intent.putExtra("body", messageRecord.getBody().getBody());
|
2011-12-20 18:20:44 +00:00
|
|
|
intent.putExtra("thread_id", messageRecord.getThreadId());
|
2013-05-23 23:36:24 +00:00
|
|
|
intent.putExtra("message_id", messageRecord.getId());
|
2011-12-20 18:20:44 +00:00
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
intent.putExtra("sent", messageRecord.isOutgoing());
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class ThumbnailSaveListener extends Handler implements View.OnLongClickListener, Runnable, MediaScannerConnection.MediaScannerConnectionClient {
|
|
|
|
private static final int SUCCESS = 0;
|
|
|
|
private static final int FAILURE = 1;
|
|
|
|
private static final int WRITE_ACCESS_FAILURE = 2;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private final Slide slide;
|
|
|
|
private ProgressDialog progressDialog;
|
|
|
|
private MediaScannerConnection mediaScannerConnection;
|
|
|
|
private File mediaFile;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public ThumbnailSaveListener(Slide slide) {
|
|
|
|
this.slide = slide;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if (!Environment.getExternalStorageDirectory().canWrite()) {
|
|
|
|
this.obtainMessage(WRITE_ACCESS_FAILURE).sendToTarget();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
mediaFile = constructOutputFile();
|
|
|
|
InputStream inputStream = slide.getPartDataInputStream();
|
|
|
|
OutputStream outputStream = new FileOutputStream(mediaFile);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
byte[] buffer = new byte[4096];
|
|
|
|
int read;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
while ((read = inputStream.read(buffer)) != -1) {
|
|
|
|
outputStream.write(buffer, 0, read);
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
outputStream.close();
|
|
|
|
inputStream.close();
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
mediaScannerConnection = new MediaScannerConnection(context, this);
|
|
|
|
mediaScannerConnection.connect();
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.w("ConversationItem", ioe);
|
|
|
|
this.obtainMessage(FAILURE).sendToTarget();
|
2012-07-20 02:23:49 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private File constructOutputFile() throws IOException {
|
|
|
|
File sdCard = Environment.getExternalStorageDirectory();
|
|
|
|
File outputDirectory;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (slide.hasVideo())
|
|
|
|
outputDirectory = new File(sdCard.getAbsoluteFile() + File.separator + "Movies");
|
|
|
|
else if (slide.hasAudio())
|
|
|
|
outputDirectory = new File(sdCard.getAbsolutePath() + File.separator + "Music");
|
|
|
|
else
|
|
|
|
outputDirectory = new File(sdCard.getAbsolutePath() + File.separator + "Pictures");
|
|
|
|
outputDirectory.mkdirs();
|
2013-10-13 12:45:04 +00:00
|
|
|
|
|
|
|
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
|
|
|
String extension = mimeTypeMap.getExtensionFromMimeType(slide.getContentType());
|
|
|
|
if (extension == null)
|
|
|
|
extension = "attach";
|
|
|
|
|
|
|
|
return File.createTempFile("textsecure", "." + extension, outputDirectory);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void saveToSdCard() {
|
|
|
|
progressDialog = new ProgressDialog(context);
|
2012-09-20 02:56:04 +00:00
|
|
|
progressDialog.setTitle(context.getString(R.string.ConversationItem_saving_attachment));
|
|
|
|
progressDialog.setMessage(context.getString(R.string.ConversationItem_saving_attachment_to_sd_card));
|
2011-12-20 18:20:44 +00:00
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
progressDialog.setIndeterminate(true);
|
|
|
|
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
|
progressDialog.show();
|
|
|
|
new Thread(this).start();
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setTitle(R.string.ConversationItem_save_to_sd_card);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
builder.setCancelable(true);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setMessage(R.string.ConversationItem_this_media_has_been_stored_in_an_encrypted_database_warning);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
saveToSdCard();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
public void handleMessage(Message message) {
|
|
|
|
switch (message.what) {
|
|
|
|
case FAILURE:
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(context, R.string.ConversationItem_error_while_saving_attachment_to_sd_card,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
break;
|
|
|
|
case SUCCESS:
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(context, R.string.ConversationItem_success_exclamation,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
break;
|
|
|
|
case WRITE_ACCESS_FAILURE:
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(context, R.string.ConversationItem_unable_to_write_to_sd_card_exclamation,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
progressDialog.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onMediaScannerConnected() {
|
|
|
|
mediaScannerConnection.scanFile(mediaFile.getAbsolutePath(), slide.getContentType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onScanCompleted(String path, Uri uri) {
|
|
|
|
mediaScannerConnection.disconnect();
|
2012-07-20 02:23:49 +00:00
|
|
|
this.obtainMessage(SUCCESS).sendToTarget();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class ThumbnailClickListener implements View.OnClickListener {
|
|
|
|
private final Slide slide;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public ThumbnailClickListener(Slide slide) {
|
|
|
|
this.slide = slide;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireIntent() {
|
|
|
|
Log.w("ConversationItem", "Clicked: " + slide.getUri() + " , " + slide.getContentType());
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setDataAndType(slide.getUri(), slide.getContentType());
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setTitle(R.string.ConversationItem_view_secure_media_question);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
builder.setCancelable(true);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setMessage(R.string.ConversationItem_this_media_has_been_stored_in_an_encrypted_database_external_viewer_warning);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
fireIntent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
2012-07-20 02:23:49 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class MmsDownloadClickListener implements View.OnClickListener {
|
|
|
|
public void onClick(View v) {
|
2012-10-28 23:04:24 +00:00
|
|
|
NotificationMmsMessageRecord notificationRecord = (NotificationMmsMessageRecord)messageRecord;
|
|
|
|
Log.w("MmsDownloadClickListener", "Content location: " + new String(notificationRecord.getContentLocation()));
|
2011-12-20 18:20:44 +00:00
|
|
|
mmsDownloadButton.setVisibility(View.GONE);
|
|
|
|
mmsDownloadingLabel.setVisibility(View.VISIBLE);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
Intent intent = new Intent(context, SendReceiveService.class);
|
2012-10-28 23:04:24 +00:00
|
|
|
intent.putExtra("content_location", new String(notificationRecord.getContentLocation()));
|
|
|
|
intent.putExtra("message_id", notificationRecord.getId());
|
|
|
|
intent.putExtra("transaction_id", notificationRecord.getTransactionId());
|
|
|
|
intent.putExtra("thread_id", notificationRecord.getThreadId());
|
2011-12-20 18:20:44 +00:00
|
|
|
intent.setAction(SendReceiveService.DOWNLOAD_MMS_ACTION);
|
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-09-16 07:55:01 +00:00
|
|
|
private class MmsPreferencesClickListener implements View.OnClickListener {
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, PromptMmsActivity.class);
|
|
|
|
intent.putExtra("message_id", messageRecord.getId());
|
|
|
|
intent.putExtra("thread_id", messageRecord.getThreadId());
|
|
|
|
intent.putExtra("automatic", true);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class FailedIconClickListener implements View.OnClickListener {
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (failedIconHandler != null && !messageRecord.isKeyExchange()) {
|
|
|
|
Message message = Message.obtain();
|
2013-05-17 19:53:16 +00:00
|
|
|
message.obj = messageRecord.getBody().getBody();
|
2011-12-20 18:20:44 +00:00
|
|
|
failedIconHandler.dispatchMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class ClickListener implements View.OnClickListener {
|
|
|
|
public void onClick(View v) {
|
2012-07-20 02:23:49 +00:00
|
|
|
if (messageRecord.isKeyExchange() &&
|
|
|
|
!messageRecord.isOutgoing() &&
|
2011-12-20 18:20:44 +00:00
|
|
|
!messageRecord.isProcessedKeyExchange() &&
|
|
|
|
!messageRecord.isStaleKeyExchange())
|
|
|
|
handleKeyExchangeClicked();
|
2012-07-20 02:23:49 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|