refactored how view intents are handled
processing view intents before saved instance caused troubles when the activity was destroyed fixes #1969
This commit is contained in:
parent
89a05265ea
commit
198a9f2226
|
@ -158,9 +158,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
||||||
public Message findMessageWithFileAndUuid(final String uuid) {
|
public Message findMessageWithFileAndUuid(final String uuid) {
|
||||||
synchronized (this.messages) {
|
synchronized (this.messages) {
|
||||||
for (final Message message : this.messages) {
|
for (final Message message : this.messages) {
|
||||||
if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
|
if (message.getUuid().equals(uuid)
|
||||||
&& message.getEncryption() != Message.ENCRYPTION_PGP
|
&& message.getEncryption() != Message.ENCRYPTION_PGP
|
||||||
&& message.getUuid().equals(uuid)) {
|
&& (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable() != Message.Decision.NEVER)) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,8 +374,10 @@ public class NotificationService {
|
||||||
|
|
||||||
private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
|
private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
|
||||||
for (final Message message : messages) {
|
for (final Message message : messages) {
|
||||||
if ((message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) &&
|
if (message.getTransferable() != null
|
||||||
message.getTransferable() != null) {
|
&& (message.getType() == Message.TYPE_FILE
|
||||||
|
|| message.getType() == Message.TYPE_IMAGE
|
||||||
|
|| message.treatAsDownloadable() != Message.Decision.NEVER)) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,28 +415,23 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
|
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
|
||||||
final TaskStackBuilder stackBuilder = TaskStackBuilder
|
final Intent viewConversationIntent = new Intent(mXmppConnectionService,ConversationActivity.class);
|
||||||
.create(mXmppConnectionService);
|
viewConversationIntent.setAction(ConversationActivity.ACTION_VIEW_CONVERSATION);
|
||||||
stackBuilder.addParentStack(ConversationActivity.class);
|
|
||||||
|
|
||||||
final Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
|
||||||
ConversationActivity.class);
|
|
||||||
if (downloadMessageUuid != null) {
|
|
||||||
viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
|
|
||||||
} else {
|
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
|
||||||
}
|
|
||||||
if (conversationUuid != null) {
|
if (conversationUuid != null) {
|
||||||
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
|
||||||
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
|
||||||
}
|
}
|
||||||
if (downloadMessageUuid != null) {
|
if (downloadMessageUuid != null) {
|
||||||
viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
|
viewConversationIntent.putExtra(ConversationActivity.EXTRA_DOWNLOAD_UUID, downloadMessageUuid);
|
||||||
|
return PendingIntent.getActivity(mXmppConnectionService,
|
||||||
|
57,
|
||||||
|
viewConversationIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
} else {
|
||||||
|
return PendingIntent.getActivity(mXmppConnectionService,
|
||||||
|
58,
|
||||||
|
viewConversationIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
stackBuilder.addNextIntent(viewConversationIntent);
|
|
||||||
|
|
||||||
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createDownloadIntent(final Message message) {
|
private PendingIntent createDownloadIntent(final Message message) {
|
||||||
|
|
|
@ -69,11 +69,9 @@ import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
public class ConversationActivity extends XmppActivity
|
public class ConversationActivity extends XmppActivity
|
||||||
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
|
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
|
||||||
|
|
||||||
public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD";
|
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
||||||
|
|
||||||
public static final String VIEW_CONVERSATION = "viewConversation";
|
|
||||||
public static final String CONVERSATION = "conversationUuid";
|
public static final String CONVERSATION = "conversationUuid";
|
||||||
public static final String MESSAGE = "messageUuid";
|
public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
|
||||||
public static final String TEXT = "text";
|
public static final String TEXT = "text";
|
||||||
public static final String NICK = "nick";
|
public static final String NICK = "nick";
|
||||||
public static final String PRIVATE_MESSAGE = "pm";
|
public static final String PRIVATE_MESSAGE = "pm";
|
||||||
|
@ -1040,13 +1038,14 @@ public class ConversationActivity extends XmppActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(final Intent intent) {
|
protected void onNewIntent(final Intent intent) {
|
||||||
if (xmppConnectionServiceBound) {
|
if (intent != null && ACTION_VIEW_CONVERSATION.equals(intent.getAction())) {
|
||||||
if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) {
|
mOpenConverstaion = null;
|
||||||
|
if (xmppConnectionServiceBound) {
|
||||||
handleViewConversationIntent(intent);
|
handleViewConversationIntent(intent);
|
||||||
setIntent(new Intent());
|
intent.setAction(Intent.ACTION_MAIN);
|
||||||
|
} else {
|
||||||
|
setIntent(intent);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setIntent(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,6 +1127,8 @@ public class ConversationActivity extends XmppActivity
|
||||||
mPendingConferenceInvite = null;
|
mPendingConferenceInvite = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
if (xmppConnectionService.getAccounts().size() == 0) {
|
if (xmppConnectionService.getAccounts().size() == 0) {
|
||||||
if (mRedirected.compareAndSet(false, true)) {
|
if (mRedirected.compareAndSet(false, true)) {
|
||||||
if (Config.X509_VERIFICATION) {
|
if (Config.X509_VERIFICATION) {
|
||||||
|
@ -1143,17 +1144,14 @@ public class ConversationActivity extends XmppActivity
|
||||||
if (mRedirected.compareAndSet(false, true)) {
|
if (mRedirected.compareAndSet(false, true)) {
|
||||||
Account pendingAccount = xmppConnectionService.getPendingAccount();
|
Account pendingAccount = xmppConnectionService.getPendingAccount();
|
||||||
if (pendingAccount == null) {
|
if (pendingAccount == null) {
|
||||||
Intent intent = new Intent(this, StartConversationActivity.class);
|
Intent startConversationActivity = new Intent(this, StartConversationActivity.class);
|
||||||
intent.putExtra("init", true);
|
intent.putExtra("init", true);
|
||||||
startActivity(intent);
|
startActivity(startConversationActivity);
|
||||||
} else {
|
} else {
|
||||||
switchToAccount(pendingAccount, true);
|
switchToAccount(pendingAccount, true);
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) {
|
|
||||||
clearPending();
|
|
||||||
handleViewConversationIntent(getIntent());
|
|
||||||
} else if (selectConversationByUuid(mOpenConverstaion)) {
|
} else if (selectConversationByUuid(mOpenConverstaion)) {
|
||||||
if (mPanelOpen) {
|
if (mPanelOpen) {
|
||||||
showConversationsOverview();
|
showConversationsOverview();
|
||||||
|
@ -1165,6 +1163,10 @@ public class ConversationActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
this.mConversationFragment.reInit(getSelectedConversation());
|
this.mConversationFragment.reInit(getSelectedConversation());
|
||||||
mOpenConverstaion = null;
|
mOpenConverstaion = null;
|
||||||
|
} else if (intent != null && ACTION_VIEW_CONVERSATION.equals(intent.getAction())) {
|
||||||
|
clearPending();
|
||||||
|
handleViewConversationIntent(intent);
|
||||||
|
intent.setAction(Intent.ACTION_MAIN);
|
||||||
} else if (getSelectedConversation() == null) {
|
} else if (getSelectedConversation() == null) {
|
||||||
showConversationsOverview();
|
showConversationsOverview();
|
||||||
clearPending();
|
clearPending();
|
||||||
|
@ -1200,12 +1202,11 @@ public class ConversationActivity extends XmppActivity
|
||||||
if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService)) {
|
if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService)) {
|
||||||
openBatteryOptimizationDialogIfNeeded();
|
openBatteryOptimizationDialogIfNeeded();
|
||||||
}
|
}
|
||||||
setIntent(new Intent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleViewConversationIntent(final Intent intent) {
|
private void handleViewConversationIntent(final Intent intent) {
|
||||||
final String uuid = intent.getStringExtra(CONVERSATION);
|
final String uuid = intent.getStringExtra(CONVERSATION);
|
||||||
final String downloadUuid = intent.getStringExtra(MESSAGE);
|
final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID);
|
||||||
final String text = intent.getStringExtra(TEXT);
|
final String text = intent.getStringExtra(TEXT);
|
||||||
final String nick = intent.getStringExtra(NICK);
|
final String nick = intent.getStringExtra(NICK);
|
||||||
final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
|
final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
|
||||||
|
|
|
@ -471,7 +471,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) {
|
private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) {
|
||||||
Intent viewConversationIntent = new Intent(this,
|
Intent viewConversationIntent = new Intent(this,
|
||||||
ConversationActivity.class);
|
ConversationActivity.class);
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
viewConversationIntent.setAction(ConversationActivity.ACTION_VIEW_CONVERSATION);
|
||||||
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
||||||
conversation.getUuid());
|
conversation.getUuid());
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
|
@ -481,7 +481,6 @@ public abstract class XmppActivity extends Activity {
|
||||||
viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
|
viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
|
||||||
viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm);
|
viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm);
|
||||||
}
|
}
|
||||||
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
|
||||||
if (newTask) {
|
if (newTask) {
|
||||||
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
|
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
|
||||||
| Intent.FLAG_ACTIVITY_NEW_TASK
|
| Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
|
Loading…
Reference in a new issue