mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Use "singleTask" to ensure a single ConversationActivity instance.
1) Mark the Activity as singleTask. 2) Process onNewIntent for updates. 3) Propagate onNewIntent to the ConversationFragment. Fixes #2232 Fixes #1532 Fixes #146 Fixes #851 Closes #2266
This commit is contained in:
parent
d7419caa4b
commit
1443d846c4
@ -107,6 +107,7 @@
|
||||
|
||||
<activity android:name=".ConversationActivity"
|
||||
android:windowSoftInputMode="stateUnchanged"
|
||||
android:launchMode="singleTask"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".GroupCreateActivity"
|
||||
|
@ -178,19 +178,29 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
initializeReceivers();
|
||||
initializeViews();
|
||||
initializeResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
initializeDraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
saveDraft();
|
||||
protected void onNewIntent(Intent intent) {
|
||||
if (!Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent()) {
|
||||
saveDraft();
|
||||
attachmentManager.clear();
|
||||
composeText.setText("");
|
||||
}
|
||||
|
||||
setIntent(intent);
|
||||
|
||||
initializeResources();
|
||||
initializeDraft();
|
||||
|
||||
ConversationFragment fragment = getFragment();
|
||||
|
||||
if (fragment != null) {
|
||||
fragment.onNewIntent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -220,6 +230,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
saveDraft();
|
||||
unregisterReceiver(securityUpdateReceiver);
|
||||
unregisterReceiver(groupUpdateReceiver);
|
||||
MemoryCleaner.clean(masterSecret);
|
||||
@ -718,24 +729,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getLongArrayExtra(RECIPIENTS_EXTRA), true);
|
||||
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
||||
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
|
||||
ThreadDatabase.DistributionTypes.DEFAULT);
|
||||
sendButton = (SendButton)findViewById(R.id.send_button);
|
||||
composeText = (EditText)findViewById(R.id.embedded_text_editor);
|
||||
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
||||
charactersLeft = (TextView)findViewById(R.id.space_left);
|
||||
emojiDrawer = (EmojiDrawer)findViewById(R.id.emoji_drawer);
|
||||
emojiToggle = (EmojiToggle)findViewById(R.id.emoji_toggle);
|
||||
private void initializeViews() {
|
||||
sendButton = (SendButton) findViewById(R.id.send_button);
|
||||
composeText = (EditText) findViewById(R.id.embedded_text_editor);
|
||||
charactersLeft = (TextView) findViewById(R.id.space_left);
|
||||
emojiDrawer = (EmojiDrawer) findViewById(R.id.emoji_drawer);
|
||||
emojiToggle = (EmojiToggle) findViewById(R.id.emoji_toggle);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
emojiToggle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
attachmentAdapter = new AttachmentTypeSelectorAdapter(this);
|
||||
attachmentManager = new AttachmentManager(this, this);
|
||||
attachmentAdapter = new AttachmentTypeSelectorAdapter(this);
|
||||
attachmentManager = new AttachmentManager(this, this);
|
||||
|
||||
SendButtonListener sendButtonListener = new SendButtonListener();
|
||||
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
|
||||
@ -750,6 +756,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
composeText.setOnFocusChangeListener(composeKeyPressedListener);
|
||||
emojiDrawer.setComposeEditText(composeText);
|
||||
emojiToggle.setOnClickListener(new EmojiToggleListener());
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getLongArrayExtra(RECIPIENTS_EXTRA), true);
|
||||
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
||||
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
||||
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
||||
|
||||
recipients.addListener(new RecipientModifiedListener() {
|
||||
@Override
|
||||
@ -906,9 +919,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
if (this.threadId <= 0 || this.recipients == null || this.recipients.isEmpty())
|
||||
return;
|
||||
|
||||
final Drafts drafts = getDraftsForCurrentState();
|
||||
|
||||
final long thisThreadId = this.threadId;
|
||||
final Drafts drafts = getDraftsForCurrentState();
|
||||
final long thisThreadId = this.threadId;
|
||||
final MasterSecret thisMasterSecret = this.masterSecret.parcelClone();
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@ -1001,8 +1013,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
boolean refreshFragment = (threadId != this.threadId);
|
||||
this.threadId = threadId;
|
||||
|
||||
ConversationFragment fragment = (ConversationFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.fragment_content);
|
||||
ConversationFragment fragment = getFragment();
|
||||
|
||||
if (fragment == null) {
|
||||
return;
|
||||
@ -1018,6 +1029,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
fragment.scrollToBottom();
|
||||
}
|
||||
|
||||
private ConversationFragment getFragment() {
|
||||
return (ConversationFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_content);
|
||||
}
|
||||
|
||||
private void sendMessage() {
|
||||
try {
|
||||
final Recipients recipients = getRecipients();
|
||||
|
@ -78,6 +78,16 @@ public class ConversationFragment extends ListFragment
|
||||
this.listener = (ConversationFragmentListener)activity;
|
||||
}
|
||||
|
||||
public void onNewIntent() {
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
|
||||
initializeResources();
|
||||
initializeListAdapter();
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.masterSecret = this.getActivity().getIntent().getParcelableExtra("master_secret");
|
||||
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
|
||||
|
Loading…
Reference in New Issue
Block a user