prevent recipient listener Activity context leak

Resolves #2372
Resolves #2425
// FREEBIE
This commit is contained in:
Jake McGinty 2015-02-10 03:15:50 -08:00
parent f38677794a
commit b88e470594
2 changed files with 21 additions and 13 deletions

View File

@ -126,7 +126,8 @@ import static org.whispersystems.textsecure.internal.push.PushMessageProtos.Push
*/ */
public class ConversationActivity extends PassphraseRequiredActionBarActivity public class ConversationActivity extends PassphraseRequiredActionBarActivity
implements ConversationFragment.ConversationFragmentListener, implements ConversationFragment.ConversationFragmentListener,
AttachmentManager.AttachmentListener AttachmentManager.AttachmentListener,
RecipientModifiedListener
{ {
private static final String TAG = ConversationActivity.class.getSimpleName(); private static final String TAG = ConversationActivity.class.getSimpleName();
@ -232,6 +233,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
protected void onDestroy() { protected void onDestroy() {
saveDraft(); saveDraft();
recipients.removeListener(this);
unregisterReceiver(securityUpdateReceiver); unregisterReceiver(securityUpdateReceiver);
unregisterReceiver(groupUpdateReceiver); unregisterReceiver(groupUpdateReceiver);
MemoryCleaner.clean(masterSecret); MemoryCleaner.clean(masterSecret);
@ -764,12 +766,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT); distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA); masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
recipients.addListener(new RecipientModifiedListener() { recipients.addListener(this);
@Override }
public void onModified(Recipient recipient) {
initializeTitleBar(); @Override
} public void onModified(Recipient recipient) {
}); initializeTitleBar();
} }
private void initializeReceivers() { private void initializeReceivers() {

View File

@ -64,6 +64,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private MasterSecret masterSecret; private MasterSecret masterSecret;
private boolean paused;
private View loadingView; private View loadingView;
private TextView errorText; private TextView errorText;
@ -114,13 +115,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
} else { } else {
relativeTimeSpan = null; relativeTimeSpan = null;
} }
getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.getName()); getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.toShortString());
getSupportActionBar().setSubtitle(relativeTimeSpan); getSupportActionBar().setSubtitle(relativeTimeSpan);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
paused = false;
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
if (recipient != null) recipient.addListener(this); if (recipient != null) recipient.addListener(this);
initializeMedia(); initializeMedia();
@ -129,6 +131,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
paused = true;
if (recipient != null) recipient.removeListener(this); if (recipient != null) recipient.removeListener(this);
cleanupMedia(); cleanupMedia();
} }
@ -140,7 +143,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
setIntent(intent); setIntent(intent);
initializeResources(); initializeResources();
initializeActionBar(); initializeActionBar();
initializeMedia();
} }
private void initializeViews() { private void initializeViews() {
@ -154,9 +156,9 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
final long recipientId = getIntent().getLongExtra(RECIPIENT_EXTRA, -1); final long recipientId = getIntent().getLongExtra(RECIPIENT_EXTRA, -1);
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA); masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
mediaUri = getIntent().getData(); mediaUri = getIntent().getData();
mediaType = getIntent().getType(); mediaType = getIntent().getType();
date = getIntent().getLongExtra(DATE_EXTRA, -1); date = getIntent().getLongExtra(DATE_EXTRA, -1);
if (recipientId > -1) { if (recipientId > -1) {
recipient = RecipientFactory.getRecipientForId(this, recipientId, true); recipient = RecipientFactory.getRecipientForId(this, recipientId, true);
@ -211,8 +213,12 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
@Override @Override
protected void onPostExecute(Bitmap bitmap) { protected void onPostExecute(Bitmap bitmap) {
loadingView.setVisibility(View.GONE); if (paused) {
if (bitmap != null) bitmap.recycle();
return;
}
loadingView.setVisibility(View.GONE);
if (bitmap == null) { if (bitmap == null) {
errorText.setText(R.string.MediaPreviewActivity_cant_display); errorText.setText(R.string.MediaPreviewActivity_cant_display);
errorText.setVisibility(View.VISIBLE); errorText.setVisibility(View.VISIBLE);