add studylist as fragment; fix so board displays beside games list

This commit is contained in:
Eric House 2014-08-01 07:48:24 -07:00
parent 96eacabf10
commit 6d3f56fa45
8 changed files with 148 additions and 28 deletions

View file

@ -515,7 +515,9 @@ public class BoardDelegate extends DelegateBase
m_utils = new BoardUtilCtxt();
m_jniu = JNIUtilsImpl.get( m_activity );
setContentView( R.layout.board );
if ( null == getContentView() ) {
setContentView( R.layout.board );
}
m_timers = new TimerRunnable[4]; // needs to be in sync with
// XWTimerReason
m_view = (BoardView)findViewById( R.id.board_view );

View file

@ -29,26 +29,12 @@ import org.eehouse.android.xw4.loc.LocUtils;
public class BoardFrag extends XWFragment implements Delegator {
private BoardDelegate m_dlgt;
// public BoardFrag( FragActivity activity )
// {
// m_activity = activity;
// }
@Override
public void onCreate( Bundle savedInstanceState )
{
DbgUtils.logf( "GamesListFrag.onCreate()" );
m_dlgt = new BoardDelegate( this, savedInstanceState );
super.onCreate( m_dlgt, savedInstanceState );
}
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState )
{
View root = inflater.inflate( R.layout.game_list, container, false );
LocUtils.xlateView( getActivity(), root );
return root;
super.onCreate( m_dlgt, savedInstanceState, R.layout.board );
}
@Override

View file

@ -105,6 +105,17 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
return m_delegator.getArguments();
}
protected View getContentView()
{
return m_rootView;
}
protected void setContentView( View view )
{
LocUtils.xlateView( m_activity, view );
m_rootView = view;
}
protected void setContentView( int resID )
{
m_activity.setContentView( resID );

View file

@ -137,6 +137,12 @@ public class FragActivity extends FragmentActivity
getSupportFragmentManager().popBackStack();
}
protected void addFragment( Fragment fragment, Bundle bundle )
{
fragment.setArguments( bundle );
addFragment( fragment );
}
protected void addFragment( Fragment fragment )
{
String newName = fragment.getClass().getName();

View file

@ -76,7 +76,10 @@ public class StudyListDelegate extends ListDelegateBase
protected void init( Bundle savedInstanceState )
{
setContentView( R.layout.studylist );
DbgUtils.logf( "%s.init() called", getClass().getName() );
if ( null == getContentView() ) {
setContentView( R.layout.studylist );
}
m_list = (ListView)findViewById( android.R.id.list );
m_spinner = (Spinner)findViewById( R.id.pick_lang_spinner );
@ -294,6 +297,7 @@ public class StudyListDelegate extends ListDelegateBase
}
}
DbgUtils.logf( "creating studylist adapter" );
ArrayAdapter<String> adapter = new
ArrayAdapter<String>( m_activity,
android.R.layout.simple_spinner_item,
@ -345,23 +349,31 @@ public class StudyListDelegate extends ListDelegateBase
setTitleBar();
}
public static void launchOrAlert( Context context, int lang,
public static void launchOrAlert( Activity activity, int lang,
DlgDelegate.HasDlgDelegate dlg )
{
String msg = null;
if ( 0 == DBUtils.studyListLangs( context ).length ) {
msg = LocUtils.getString( context, R.string.study_no_lists );
if ( 0 == DBUtils.studyListLangs( activity ).length ) {
msg = LocUtils.getString( activity, R.string.study_no_lists );
} else if ( NO_LANG != lang &&
0 == DBUtils.studyListWords( context, lang ).length ) {
String langname = DictLangCache.getLangName( context, lang );
msg = LocUtils.getString( context, R.string.study_no_lang_fmt,
0 == DBUtils.studyListWords( activity, lang ).length ) {
String langname = DictLangCache.getLangName( activity, lang );
msg = LocUtils.getString( activity, R.string.study_no_lang_fmt,
langname );
} else {
Intent intent = new Intent( context, StudyListActivity.class );
Bundle bundle = new Bundle();
if ( NO_LANG != lang ) {
intent.putExtra( START_LANG, lang );
bundle.putInt( START_LANG, lang );
}
if ( activity instanceof FragActivity ) {
StudyListFrag frag = new StudyListFrag();
((FragActivity)activity).addFragment( frag, bundle );
} else {
Intent intent = new Intent( activity, StudyListActivity.class );
intent.putExtras( bundle );
activity.startActivity( intent );
}
context.startActivity( intent );
}
if ( null != msg ) {

View file

@ -0,0 +1,44 @@
/* -*- 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;
import android.view.View;
import org.eehouse.android.xw4.loc.LocUtils;
public class StudyListFrag extends XWListFragment implements ListDelegator {
private StudyListDelegate m_dlgt;
@Override
public void onCreate( Bundle savedInstanceState )
{
DbgUtils.logf( "StudyListFrag.onCreate()" );
m_dlgt = new StudyListDelegate( this, savedInstanceState );
super.onCreate( m_dlgt, savedInstanceState, R.layout.studylist );
}
@Override
public void onActivityCreated( Bundle savedInstanceState )
{
super.onActivityCreated( savedInstanceState );
setHasOptionsMenu( true );
}
}

View file

@ -22,25 +22,52 @@ package org.eehouse.android.xw4;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import junit.framework.Assert;
import org.eehouse.android.xw4.loc.LocUtils;
public class XWFragment extends Fragment {
private DelegateBase m_dlgt;
private int m_layoutID = -1;
public void onCreate( DelegateBase dlgt, Bundle savedInstanceState )
protected void onCreate( DelegateBase dlgt, Bundle sis, int layoutID )
{
super.onCreate( savedInstanceState );
onCreate( dlgt, sis );
m_layoutID = layoutID;
}
public void onCreate( DelegateBase dlgt, Bundle sis )
{
super.onCreate( sis );
m_dlgt = dlgt;
}
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container,
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;
}
@Override
public void onActivityCreated( Bundle savedInstanceState )
{
DbgUtils.logf( "%s.onActivityCreated() called", this.getClass().getName() );
m_dlgt.init( savedInstanceState );
super.onActivityCreated( savedInstanceState );
}

View file

@ -22,15 +22,27 @@ package org.eehouse.android.xw4;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import junit.framework.Assert;
import org.eehouse.android.xw4.loc.LocUtils;
public class XWListFragment extends ListFragment {
private ListDelegateBase m_dlgt;
private int m_layoutID = -1;
protected void onCreate( ListDelegateBase dlgt, Bundle sis, int layoutID )
{
onCreate( dlgt, sis );
m_layoutID = layoutID;
}
public void onCreate( ListDelegateBase dlgt, Bundle savedInstanceState )
{
@ -38,9 +50,24 @@ public class XWListFragment extends ListFragment {
m_dlgt = dlgt;
}
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container,
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 );
// LocUtils.xlateView( getActivity(), view );
}
return view;
}
@Override
public void onActivityCreated( Bundle savedInstanceState )
{
DbgUtils.logf( "%s.onActivityCreated() called", this.getClass().getName() );
m_dlgt.init( savedInstanceState );
super.onActivityCreated( savedInstanceState );
}
@ -48,6 +75,7 @@ public class XWListFragment extends ListFragment {
@Override
public void onPause()
{
DbgUtils.logf( "%s.onPause() called", this.getClass().getName() );
m_dlgt.onPause();
super.onPause();
}
@ -55,6 +83,7 @@ public class XWListFragment extends ListFragment {
@Override
public void onResume()
{
DbgUtils.logf( "%s.onResume() called", this.getClass().getName() );
super.onResume();
m_dlgt.onResume();
}
@ -62,6 +91,7 @@ public class XWListFragment extends ListFragment {
@Override
public void onStart()
{
DbgUtils.logf( "%s.onStart() called", this.getClass().getName() );
super.onStart();
m_dlgt.onStart();
}
@ -69,6 +99,7 @@ public class XWListFragment extends ListFragment {
@Override
public void onStop()
{
DbgUtils.logf( "%s.onStop() called", this.getClass().getName() );
m_dlgt.onStop();
super.onStop();
}
@ -76,6 +107,7 @@ public class XWListFragment extends ListFragment {
@Override
public void onDestroy()
{
DbgUtils.logf( "%s.onDestroy() called", this.getClass().getName() );
m_dlgt.onDestroy();
super.onDestroy();
}