diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java index 3c943c309..670e54c1d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -585,6 +585,12 @@ public class DelegateBase implements DlgClickNotify, } protected boolean isVisible() { return m_isVisible; } + + protected boolean handleNewIntent( Intent intent ) { + DbgUtils.logf( "%s.handleNewIntent(%s): not handling", + getClass().getSimpleName(), intent.toString() ); + return false; // not handled + } ////////////////////////////////////////////////// // MultiService.MultiEventListener interface @@ -681,5 +687,4 @@ public class DelegateBase implements DlgClickNotify, { Assert.fail(); } - } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java index bacde5c1c..a437e0553 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java @@ -20,14 +20,18 @@ package org.eehouse.android.xw4; +import android.app.Activity; import android.app.Dialog; +import android.content.Intent; import android.os.Bundle; public class DualpaneDelegate extends DelegateBase { + private Activity m_activity; public DualpaneDelegate( Delegator delegator, Bundle sis ) { super( delegator, sis, R.layout.dualcontainer ); + m_activity = delegator.getActivity(); } @Override @@ -46,4 +50,13 @@ public class DualpaneDelegate extends DelegateBase { { DlgDelegate.onPrepareDialog( dlgId.ordinal(), dialog ); } + + @Override + protected boolean handleNewIntent( Intent intent ) + { + MainActivity main = (MainActivity)m_activity; + boolean handled = main.dispatchNewIntent( intent ); + DbgUtils.logf( "DualpaneDelegate.handleNewIntent() => %b", handled ); + return handled; + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index f62f8a06b..db4c92e68 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -955,16 +955,18 @@ public class GamesListDelegate extends ListDelegateBase getDictForLangIf(); } // init - // called when we're brought to the front (probably as a result of - // notification) - protected void onNewIntent( Intent intent ) + @Override + protected boolean handleNewIntent( Intent intent ) { - // super.onNewIntent( intent ); + DbgUtils.logf( "GamesListDelegate.handleNewIntent(%s)", + intent.toString() ); + m_launchedGames.clear(); Assert.assertNotNull( intent ); invalRelayIDs( intent.getStringArrayExtra( RELAYIDS_EXTRA ) ); reloadGame( intent.getLongExtra( ROWID_EXTRA, -1 ) ); tryStartsFromIntent( intent ); + return true; // handled it } protected void onStop() diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java index b956006f9..3ea0c4007 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java @@ -93,10 +93,56 @@ public class MainActivity extends XWActivity { super.onNewIntent( intent ); - // HACK!!!!! FIXME - if ( m_dlgt instanceof GamesListDelegate ) { - ((GamesListDelegate)m_dlgt).onNewIntent( intent ); + m_dlgt.handleNewIntent( intent ); + } + + /** + * Run down the list of fragments until one handles the intent. If no + * visible one does, pop hidden ones into view until one of them + * does. Yes, this will take us back to GamesList being visible even if + * nothing handles the intent, but at least now all are handled by + * GamesList anyway. + */ + protected boolean dispatchNewIntent( Intent intent ) + { + boolean handled = false; + FragmentManager fm = getSupportFragmentManager(); + + // First try non-left-most fragments, if any. Once we've eliminated + // them we can just iterate on the leftmost fragment. + int nNonLeft = m_maxPanes - 1; + // include paged-to-left invisible views + int viewCount = m_root.getChildCount(); + for ( int ii = nNonLeft; !handled && 0 < ii; --ii ) { + View child = m_root.getChildAt( viewCount - ii ); + Fragment frag = fm.findFragmentById( child.getId() ); + handled = ((XWFragment)frag).getDelegate().handleNewIntent( intent ); } + + while ( !handled ) { + // Now iterate on the leftmost, popping if necessary to page new + // ones into place + int childCount = m_root.getChildCount(); + int hiddenCount = Math.max( 0, childCount - m_maxPanes ); + for ( int ii = hiddenCount; ii >= 0; --ii ) { + View child = m_root.getChildAt( ii ); + Fragment frag = fm.findFragmentById( child.getId() ); + // DbgUtils.logf( "left-most case (child %d): %s", hiddenCount, + // frag.getClass().getSimpleName() ); + handled = ((XWFragment)frag).getDelegate() + .handleNewIntent( intent ); + + if ( handled ) { + break; + } else if ( ii > 0 ) { + DbgUtils.logf( "popping %s", + frag.getClass().getSimpleName() ); + fm.popBackStackImmediate(); // callback removes view + } + } + } + + return handled; } ////////////////////////////////////////////////////////////////////// diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java index c70a2092e..52e43c774 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java @@ -162,6 +162,8 @@ public class XWFragment extends Fragment main.addFragmentForResult( fragment, extras, code ); } + public DelegateBase getDelegate() { return m_dlgt; } + // FragActivity.OrientChangeListener public void orientationChanged() { @@ -184,5 +186,3 @@ public class XWFragment extends Fragment return getListView().getAdapter(); } } - -