Skip to content

Commit

Permalink
Show "you" in MediaPreviewActivity
Browse files Browse the repository at this point in the history
Fixes signalapp#7038
// FREEBIE
  • Loading branch information
moxie0 committed Oct 4, 2017
1 parent 677c773 commit 9a876a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/ConversationItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
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;
Expand Down Expand Up @@ -606,6 +605,7 @@ public void onClick(final View v, final Slide slide) {
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());

Expand Down
1 change: 1 addition & 0 deletions src/org/thoughtcrime/securesms/MediaGalleryAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void onClick(View v) {
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());
Expand Down
24 changes: 15 additions & 9 deletions src/org/thoughtcrime/securesms/MediaPreviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
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();

Expand All @@ -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) {
Expand Down Expand Up @@ -102,13 +104,16 @@ public void onModified(Recipient recipient) {

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);
}

Expand Down Expand Up @@ -144,10 +149,11 @@ private void initializeViews() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private void initializeToolbar() {
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());
Expand Down
11 changes: 9 additions & 2 deletions src/org/thoughtcrime/securesms/database/MediaDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ public static class MediaRecord {
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) {
Expand All @@ -92,7 +95,7 @@ public static MediaRecord from(@NonNull Context context, @NonNull MasterSecret m
date = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.DATE_RECEIVED));
}

return new MediaRecord(attachment, address, date);
return new MediaRecord(attachment, address, date, outgoing);
}

public Attachment getAttachment() {
Expand All @@ -111,6 +114,10 @@ public long getDate() {
return date;
}

public boolean isOutgoing() {
return outgoing;
}

}


Expand Down

0 comments on commit 9a876a3

Please sign in to comment.