mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 15:38:27 +00:00
parent
9939461d9e
commit
14644077e7
@ -611,6 +611,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, messageRecord.isOutgoing());
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, messageRecord.isOutgoing());
|
||||||
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getTimestamp());
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getTimestamp());
|
||||||
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().getSize());
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().getSize());
|
||||||
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, false);
|
||||||
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} else if (slide.getUri() != null) {
|
} else if (slide.getUri() != null) {
|
||||||
|
@ -137,6 +137,7 @@ class MediaGalleryAdapter extends StickyHeaderGridAdapter {
|
|||||||
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
||||||
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
|
||||||
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
||||||
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, true);
|
||||||
|
|
||||||
if (mediaRecord.getAddress() != null) {
|
if (mediaRecord.getAddress() != null) {
|
||||||
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, mediaRecord.getAddress());
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, mediaRecord.getAddress());
|
||||||
|
@ -77,6 +77,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
public static final String DATE_EXTRA = "date";
|
public static final String DATE_EXTRA = "date";
|
||||||
public static final String SIZE_EXTRA = "size";
|
public static final String SIZE_EXTRA = "size";
|
||||||
public static final String OUTGOING_EXTRA = "outgoing";
|
public static final String OUTGOING_EXTRA = "outgoing";
|
||||||
|
public static final String LEFT_IS_RECENT_EXTRA = "left_is_recent";
|
||||||
|
|
||||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||||
|
|
||||||
@ -87,6 +88,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
private String initialMediaType;
|
private String initialMediaType;
|
||||||
private long initialMediaSize;
|
private long initialMediaSize;
|
||||||
private Recipient conversationRecipient;
|
private Recipient conversationRecipient;
|
||||||
|
private boolean leftIsRecent;
|
||||||
|
|
||||||
private int restartItem = -1;
|
private int restartItem = -1;
|
||||||
|
|
||||||
@ -179,6 +181,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
initialMediaUri = getIntent().getData();
|
initialMediaUri = getIntent().getData();
|
||||||
initialMediaType = getIntent().getType();
|
initialMediaType = getIntent().getType();
|
||||||
initialMediaSize = getIntent().getLongExtra(SIZE_EXTRA, 0);
|
initialMediaSize = getIntent().getLongExtra(SIZE_EXTRA, 0);
|
||||||
|
leftIsRecent = getIntent().getBooleanExtra(LEFT_IS_RECENT_EXTRA, false);
|
||||||
restartItem = -1;
|
restartItem = -1;
|
||||||
|
|
||||||
if (address != null) {
|
if (address != null) {
|
||||||
@ -294,14 +297,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Pair<Cursor, Integer>> onCreateLoader(int id, Bundle args) {
|
public Loader<Pair<Cursor, Integer>> onCreateLoader(int id, Bundle args) {
|
||||||
return new PagingMediaLoader(this, conversationRecipient, initialMediaUri);
|
return new PagingMediaLoader(this, conversationRecipient, initialMediaUri, leftIsRecent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<Pair<Cursor, Integer>> loader, @Nullable Pair<Cursor, Integer> data) {
|
public void onLoadFinished(Loader<Pair<Cursor, Integer>> loader, @Nullable Pair<Cursor, Integer> data) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
CursorPagerAdapter adapter = new CursorPagerAdapter(this, masterSecret, GlideApp.with(this), getWindow(), data.first, data.second);
|
CursorPagerAdapter adapter = new CursorPagerAdapter(this, masterSecret, GlideApp.with(this), getWindow(), data.first, data.second, leftIsRecent);
|
||||||
mediaPager.setAdapter(adapter);
|
mediaPager.setAdapter(adapter);
|
||||||
adapter.setActive(true);
|
adapter.setActive(true);
|
||||||
|
|
||||||
@ -423,13 +426,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
private final GlideRequests glideRequests;
|
private final GlideRequests glideRequests;
|
||||||
private final Window window;
|
private final Window window;
|
||||||
private final Cursor cursor;
|
private final Cursor cursor;
|
||||||
|
private final boolean leftIsRecent;
|
||||||
|
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private int autoPlayPosition;
|
private int autoPlayPosition;
|
||||||
|
|
||||||
CursorPagerAdapter(@NonNull Context context, @NonNull MasterSecret masterSecret,
|
CursorPagerAdapter(@NonNull Context context, @NonNull MasterSecret masterSecret,
|
||||||
@NonNull GlideRequests glideRequests, @NonNull Window window,
|
@NonNull GlideRequests glideRequests, @NonNull Window window,
|
||||||
@NonNull Cursor cursor, int autoPlayPosition)
|
@NonNull Cursor cursor, int autoPlayPosition, boolean leftIsRecent)
|
||||||
{
|
{
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
this.masterSecret = masterSecret;
|
this.masterSecret = masterSecret;
|
||||||
@ -437,6 +441,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
this.window = window;
|
this.window = window;
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
this.autoPlayPosition = autoPlayPosition;
|
this.autoPlayPosition = autoPlayPosition;
|
||||||
|
this.leftIsRecent = leftIsRecent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActive(boolean active) {
|
public void setActive(boolean active) {
|
||||||
@ -460,10 +465,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
View itemView = LayoutInflater.from(context).inflate(R.layout.media_view_page, container, false);
|
View itemView = LayoutInflater.from(context).inflate(R.layout.media_view_page, container, false);
|
||||||
MediaView mediaView = itemView.findViewById(R.id.media_view);
|
MediaView mediaView = itemView.findViewById(R.id.media_view);
|
||||||
boolean autoplay = position == autoPlayPosition;
|
boolean autoplay = position == autoPlayPosition;
|
||||||
|
int cursorPosition = getCursorPosition(position);
|
||||||
|
|
||||||
autoPlayPosition = -1;
|
autoPlayPosition = -1;
|
||||||
|
|
||||||
cursor.moveToPosition(position);
|
cursor.moveToPosition(cursorPosition);
|
||||||
|
|
||||||
MediaRecord mediaRecord = MediaRecord.from(context, masterSecret, cursor);
|
MediaRecord mediaRecord = MediaRecord.from(context, masterSecret, cursor);
|
||||||
|
|
||||||
@ -490,7 +496,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MediaItem getMediaItemFor(int position) {
|
public MediaItem getMediaItemFor(int position) {
|
||||||
cursor.moveToPosition(position);
|
cursor.moveToPosition(getCursorPosition(position));
|
||||||
MediaRecord mediaRecord = MediaRecord.from(context, masterSecret, cursor);
|
MediaRecord mediaRecord = MediaRecord.from(context, masterSecret, cursor);
|
||||||
Address address = mediaRecord.getAddress();
|
Address address = mediaRecord.getAddress();
|
||||||
|
|
||||||
@ -508,6 +514,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
MediaView mediaView = mediaViews.get(position);
|
MediaView mediaView = mediaViews.get(position);
|
||||||
if (mediaView != null) mediaView.pause();
|
if (mediaView != null) mediaView.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCursorPosition(int position) {
|
||||||
|
if (leftIsRecent) return position;
|
||||||
|
else return cursor.getCount() - 1 - position;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MediaItem {
|
private static class MediaItem {
|
||||||
|
@ -161,6 +161,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
||||||
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
|
||||||
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
||||||
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, true);
|
||||||
intent.setDataAndType(mediaRecord.getAttachment().getDataUri(), mediaRecord.getContentType());
|
intent.setDataAndType(mediaRecord.getAttachment().getDataUri(), mediaRecord.getContentType());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
@ -22,11 +22,13 @@ public class PagingMediaLoader extends AsyncLoader<Pair<Cursor, Integer>> {
|
|||||||
|
|
||||||
private final Recipient recipient;
|
private final Recipient recipient;
|
||||||
private final Uri uri;
|
private final Uri uri;
|
||||||
|
private final boolean leftIsRecent;
|
||||||
|
|
||||||
public PagingMediaLoader(@NonNull Context context, @NonNull Recipient recipient, @NonNull Uri uri) {
|
public PagingMediaLoader(@NonNull Context context, @NonNull Recipient recipient, @NonNull Uri uri, boolean leftIsRecent) {
|
||||||
super(context);
|
super(context);
|
||||||
this.recipient = recipient;
|
this.recipient = recipient;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
this.leftIsRecent = leftIsRecent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -40,7 +42,7 @@ public class PagingMediaLoader extends AsyncLoader<Pair<Cursor, Integer>> {
|
|||||||
Uri attachmentUri = PartAuthority.getAttachmentDataUri(attachmentId);
|
Uri attachmentUri = PartAuthority.getAttachmentDataUri(attachmentId);
|
||||||
|
|
||||||
if (attachmentUri.equals(uri)) {
|
if (attachmentUri.equals(uri)) {
|
||||||
return new Pair<>(cursor, cursor.getPosition());
|
return new Pair<>(cursor, leftIsRecent ? cursor.getPosition() : cursor.getCount() - 1 - cursor.getPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user