Add gallery button to MediaPreview

// FREEBIE
This commit is contained in:
FeuRenard 2016-09-20 18:53:44 +02:00 committed by Moxie Marlinspike
parent 43e1d452c7
commit 09ff8d5865
12 changed files with 33 additions and 7 deletions

View File

@ -308,6 +308,7 @@
<activity android:name=".MediaOverviewActivity"
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTask"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
<activity android:name=".DummyActivity"

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

View File

@ -9,4 +9,8 @@
android:title="@string/media_preview__save_title"
android:icon="@drawable/ic_save_white_24dp"
app:showAsAction="always"/>
<item android:id="@+id/media_preview__overview"
android:title="@string/media_preview__overview_title"
android:icon="@drawable/ic_photo_library_white_24dp"
app:showAsAction="ifRoom"/>
</menu>

View File

@ -1245,6 +1245,7 @@
<!-- media_preview -->
<string name="media_preview__save_title">Save</string>
<string name="media_preview__forward_title">Forward</string>
<string name="media_preview__overview_title">All images</string>
<!-- media_overview -->
<string name="media_overview__save_all">Save all</string>

View File

@ -542,6 +542,7 @@ public class ConversationItem extends LinearLayout
if (!messageRecord.isOutgoing()) intent.putExtra(MediaPreviewActivity.RECIPIENT_EXTRA, recipient.getRecipientId());
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getTimestamp());
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().getSize());
intent.putExtra(MediaPreviewActivity.THREAD_ID_EXTRA, messageRecord.getThreadId());
context.startActivity(intent);
} else {

View File

@ -41,6 +41,7 @@ public class ImageMediaAdapter extends CursorRecyclerViewAdapter<ViewHolder> {
private static final String TAG = ImageMediaAdapter.class.getSimpleName();
private final MasterSecret masterSecret;
private final long threadId;
public static class ViewHolder extends RecyclerView.ViewHolder {
public ThumbnailView imageView;
@ -51,9 +52,10 @@ public class ImageMediaAdapter extends CursorRecyclerViewAdapter<ViewHolder> {
}
}
public ImageMediaAdapter(Context context, MasterSecret masterSecret, Cursor c) {
public ImageMediaAdapter(Context context, MasterSecret masterSecret, Cursor c, long threadId) {
super(context, c);
this.masterSecret = masterSecret;
this.threadId = threadId;
}
@Override
@ -87,6 +89,7 @@ public class ImageMediaAdapter extends CursorRecyclerViewAdapter<ViewHolder> {
public void onClick(View v) {
Intent intent = new Intent(getContext(), MediaPreviewActivity.class);
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, imageRecord.getDate());
intent.putExtra(MediaPreviewActivity.THREAD_ID_EXTRA, threadId);
if (!TextUtils.isEmpty(imageRecord.getAddress())) {
Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(),

View File

@ -135,14 +135,19 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity i
final long recipientId = getIntent().getLongExtra(RECIPIENT_EXTRA, -1);
if (recipientId > -1) {
recipient = RecipientFactory.getRecipientForId(this, recipientId, true);
} else if (threadId > -1){
recipient = DatabaseFactory.getThreadDatabase(this).getRecipientsForThreadId(threadId).getPrimaryRecipient();
} else {
recipient = null;
}
if (recipient != null) {
recipient.addListener(new RecipientModifiedListener() {
@Override
public void onModified(Recipient recipient) {
initializeActionBar();
}
});
} else {
recipient = null;
}
}
@ -215,7 +220,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity i
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
Log.w(TAG, "onLoadFinished()");
gridView.setAdapter(new ImageMediaAdapter(this, masterSecret, cursor));
gridView.setAdapter(new ImageMediaAdapter(this, masterSecret, cursor, threadId));
noImages.setVisibility(gridView.getAdapter().getItemCount() > 0 ? View.GONE : View.VISIBLE);
invalidateOptionsMenu();
}

View File

@ -53,6 +53,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private final static String TAG = MediaPreviewActivity.class.getSimpleName();
public static final String RECIPIENT_EXTRA = "recipient";
public static final String THREAD_ID_EXTRA = "thread_id";
public static final String DATE_EXTRA = "date";
public static final String SIZE_EXTRA = "size";
@ -65,6 +66,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private Uri mediaUri;
private String mediaType;
private Recipient recipient;
private long threadId;
private long date;
private long size;
@ -148,6 +150,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
mediaType = getIntent().getType();
date = getIntent().getLongExtra(DATE_EXTRA, System.currentTimeMillis());
size = getIntent().getLongExtra(SIZE_EXTRA, 0);
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
if (recipientId > -1) {
recipient = RecipientFactory.getRecipientForId(this, recipientId, true);
@ -188,6 +191,12 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
video.cleanup();
}
private void showOverview() {
Intent intent = new Intent(this, MediaOverviewActivity.class);
intent.putExtra(MediaOverviewActivity.THREAD_ID_EXTRA, threadId);
startActivity(intent);
}
private void forward() {
Intent composeIntent = new Intent(this, ShareActivity.class);
composeIntent.putExtra(Intent.EXTRA_STREAM, mediaUri);
@ -212,6 +221,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
menu.clear();
MenuInflater inflater = this.getMenuInflater();
inflater.inflate(R.menu.media_preview, menu);
if (threadId == -1) menu.findItem(R.id.media_overview).setVisible(false);
return true;
}
@ -221,9 +231,10 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.media_preview__forward: forward(); return true;
case R.id.save: saveToDisk(); return true;
case android.R.id.home: finish(); return true;
case R.id.media_preview__overview: showOverview(); return true;
case R.id.media_preview__forward: forward(); return true;
case R.id.save: saveToDisk(); return true;
case android.R.id.home: finish(); return true;
}
return false;