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

@ -114,7 +114,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false); private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
private static boolean isViewOrShareIntent(Intent i) { private static boolean isViewOrShareIntent(Intent i) {
Log.d(Config.LOGTAG,"action: "+(i == null ? null : i.getAction())); Log.d(Config.LOGTAG, "action: " + (i == null ? null : i.getAction()));
return i != null && VIEW_AND_SHARE_ACTIONS.contains(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION); return i != null && VIEW_AND_SHARE_ACTIONS.contains(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
} }
@ -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());
} }
@ -465,7 +472,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try { try {
fragmentTransaction.commit(); fragmentTransaction.commit();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.w(Config.LOGTAG,"sate loss while opening conversation",e); Log.w(Config.LOGTAG, "sate loss while opening conversation", e);
//allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored' //allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
return; return;
} }
@ -505,7 +512,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try { try {
fm.popBackStack(); fm.popBackStack();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.w(Config.LOGTAG,"Unable to pop back stack after pressing home button"); Log.w(Config.LOGTAG, "Unable to pop back stack after pressing home button");
} }
return true; return true;
} }
@ -626,7 +633,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try { try {
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.w(Config.LOGTAG,"state loss while popping back state after archiving conversation",e); Log.w(Config.LOGTAG, "state loss while popping back state after archiving conversation", e);
//this usually means activity is no longer active; meaning on the next open we will run through this again //this usually means activity is no longer active; meaning on the next open we will run through this again
} }
return; return;

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;
}
} }