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) {
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
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -1872,6 +1885,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void reInit(Conversation conversation, Bundle extras) {
QuickLoader.set(conversation.getUuid());
this.saveMessageDraftStopAudioPlayer();
this.clearPending();
if (this.reInit(conversation, extras != null)) {
if (extras != null) {
processExtras(extras);
@ -2662,11 +2676,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
private void clearPending() {
if (postponedActivityResult.pop() != null) {
if (postponedActivityResult.clear()) {
Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left");
}
pendingScrollState.pop();
if (pendingTakePhotoUri.pop() != null) {
if (pendingScrollState.clear()) {
Log.e(Config.LOGTAG,"cleared scroll state");
}
if (pendingTakePhotoUri.clear()) {
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 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);
}
@ -418,6 +418,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
@Override
public void onConversationSelected(Conversation conversation) {
clearPendingViewIntent();
if (ConversationFragment.getConversation(this) == conversation) {
Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
return;
@ -425,6 +426,12 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
openConversation(conversation, null);
}
public void clearPendingViewIntent() {
if (pendingViewIntent.clear()) {
Log.e(Config.LOGTAG, "cleared pending view intent");
}
}
private void displayToast(final String msg) {
runOnUiThread(() -> Toast.makeText(ConversationsActivity.this, msg, Toast.LENGTH_SHORT).show());
}
@ -465,7 +472,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try {
fragmentTransaction.commit();
} 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'
return;
}
@ -505,7 +512,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try {
fm.popBackStack();
} 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;
}
@ -626,7 +633,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
try {
getFragmentManager().popBackStack();
} 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
}
return;

View file

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