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