diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 98abdd2a90..782d3ef562 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -206,6 +206,7 @@ -1) { - recipient = RecipientFactory.getRecipientForId(this, recipientId, true); - recipient.addListener(new RecipientModifiedListener() { - @Override - public void onModified(Recipient recipient) { - initializeActionBar(); - } - }); - } else { - recipient = null; - } - + public void onModified(Recipient recipient) { initializeActionBar(); - - 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(); - finish(); - } - - Log.w(TAG, "Loading Part URI: " + mediaUri); - - if (mediaType != null && mediaType.startsWith("image/")) { - displayImage(); - } } private void initializeActionBar() { @@ -148,20 +116,77 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity { } 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(); } - private void initializeResources() { + @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); + + if (recipientId > -1) { + recipient = RecipientFactory.getRecipientForId(this, recipientId, true); + recipient.addListener(this); + } else { + recipient = null; + } + } + + 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(); + finish(); + } + + Log.w(TAG, "Loading Part URI: " + mediaUri); + + if (mediaType != null && mediaType.startsWith("image/")) { + displayImage(); + } + } + + private void cleanupMedia() { + image.setImageDrawable(null); + if (bitmap != null) { + bitmap.recycle(); + bitmap = null; + } + } private void displayImage() { new AsyncTask() { @@ -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();