add and use NewGameFrag (but the game it launches is as an activity);

cleanup so delegate is only source of what its layout is.
This commit is contained in:
Eric House 2014-08-07 07:26:53 -07:00
parent 4f4a84ccf5
commit b7db0125ba
5 changed files with 63 additions and 52 deletions

View file

@ -32,9 +32,8 @@ public class BoardFrag extends XWFragment implements Delegator {
@Override
public void onCreate( Bundle savedInstanceState )
{
DbgUtils.logf( "GamesListFrag.onCreate()" );
m_dlgt = new BoardDelegate( this, savedInstanceState );
super.onCreate( m_dlgt, savedInstanceState, R.layout.board );
super.onCreate( m_dlgt, savedInstanceState );
}
@Override

View file

@ -58,22 +58,13 @@ public class FragActivity extends FragmentActivity
m_root = (LinearLayout)findViewById( R.id.main_container );
getSupportFragmentManager().addOnBackStackChangedListener( this );
int orientation = getResources().getConfiguration().orientation;
m_maxPanes = maxPanes();
// Nothing to do if we're restarting
if ( savedInstanceState == null ) {
DbgUtils.logf( "calling new GamesListFrag()" );
GamesListFrag glf = new GamesListFrag();
DbgUtils.logf( "new GamesListFrag() done" );
// In case this activity was started with special instructions from an Intent,
// pass the Intent's extras to the fragment as arguments
glf.setArguments( getIntent().getExtras() );
DbgUtils.logf( "calling addFragment(glf)" );
addFragment( glf );
DbgUtils.logf( "addFragment(glf) DONE" );
addFragmentImpl( new GamesListFrag(), getIntent().getExtras() );
}
}
@ -120,37 +111,25 @@ public class FragActivity extends FragmentActivity
}
}
//////////////////////////////////////////////////////////////////////
// GameListDelegate.DlgtOwner
//////////////////////////////////////////////////////////////////////
public static void launchGame( long rowid, boolean invited )
{
DbgUtils.logf( "FragActivity.launchGame(%d)", rowid );
Bundle args = GameUtils.makeLaunchExtras( rowid, invited );
BoardFrag bf = new BoardFrag();
bf.setArguments( args );
getThis().addFragment( bf );
}
public void launchDictFrag( Bundle args )
{
// DictBrowseFrag dbf = new DictBrowseFrag();
// dbf.setArguments( args );
// addFragment( dbf );
}
// public void launchDictFrag( Bundle args )
// {
// // DictBrowseFrag dbf = new DictBrowseFrag();
// // dbf.setArguments( args );
// // addFragment( dbf );
// }
protected void popFragment( Fragment frag )
{
getSupportFragmentManager().popBackStack();
}
protected void addFragment( Fragment fragment, Bundle bundle )
private void addFragmentImpl( Fragment fragment, Bundle bundle )
{
fragment.setArguments( bundle );
addFragment( fragment );
addFragmentImpl( fragment );
}
protected void addFragment( Fragment fragment )
private void addFragmentImpl( Fragment fragment )
{
String newName = fragment.getClass().getName();
boolean replace = false;
@ -240,4 +219,14 @@ public class FragActivity extends FragmentActivity
return s_this;
}
public static void launchGame( long rowid, boolean invited )
{
Bundle args = GameUtils.makeLaunchExtras( rowid, invited );
addFragment( new BoardFrag(), args );
}
public static void addFragment( Fragment fragment, Bundle bundle )
{
getThis().addFragmentImpl( fragment, bundle );
}
}

View file

@ -476,9 +476,14 @@ public class NewGameDelegate extends DelegateBase {
public static void startActivity( Activity parent, long groupID )
{
Bundle extras = new Bundle();
extras.putLong( GROUPID_EXTRA, groupID );
if ( parent instanceof FragActivity ) {
FragActivity.addFragment( new NewGameFrag(), extras );
} else {
Intent intent = new Intent( parent, NewGameActivity.class );
intent.putExtra( GROUPID_EXTRA, groupID );
intent.putExtras( extras );
parent.startActivity( intent );
}
}
}

View file

@ -0,0 +1,31 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/*
* Copyright 2014 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.os.Bundle;
public class NewGameFrag extends XWFragment implements Delegator {
@Override
public void onCreate( Bundle sis )
{
super.onCreate( new NewGameDelegate( this, sis ), sis );
}
}

View file

@ -36,13 +36,6 @@ import org.eehouse.android.xw4.loc.LocUtils;
public class XWFragment extends Fragment {
private DelegateBase m_dlgt;
private int m_layoutID = -1;
protected void onCreate( DelegateBase dlgt, Bundle sis, int layoutID )
{
onCreate( dlgt, sis );
m_layoutID = layoutID;
}
public void onCreate( DelegateBase dlgt, Bundle sis )
{
@ -55,13 +48,7 @@ public class XWFragment extends Fragment {
Bundle savedInstanceState )
{
DbgUtils.logf( "%s.onCreateView() called", this.getClass().getName() );
View view = null;
if ( 0 < m_layoutID ) {
view = inflater.inflate( m_layoutID, container, false );
m_dlgt.setContentView( view );
}
DbgUtils.logf( "%s.onCreateView() => %H", this.getClass().getName(), view );
return view;
return m_dlgt.inflateView( inflater, container );
}
@Override