clear parent activities pending view intent before calling startAcitvityForResult()

This commit is contained in:
Daniel Gultsch 2018-09-16 10:09:22 +02:00
parent febd9cc3e0
commit b8474941c7
3 changed files with 567 additions and 538 deletions

View file

@ -902,7 +902,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void handleNegativeActivityResult(int requestCode) { private void handleNegativeActivityResult(int requestCode) {
switch (requestCode) { switch (requestCode) {
//nothing to do for now case ATTACHMENT_CHOICE_TAKE_PHOTO:
if (pendingTakePhotoUri.clear()) {
Log.d(Config.LOGTAG,"cleared pending photo uri after negative activity result");
}
break;
} }
} }
@ -1761,6 +1765,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
@Override
public void startActivityForResult(Intent intent, int requestCode) {
final Activity activity = getActivity();
if (activity instanceof ConversationsActivity) {
((ConversationsActivity) activity).clearPendingViewIntent();
}
super.startActivityForResult(intent, requestCode);
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -1872,6 +1885,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void reInit(Conversation conversation, Bundle extras) { public void reInit(Conversation conversation, Bundle extras) {
QuickLoader.set(conversation.getUuid()); QuickLoader.set(conversation.getUuid());
this.saveMessageDraftStopAudioPlayer(); this.saveMessageDraftStopAudioPlayer();
this.clearPending();
if (this.reInit(conversation, extras != null)) { if (this.reInit(conversation, extras != null)) {
if (extras != null) { if (extras != null) {
processExtras(extras); processExtras(extras);
@ -2662,11 +2676,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
private void clearPending() { private void clearPending() {
if (postponedActivityResult.pop() != null) { if (postponedActivityResult.clear()) {
Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left"); Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left");
} }
pendingScrollState.pop(); if (pendingScrollState.clear()) {
if (pendingTakePhotoUri.pop() != null) { Log.e(Config.LOGTAG,"cleared scroll state");
}
if (pendingTakePhotoUri.clear()) {
Log.e(Config.LOGTAG, "cleared pending photo uri"); Log.e(Config.LOGTAG, "cleared pending photo uri");
} }
} }

View file

@ -418,6 +418,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
@Override @Override
public void onConversationSelected(Conversation conversation) { public void onConversationSelected(Conversation conversation) {
clearPendingViewIntent();
if (ConversationFragment.getConversation(this) == conversation) { if (ConversationFragment.getConversation(this) == conversation) {
Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open"); Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
return; return;
@ -425,6 +426,12 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
openConversation(conversation, null); openConversation(conversation, null);
} }
public void clearPendingViewIntent() {
if (pendingViewIntent.clear()) {
Log.e(Config.LOGTAG, "cleared pending view intent");
}
}
private void displayToast(final String msg) { private void displayToast(final String msg) {
runOnUiThread(() -> Toast.makeText(ConversationsActivity.this, msg, Toast.LENGTH_SHORT).show()); runOnUiThread(() -> Toast.makeText(ConversationsActivity.this, msg, Toast.LENGTH_SHORT).show());
} }

View file

@ -46,4 +46,10 @@ public class PendingItem<T> {
public synchronized T peek() { public synchronized T peek() {
return item; return item;
} }
public synchronized boolean clear() {
boolean notNull = this.item != null;
this.item = null;
return notNull;
}
} }