session-android/src/org/thoughtcrime/securesms/ConversationItem.java

700 lines
29 KiB
Java
Raw Normal View History

/**
2011-12-20 18:20:44 +00:00
* Copyright (C) 2011 Whisper Systems
*
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.
*
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;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
2011-12-20 18:20:44 +00:00
import android.media.MediaScannerConnection;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
2011-12-20 18:20:44 +00:00
import android.net.Uri;
import android.os.Build;
2011-12-20 18:20:44 +00:00
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Contacts.Intents;
import android.provider.ContactsContract.QuickContact;
import android.util.AttributeSet;
2011-12-20 18:20:44 +00:00
import android.util.Log;
import android.view.View;
import android.webkit.MimeTypeMap;
2011-12-20 18:20:44 +00:00
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
2014-03-01 22:17:55 +00:00
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MmsDatabase;
2014-03-01 22:17:55 +00:00
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.SendReceiveService;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.Emoji;
import org.thoughtcrime.securesms.util.Dialogs;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.storage.Session;
2013-09-11 22:32:18 +00:00
import org.whispersystems.textsecure.util.FutureTaskListener;
import org.whispersystems.textsecure.util.ListenableFutureTask;
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.
*
2011-12-20 18:20:44 +00:00
* @author Moxie Marlinspike
*
*/
public class ConversationItem extends LinearLayout {
private final static String TAG = ConversationItem.class.getSimpleName();
2011-12-20 18:20:44 +00:00
2014-02-24 01:11:10 +00:00
private final int STYLE_ATTRIBUTES[] = new int[]{R.attr.conversation_item_sent_push_background,
R.attr.conversation_item_sent_push_triangle_background,
R.attr.conversation_item_sent_background,
R.attr.conversation_item_sent_triangle_background,
R.attr.conversation_item_sent_pending_background,
R.attr.conversation_item_sent_pending_triangle_background,
R.attr.conversation_item_sent_push_pending_background,
R.attr.conversation_item_sent_push_pending_triangle_background};
private final static int SENT_PUSH = 0;
private final static int SENT_PUSH_TRIANGLE = 1;
private final static int SENT_SMS = 2;
private final static int SENT_SMS_TRIANGLE = 3;
private final static int SENT_SMS_PENDING = 4;
private final static int SENT_SMS_PENDING_TRIANGLE = 5;
private final static int SENT_PUSH_PENDING = 6;
private final static int SENT_PUSH_PENDING_TRIANGLE = 7;
2014-02-24 01:11:10 +00:00
2011-12-20 18:20:44 +00:00
private Handler failedIconHandler;
private MessageRecord messageRecord;
private MasterSecret masterSecret;
private boolean groupThread;
private boolean pushDestination;
2011-12-20 18:20:44 +00:00
2014-02-24 01:11:10 +00:00
private View conversationParent;
private TextView bodyText;
private TextView dateText;
2014-03-01 22:17:55 +00:00
private TextView indicatorText;
2014-02-24 01:11:10 +00:00
private TextView groupStatusText;
private ImageView secureImage;
private ImageView failedImage;
private ImageView keyImage;
private ImageView contactPhoto;
private ImageView deliveredImage;
2014-03-01 22:17:55 +00:00
private View triangleTick;
private ImageView pendingIndicator;
private View mmsContainer;
private ImageView mmsThumbnail;
private Button mmsDownloadButton;
private TextView mmsDownloadingLabel;
private ListenableFutureTask<SlideDeck> slideDeck;
2014-02-24 01:11:10 +00:00
private TypedArray backgroundDrawables;
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;
2011-12-20 18:20:44 +00:00
public ConversationItem(Context context) {
super(context);
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);
2014-03-01 22:17:55 +00:00
this.indicatorText = (TextView) findViewById(R.id.indicator_text);
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);
this.mmsContainer = 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);
this.deliveredImage = (ImageView)findViewById(R.id.delivered_indicator);
2014-02-24 01:11:10 +00:00
this.conversationParent = (View) findViewById(R.id.conversation_item_parent);
2014-03-01 22:17:55 +00:00
this.triangleTick = findViewById(R.id.triangle_tick);
this.pendingIndicator = (ImageView)findViewById(R.id.pending_approval_indicator);
2014-02-24 01:11:10 +00:00
this.backgroundDrawables = context.obtainStyledAttributes(STYLE_ATTRIBUTES);
2011-12-20 18:20:44 +00:00
setOnClickListener(clickListener);
if (failedImage != null) failedImage.setOnClickListener(failedIconClickListener);
if (mmsDownloadButton != null) mmsDownloadButton.setOnClickListener(mmsDownloadClickListener);
2011-12-20 18:20:44 +00:00
}
public void set(MasterSecret masterSecret, MessageRecord messageRecord,
Handler failedIconHandler, boolean groupThread, boolean pushDestination)
2011-12-20 18:20:44 +00:00
{
2011-12-20 18:20:44 +00:00
this.messageRecord = messageRecord;
this.masterSecret = masterSecret;
this.failedIconHandler = failedIconHandler;
this.groupThread = groupThread;
this.pushDestination = pushDestination;
setBackgroundDrawables(messageRecord);
setBodyText(messageRecord);
2014-02-17 19:54:39 +00:00
if (!messageRecord.isGroupAction()) {
setStatusIcons(messageRecord);
setContactPhoto(messageRecord);
setGroupMessageStatus(messageRecord);
setEvents(messageRecord);
2014-03-01 22:17:55 +00:00
setMinimumWidth();
2014-02-17 19:54:39 +00:00
if (messageRecord instanceof NotificationMmsMessageRecord) {
setNotificationMmsAttributes((NotificationMmsMessageRecord)messageRecord);
} else if (messageRecord instanceof MediaMmsMessageRecord) {
setMediaMmsAttributes((MediaMmsMessageRecord)messageRecord);
}
}
2011-12-20 18:20:44 +00:00
}
public void unbind() {
if (slideDeck != null)
slideDeck.setListener(null);
}
2011-12-20 18:20:44 +00:00
public MessageRecord getMessageRecord() {
return messageRecord;
}
public void setHandler(Handler failedIconHandler) {
this.failedIconHandler = failedIconHandler;
2011-12-20 18:20:44 +00:00
}
public static void setViewBackgroundWithoutResettingPadding(final View v, final int backgroundResId) {
final int paddingBottom = v.getPaddingBottom();
final int paddingLeft = v.getPaddingLeft();
final int paddingRight = v.getPaddingRight();
final int paddingTop = v.getPaddingTop();
v.setBackgroundResource(backgroundResId);
v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
}
/// MessageRecord Attribute Parsers
private void setBackgroundDrawables(MessageRecord messageRecord) {
2014-02-24 01:11:10 +00:00
if (conversationParent != null && backgroundDrawables != null) {
if (messageRecord.isOutgoing()) {
final int background;
final int triangleBackground;
2014-03-01 22:17:55 +00:00
if (messageRecord.isPending() && pushDestination && !messageRecord.isForcedSms()) {
background = SENT_PUSH_PENDING;
triangleBackground = SENT_PUSH_PENDING_TRIANGLE;
2014-03-01 22:17:55 +00:00
} else if (messageRecord.isPending() || messageRecord.isPendingFallbackApproval()) {
background = SENT_SMS_PENDING;
triangleBackground = SENT_SMS_PENDING_TRIANGLE;
} else if (messageRecord.isPush()) {
background = SENT_PUSH;
triangleBackground = SENT_PUSH_TRIANGLE;
} else {
background = SENT_SMS;
triangleBackground = SENT_SMS_TRIANGLE;
}
setViewBackgroundWithoutResettingPadding(conversationParent, backgroundDrawables.getResourceId(background, -1));
2014-03-01 22:17:55 +00:00
setViewBackgroundWithoutResettingPadding(triangleTick, backgroundDrawables.getResourceId(triangleBackground, -1));
}
}
}
private void setBodyText(MessageRecord messageRecord) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
bodyText.setText(Emoji.getInstance(context).emojify(messageRecord.getDisplayBody(), Emoji.EMOJI_LARGE),
TextView.BufferType.SPANNABLE);
} else {
bodyText.setText(messageRecord.getDisplayBody());
}
2011-12-20 18:20:44 +00:00
}
private void setContactPhoto(MessageRecord messageRecord) {
if (! messageRecord.isOutgoing()) {
setContactPhotoForRecipient(messageRecord.getIndividualRecipient());
}
}
private void setStatusIcons(MessageRecord messageRecord) {
failedImage.setVisibility(messageRecord.isFailed() ? View.VISIBLE : View.GONE);
2014-03-01 22:17:55 +00:00
if (messageRecord.isOutgoing()) {
pendingIndicator.setVisibility(messageRecord.isPendingFallbackApproval() ? View.VISIBLE : View.GONE);
indicatorText.setVisibility(messageRecord.isPendingFallbackApproval() ? View.VISIBLE : View.GONE);
}
secureImage.setVisibility(messageRecord.isSecure() ? View.VISIBLE : View.GONE);
keyImage.setVisibility(messageRecord.isKeyExchange() ? View.VISIBLE : View.GONE);
deliveredImage.setVisibility(!messageRecord.isKeyExchange() && messageRecord.isDelivered() ? View.VISIBLE : View.GONE);
mmsThumbnail.setVisibility(View.GONE);
mmsDownloadButton.setVisibility(View.GONE);
mmsDownloadingLabel.setVisibility(View.GONE);
if (messageRecord.isFailed()) {
dateText.setText(R.string.ConversationItem_error_sending_message);
2014-03-01 22:17:55 +00:00
} else if (messageRecord.isPendingFallbackApproval() && indicatorText != null) {
dateText.setText("");
indicatorText.setText(R.string.ConversationItem_click_to_approve);
} else if (messageRecord.isPending()) {
dateText.setText(" ··· ");
} else {
final long timestamp = (messageRecord.isOutgoing() ?
messageRecord.getDateSent() :
messageRecord.getDateReceived());
dateText.setText(DateUtils.getBetterRelativeTimeSpanString(getContext(), timestamp));
}
}
2014-03-01 22:17:55 +00:00
private void setMinimumWidth() {
if (indicatorText != null && indicatorText.getVisibility() == View.VISIBLE && indicatorText.getText() != null) {
conversationParent.setMinimumWidth(indicatorText.getText().length() * 20);
} else {
conversationParent.setMinimumWidth(0);
}
}
private void setEvents(MessageRecord messageRecord) {
2014-03-01 22:17:55 +00:00
setClickable(messageRecord.isPendingFallbackApproval() ||
(messageRecord.isKeyExchange() &&
!messageRecord.isCorruptedKeyExchange() &&
!messageRecord.isOutgoing()));
2014-01-07 04:03:16 +00:00
if (!messageRecord.isOutgoing() &&
messageRecord.getRecipients().isSingleRecipient() &&
!messageRecord.isSecure())
{
checkForAutoInitiate(messageRecord.getIndividualRecipient(),
2014-01-07 04:03:16 +00:00
messageRecord.getBody().getBody(),
messageRecord.getThreadId());
}
}
private void setGroupMessageStatus(MessageRecord messageRecord) {
if (groupThread && !messageRecord.isOutgoing()) {
this.groupStatusText.setText(messageRecord.getIndividualRecipient().toShortString());
this.groupStatusText.setVisibility(View.VISIBLE);
} else {
this.groupStatusText.setVisibility(View.GONE);
}
}
private void setNotificationMmsAttributes(NotificationMmsMessageRecord messageRecord) {
String messageSize = String.format(context.getString(R.string.ConversationItem_message_size_d_kb),
messageRecord.getMessageSize());
String expires = String.format(context.getString(R.string.ConversationItem_expires_s),
DateUtils.getRelativeTimeSpanString(getContext(),
messageRecord.getExpiration(),
false));
2011-12-20 18:20:44 +00:00
dateText.setText(messageSize + "\n" + expires);
if (MmsDatabase.Status.isDisplayDownloadButton(messageRecord.getStatus())) {
2011-12-20 18:20:44 +00:00
mmsDownloadButton.setVisibility(View.VISIBLE);
mmsDownloadingLabel.setVisibility(View.GONE);
} else {
mmsDownloadingLabel.setText(MmsDatabase.Status.getLabelForStatus(context, messageRecord.getStatus()));
2011-12-20 18:20:44 +00:00
mmsDownloadButton.setVisibility(View.GONE);
mmsDownloadingLabel.setVisibility(View.VISIBLE);
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
}
}
private void setMediaMmsAttributes(MediaMmsMessageRecord messageRecord) {
if (messageRecord.getPartCount() > 0) {
mmsThumbnail.setVisibility(View.VISIBLE);
mmsContainer.setVisibility(View.VISIBLE);
mmsThumbnail.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
} else {
mmsThumbnail.setVisibility(View.GONE);
mmsContainer.setVisibility(View.GONE);
}
slideDeck = messageRecord.getSlideDeck();
slideDeck.setListener(new FutureTaskListener<SlideDeck>() {
@Override
public void onSuccess(final SlideDeck result) {
if (result == null)
return;
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
}
@Override
public void onFailure(Throwable error) {}
});
2011-12-20 18:20:44 +00:00
}
/// Helper Methods
private void checkForAutoInitiate(Recipient recipient, String body, long threadId) {
if (!groupThread &&
AutoInitiateActivity.isValidAutoInitiateSituation(context, masterSecret, recipient,
body, threadId))
{
AutoInitiateActivity.exemptThread(context, threadId);
2011-12-20 18:20:44 +00:00
Intent intent = new Intent();
intent.setClass(context, AutoInitiateActivity.class);
intent.putExtra("threadId", threadId);
2011-12-20 18:20:44 +00:00
intent.putExtra("masterSecret", masterSecret);
intent.putExtra("recipient", recipient);
2011-12-20 18:20:44 +00:00
context.startActivity(intent);
}
}
private void setContactPhotoForRecipient(final Recipient recipient) {
contactPhoto.setImageBitmap(BitmapUtil.getCircleCroppedBitmap(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 {
Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null));
context.startActivity(intent);
}
}
});
contactPhoto.setVisibility(View.VISIBLE);
2011-12-20 18:20:44 +00:00
}
/// Event handlers
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());
intent.putExtra("recipient_device_id", messageRecord.getRecipientDeviceId());
intent.putExtra("body", messageRecord.getBody().getBody());
2011-12-20 18:20:44 +00:00
intent.putExtra("thread_id", messageRecord.getThreadId());
intent.putExtra("message_id", messageRecord.getId());
intent.putExtra("is_bundle", messageRecord.isBundleKeyExchange());
intent.putExtra("is_identity_update", messageRecord.isIdentityUpdate());
intent.putExtra("is_push", messageRecord.isPush());
2011-12-20 18:20:44 +00:00
intent.putExtra("master_secret", masterSecret);
intent.putExtra("sent", messageRecord.isOutgoing());
context.startActivity(intent);
}
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;
2011-12-20 18:20:44 +00:00
private final Slide slide;
private ProgressDialog progressDialog;
private MediaScannerConnection mediaScannerConnection;
private File mediaFile;
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);
2011-12-20 18:20:44 +00:00
byte[] buffer = new byte[4096];
int read;
2011-12-20 18:20:44 +00:00
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
2011-12-20 18:20:44 +00:00
outputStream.close();
inputStream.close();
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();
}
2011-12-20 18:20:44 +00:00
}
2011-12-20 18:20:44 +00:00
private File constructOutputFile() throws IOException {
File sdCard = Environment.getExternalStorageDirectory();
File outputDirectory;
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();
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
}
2011-12-20 18:20:44 +00:00
private void saveToSdCard() {
progressDialog = new ProgressDialog(context);
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();
}
2011-12-20 18:20:44 +00:00
public boolean onLongClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.ConversationItem_save_to_sd_card);
builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_alert_icon));
2011-12-20 18:20:44 +00:00
builder.setCancelable(true);
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();
2011-12-20 18:20:44 +00:00
return true;
}
2011-12-20 18:20:44 +00:00
@Override
public void handleMessage(Message message) {
switch (message.what) {
case FAILURE:
Toast.makeText(context, R.string.ConversationItem_error_while_saving_attachment_to_sd_card,
Toast.LENGTH_LONG).show();
2011-12-20 18:20:44 +00:00
break;
case SUCCESS:
Toast.makeText(context, R.string.ConversationItem_success_exclamation,
Toast.LENGTH_LONG).show();
2011-12-20 18:20:44 +00:00
break;
case WRITE_ACCESS_FAILURE:
Toast.makeText(context, R.string.ConversationItem_unable_to_write_to_sd_card_exclamation,
Toast.LENGTH_LONG).show();
2011-12-20 18:20:44 +00:00
break;
}
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();
this.obtainMessage(SUCCESS).sendToTarget();
2011-12-20 18:20:44 +00:00
}
}
2011-12-20 18:20:44 +00:00
private class ThumbnailClickListener implements View.OnClickListener {
private final Slide slide;
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);
}
2011-12-20 18:20:44 +00:00
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.ConversationItem_view_secure_media_question);
builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_alert_icon));
2011-12-20 18:20:44 +00:00
builder.setCancelable(true);
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();
}
2011-12-20 18:20:44 +00:00
}
2011-12-20 18:20:44 +00:00
private class MmsDownloadClickListener implements View.OnClickListener {
public void onClick(View v) {
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);
2011-12-20 18:20:44 +00:00
Intent intent = new Intent(context, SendReceiveService.class);
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);
}
}
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);
}
}
}
2011-12-20 18:20:44 +00:00
private class ClickListener implements View.OnClickListener {
public void onClick(View v) {
if (messageRecord.isKeyExchange() &&
!messageRecord.isOutgoing() &&
2011-12-20 18:20:44 +00:00
!messageRecord.isProcessedKeyExchange() &&
!messageRecord.isStaleKeyExchange())
handleKeyExchangeClicked();
2014-03-01 22:17:55 +00:00
else if (messageRecord.isPendingFallbackApproval())
handleMessageApproval();
}
2011-12-20 18:20:44 +00:00
}
2014-03-01 22:17:55 +00:00
private void handleMessageApproval() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.ConversationItem_click_to_approve_dialog_title);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (messageRecord.isMms()) {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
database.markAsOutbox(messageRecord.getId());
database.markAsForcedSms(messageRecord.getId());
} else {
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
database.markAsOutbox(messageRecord.getId());
database.markAsForcedSms(messageRecord.getId());
}
Intent intent = new Intent(context, SendReceiveService.class);
intent.setAction(SendReceiveService.SEND_SMS_ACTION);
intent.putExtra(SendReceiveService.MASTER_SECRET_EXTRA, masterSecret);
context.startService(intent);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (messageRecord.isMms()) DatabaseFactory.getMmsDatabase(context).markAsSentFailed(messageRecord.getId());
else DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageRecord.getId());
}
});
builder.show();
}
private void handleAbortSecureSession() {
if (!messageRecord.isSecure()) return;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.ConversationActivity_abort_secure_session_confirmation);
builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_alert_icon));
builder.setCancelable(true);
builder.setMessage(R.string.ConversationActivity_are_you_sure_that_you_want_to_abort_this_secure_session_question);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (messageRecord.getRecipients().isSingleRecipient()) {
Recipient recipient = messageRecord.getRecipients().getPrimaryRecipient();
Session.abortSessionFor(context, recipient);
}
}
});
builder.setNegativeButton(R.string.no, null);
builder.show();
}
2011-12-20 18:20:44 +00:00
}