Show "you" in MediaPreviewActivity

Fixes #7038
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-10-04 11:35:16 -07:00
parent 677c7732cf
commit 9a876a3672
5 changed files with 27 additions and 12 deletions

View File

@ -74,7 +74,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.LongClickCopySpan;
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
@ -606,6 +605,7 @@ public class ConversationItem extends LinearLayout
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(slide.getUri(), slide.getContentType());
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, conversationRecipient.getAddress());
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, messageRecord.isOutgoing());
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getTimestamp());
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().getSize());

View File

@ -129,6 +129,7 @@ public class MediaGalleryAdapter extends StickyHeaderGridAdapter {
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
if (mediaRecord.getAddress() != null) {
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, mediaRecord.getAddress());

View File

@ -53,9 +53,10 @@ import java.io.IOException;
public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity implements RecipientModifiedListener {
private final static String TAG = MediaPreviewActivity.class.getSimpleName();
public static final String ADDRESS_EXTRA = "address";
public static final String DATE_EXTRA = "date";
public static final String SIZE_EXTRA = "size";
public static final String ADDRESS_EXTRA = "address";
public static final String DATE_EXTRA = "date";
public static final String SIZE_EXTRA = "size";
public static final String OUTGOING_EXTRA = "outgoing";
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
@ -69,6 +70,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private Recipient recipient;
private long date;
private long size;
private boolean outgoing;
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
@ -102,13 +104,16 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private void initializeActionBar() {
final CharSequence relativeTimeSpan;
if (date > 0) {
relativeTimeSpan = DateUtils.getExtendedRelativeTimeSpanString(this,dynamicLanguage.getCurrentLocale(),date);
} else {
relativeTimeSpan = getString(R.string.MediaPreviewActivity_draft);
}
getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you)
: recipient.toShortString());
if (outgoing) getSupportActionBar().setTitle(getString(R.string.MediaPreviewActivity_you));
else getSupportActionBar().setTitle(recipient.toShortString());
getSupportActionBar().setSubtitle(relativeTimeSpan);
}
@ -144,10 +149,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private void initializeResources() {
Address address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
mediaUri = getIntent().getData();
mediaType = getIntent().getType();
date = getIntent().getLongExtra(DATE_EXTRA, -1);
size = getIntent().getLongExtra(SIZE_EXTRA, 0);
mediaUri = getIntent().getData();
mediaType = getIntent().getType();
date = getIntent().getLongExtra(DATE_EXTRA, -1);
size = getIntent().getLongExtra(SIZE_EXTRA, 0);
outgoing = getIntent().getBooleanExtra(OUTGOING_EXTRA, false);
if (address != null) {
recipient = Recipient.from(this, address, true);

View File

@ -161,6 +161,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
this.threadPhotoRailView.setListener(mediaRecord -> {
Intent intent = new Intent(RecipientPreferenceActivity.this, MediaPreviewActivity.class);
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
intent.setDataAndType(mediaRecord.getAttachment().getDataUri(), mediaRecord.getContentType());

View File

@ -67,17 +67,20 @@ public class MediaDatabase extends Database {
private final DatabaseAttachment attachment;
private final Address address;
private final long date;
private final boolean outgoing;
private MediaRecord(DatabaseAttachment attachment, @Nullable Address address, long date) {
private MediaRecord(DatabaseAttachment attachment, @Nullable Address address, long date, boolean outgoing) {
this.attachment = attachment;
this.address = address;
this.date = date;
this.outgoing = outgoing;
}
public static MediaRecord from(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull Cursor cursor) {
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
DatabaseAttachment attachment = attachmentDatabase.getAttachment(masterSecret, cursor);
String serializedAddress = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS));
boolean outgoing = MessagingDatabase.Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_BOX)));
Address address = null;
if (serializedAddress != null) {
@ -92,7 +95,7 @@ public class MediaDatabase extends Database {
date = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.DATE_RECEIVED));
}
return new MediaRecord(attachment, address, date);
return new MediaRecord(attachment, address, date, outgoing);
}
public Attachment getAttachment() {
@ -111,6 +114,10 @@ public class MediaDatabase extends Database {
return date;
}
public boolean isOutgoing() {
return outgoing;
}
}