diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 98abdd2a90..782d3ef562 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -206,6 +206,7 @@
0) {
+ relativeTimeSpan = DateUtils.getRelativeTimeSpanString(date,
+ System.currentTimeMillis(),
+ DateUtils.MINUTE_IN_MILLIS);
+ } else {
+ relativeTimeSpan = null;
+ }
+ getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.getName());
+ getSupportActionBar().setSubtitle(relativeTimeSpan);
+ }
+
@Override
public void onResume() {
super.onResume();
dynamicLanguage.onResume(this);
+ if (recipient != null) recipient.addListener(this);
+ initializeMedia();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (recipient != null) recipient.removeListener(this);
+ cleanupMedia();
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ if (recipient != null) recipient.removeListener(this);
+ setIntent(intent);
+ initializeResources();
+ initializeActionBar();
+ initializeMedia();
+ }
+
+ private void initializeViews() {
+ loadingView = findViewById(R.id.loading_indicator);
+ errorText = (TextView) findViewById(R.id.error);
+ image = (ImageView) findViewById(R.id.image);
+ imageAttacher = new PhotoViewAttacher(image);
+ }
+ private void initializeResources() {
final long recipientId = getIntent().getLongExtra(RECIPIENT_EXTRA, -1);
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
- mediaUri = getIntent().getData();
- mediaType = getIntent().getType();
- date = getIntent().getLongExtra(DATE_EXTRA, -1);
+ mediaUri = getIntent().getData();
+ mediaType = getIntent().getType();
+ date = getIntent().getLongExtra(DATE_EXTRA, -1);
if (recipientId > -1) {
recipient = RecipientFactory.getRecipientForId(this, recipientId, true);
- recipient.addListener(new RecipientModifiedListener() {
- @Override
- public void onModified(Recipient recipient) {
- initializeActionBar();
- }
- });
+ recipient.addListener(this);
} else {
recipient = null;
}
+ }
- initializeActionBar();
-
+ private void initializeMedia() {
if (!isContentTypeSupported(mediaType)) {
Log.w(TAG, "Unsupported media type sent to MediaPreviewActivity, finishing.");
Toast.makeText(getApplicationContext(), R.string.MediaPreviewActivity_unssuported_media_type, Toast.LENGTH_LONG).show();
@@ -137,32 +180,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity {
}
}
- private void initializeActionBar() {
- final CharSequence relativeTimeSpan;
- if (date > 0) {
- relativeTimeSpan = DateUtils.getRelativeTimeSpanString(date,
- System.currentTimeMillis(),
- DateUtils.MINUTE_IN_MILLIS);
- } else {
- relativeTimeSpan = null;
+ private void cleanupMedia() {
+ image.setImageDrawable(null);
+ if (bitmap != null) {
+ bitmap.recycle();
+ bitmap = null;
}
- getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.getName());
- getSupportActionBar().setSubtitle(relativeTimeSpan);
-
}
- @Override
- public void onPause() {
- super.onPause();
- }
-
- private void initializeResources() {
- loadingView = findViewById(R.id.loading_indicator);
- errorText = (TextView) findViewById(R.id.error);
- image = (ImageView) findViewById(R.id.image);
- imageAttacher = new PhotoViewAttacher(image);
- }
-
private void displayImage() {
new AsyncTask() {
@Override
@@ -192,6 +217,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity {
errorText.setText(R.string.MediaPreviewActivity_cant_display);
errorText.setVisibility(View.VISIBLE);
} else {
+ MediaPreviewActivity.this.bitmap = bitmap;
image.setImageBitmap(bitmap);
image.setVisibility(View.VISIBLE);
imageAttacher.update();