mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
fix so when left pane launches a fragment it replaces the right
Required passing parent into constructors so it's available for matching against the left pane later.
This commit is contained in:
parent
2b58072524
commit
5dee7080a0
15 changed files with 43 additions and 27 deletions
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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<DelegateBase>(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
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue