diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardFrag.java index 79fce7a33..4e43aa2b5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardFrag.java @@ -24,6 +24,8 @@ import android.os.Bundle; public class BoardFrag extends XWFragment { + public BoardFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java index 7176fc97f..8317057f4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java @@ -265,7 +265,7 @@ public class ChatDelegate extends DelegateBase { bundle.putBooleanArray( INTENT_KEY_LOCS, locs ); if ( delegator.inDPMode() ) { - delegator.addFragment( new ChatFrag(), bundle ); + delegator.addFragment( new ChatFrag( delegator ), bundle ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, ChatActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatFrag.java index add426c10..0b3fd7fd3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatFrag.java @@ -23,6 +23,8 @@ import android.os.Bundle; public class ChatFrag extends XWFragment { + public ChatFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseDelegate.java index 63a931f0a..9b3659e36 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseDelegate.java @@ -424,7 +424,7 @@ public class DictBrowseDelegate extends ListDelegateBase private static void launch( Delegator delegator, Bundle bundle ) { if ( delegator.inDPMode() ) { - delegator.addFragment( new DictBrowseFrag(), bundle ); + delegator.addFragment( new DictBrowseFrag( delegator ), bundle ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, DictBrowseActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseFrag.java index 8fd890dbf..22b10d1cf 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictBrowseFrag.java @@ -23,6 +23,8 @@ import android.os.Bundle; public class DictBrowseFrag extends XWFragment { + public DictBrowseFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java index 236c352ce..54e0075d3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -1450,7 +1450,7 @@ public class DictsDelegate extends ListDelegateBase public static void start( Delegator delegator ) { if ( delegator.inDPMode() ) { - delegator.addFragment( new DictsFrag(), null ); + delegator.addFragment( new DictsFrag( delegator ), null ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, DictsActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsFrag.java index 5a49b6b7b..0aa712387 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsFrag.java @@ -23,6 +23,8 @@ import android.os.Bundle; public class DictsFrag extends XWFragment { + public DictsFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index 14c05c86a..fbbb68eaf 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -1234,7 +1234,8 @@ public class GameConfigDelegate extends DelegateBase bundle.putBoolean( INTENT_FORRESULT_ROWID, true ); if ( delegator.inDPMode() ) { - delegator.addFragmentForResult( new GameConfigFrag(), bundle, requestCode ); + delegator.addFragmentForResult( new GameConfigFrag( delegator ), + bundle, requestCode ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, GameConfigActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigFrag.java index e835da137..8cce822e9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigFrag.java @@ -23,6 +23,8 @@ import android.os.Bundle; public class GameConfigFrag extends XWFragment { + public GameConfigFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 322450d7f..a83b3a118 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -853,7 +853,7 @@ public class GameUtils { { Bundle extras = makeLaunchExtras( rowid, invited ); if ( delegator.inDPMode() ) { - delegator.addFragment( new BoardFrag(), extras ); + delegator.addFragment( new BoardFrag( delegator ), extras ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, BoardActivity.class ); @@ -1093,7 +1093,7 @@ public class GameUtils { extras.putLong( INTENT_KEY_ROWID, rowid ); if ( delegator.inDPMode() ) { - delegator.addFragment( new GameConfigFrag(), extras ); + delegator.addFragment( new GameConfigFrag( delegator ), extras ); } else { Activity activity = delegator.getActivity(); Intent intent = new Intent( activity, GameConfigActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListFrag.java index f9828a693..9cfe6a83f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListFrag.java @@ -24,6 +24,8 @@ import android.os.Bundle; public class GamesListFrag extends XWFragment { + public GamesListFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { 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 d8abc7f71..f038515ec 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java @@ -87,7 +87,8 @@ public class MainActivity extends XWActivity if ( savedInstanceState == null ) { // In case this activity was started with special instructions from an Intent, // pass the Intent's extras to the fragment as arguments - addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null ); + addFragmentImpl( new GamesListFrag(null), + getIntent().getExtras(), null ); } } } // onCreate @@ -217,7 +218,7 @@ public class MainActivity extends XWActivity @Override public void addFragment( XWFragment fragment, Bundle extras ) { - addFragmentImpl( fragment, extras, this ); + addFragmentImpl( fragment, extras, fragment.getParent() ); } @Override @@ -230,7 +231,7 @@ public class MainActivity extends XWActivity = new WeakReference(fragment.getDelegate()); m_pendingCodes.put( requestCode, ref ); - addFragmentImpl( fragment, extras, this ); + addFragmentImpl( fragment, extras, fragment.getParent() ); } protected void setFragmentResult( DelegateBase delegate, int resultCode, @@ -344,9 +345,9 @@ public class MainActivity extends XWActivity addFragmentImpl( fragment, parent ); } - private void addFragmentImpl( Fragment fragment, Delegator delegator ) + private void addFragmentImpl( Fragment fragment, Delegator parent ) { - String newName = fragment.getClass().getName(); + String newName = fragment.getClass().getSimpleName(); boolean replace = false; FragmentManager fm = getSupportFragmentManager(); int fragCount = fm.getBackStackEntryCount(); @@ -357,23 +358,18 @@ public class MainActivity extends XWActivity // Replace IF we're adding something of the same class at right OR if // we're adding something with the existing left pane as its parent // (delegator) - if ( 0 < fragCount ) { - FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 ); + if ( 1 < fragCount ) { + Assert.assertTrue( MAX_PANES_LANDSCAPE == 2 ); // otherwise FIXME + FragmentManager.BackStackEntry entry + = fm.getBackStackEntryAt( fragCount - 2 ); String curName = entry.getName(); - DbgUtils.logf( "name of last entry: %s", curName ); - replace = curName.equals( newName ); + String delName = parent.getClass().getSimpleName(); + // DbgUtils.logf( "comparing %s, %s", curName, delName ); + replace = curName.equals( delName ); + } - if ( !replace && 1 < fragCount ) { - entry = fm.getBackStackEntryAt( fragCount - 2 ); - curName = entry.getName(); - String delName = delegator.getClass().getName(); - DbgUtils.logf( "comparing %s, %s", curName, delName ); - replace = curName.equals( delName ); - } - - if ( replace ) { - fm.popBackStack(); - } + if ( replace ) { + fm.popBackStack(); } // Replace doesn't seem to work with generated IDs, so we'll create a diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java index 729312ace..80755a2f0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java @@ -363,7 +363,7 @@ public class StudyListDelegate extends ListDelegateBase } if ( delegator.inDPMode() ) { - delegator.addFragment( new StudyListFrag(), bundle ); + delegator.addFragment( new StudyListFrag( delegator ), bundle ); } else { Intent intent = new Intent( activity, StudyListActivity.class ); intent.putExtras( bundle ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListFrag.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListFrag.java index 0fcae720d..91dcb6259 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListFrag.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListFrag.java @@ -24,6 +24,8 @@ import android.os.Bundle; public class StudyListFrag extends XWFragment { + public StudyListFrag( Delegator parent ) { super( parent ); } + @Override public void onCreate( Bundle sis ) { 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 d3e9ac86b..ac223f47c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java @@ -37,8 +37,13 @@ import junit.framework.Assert; public class XWFragment extends Fragment implements Delegator { private DelegateBase m_dlgt; + private Delegator m_parent; private boolean m_hasOptionsMenu = false; + public XWFragment( Delegator parent ) { m_parent = parent; } + + public Delegator getParent() { return m_parent; } + protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu ) { m_hasOptionsMenu = hasOptionsMenu;