mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
replace activity.show(dlgID) with fragment-based
For GamesListDelegate only so far, replace calling <activity>.show(int) to launch an Alert with something producing and showing a DialogFragment. Replaces passing and saving state inside the DelegateBase subclass with saving it as part of the fragment's bundle, and it looks as if a single class will work for nearly all of the alerts managed by DelegateBase.{onCreateDialog,prepareDialog}(), which will eventually go away. The beauty is that the implementations of onCreateDialog and onPrepareDialog remain, but as the body of a new makeDialog() that's called by the fragment's onCreateView. Less code changes, but now it's all called every time an alert's created.
This commit is contained in:
parent
c66764bd77
commit
07da48db73
5 changed files with 257 additions and 165 deletions
|
@ -0,0 +1,75 @@
|
||||||
|
/* -*- compile-command: "find-and-gradle.sh installXw4Debug"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.support.v4.app.DialogFragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.app.Dialog;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
public class DBAlert extends DialogFragment {
|
||||||
|
private static final String DLG_ID_KEY = "DLG_ID_KEY";
|
||||||
|
private static final String PARMS_KEY = "PARMS_KEY";
|
||||||
|
|
||||||
|
private Object[] mParams;
|
||||||
|
private DlgID mDlgID;
|
||||||
|
|
||||||
|
public static DBAlert newInstance( DlgID dlgID, Object[] params )
|
||||||
|
{
|
||||||
|
if ( BuildConfig.DEBUG ) {
|
||||||
|
for ( Object obj : params ) {
|
||||||
|
Assert.assertTrue( obj instanceof Serializable );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt( DLG_ID_KEY, dlgID.ordinal() );
|
||||||
|
bundle.putSerializable( PARMS_KEY, params );
|
||||||
|
DBAlert result = new DBAlert();
|
||||||
|
result.setArguments( bundle );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBAlert() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState( Bundle bundle )
|
||||||
|
{
|
||||||
|
super.onSaveInstanceState( bundle );
|
||||||
|
bundle.putInt( DLG_ID_KEY, mDlgID.ordinal() );
|
||||||
|
bundle.putSerializable( PARMS_KEY, mParams );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog( Bundle sis )
|
||||||
|
{
|
||||||
|
if ( null == sis ) {
|
||||||
|
sis = getArguments();
|
||||||
|
}
|
||||||
|
mDlgID = DlgID.values()[sis.getInt(DLG_ID_KEY, -1)];
|
||||||
|
mParams = (Object[])sis.getSerializable(PARMS_KEY);
|
||||||
|
|
||||||
|
XWActivity activity = (XWActivity)getActivity();
|
||||||
|
return activity.makeDialog( mDlgID, mParams );
|
||||||
|
}
|
||||||
|
}
|
|
@ -423,6 +423,18 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
m_dlgDelegate.showDialog( dlgID );
|
m_dlgDelegate.showDialog( dlgID );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||||
|
{
|
||||||
|
DbgUtils.logd( TAG, "makeDialog(): not handling %s", dlgID.toString() );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showDialogFragment( DlgID dlgID, Object... params )
|
||||||
|
{
|
||||||
|
DialogFragment fragment = DBAlert.newInstance( dlgID, params );
|
||||||
|
show( fragment );
|
||||||
|
}
|
||||||
|
|
||||||
protected void show( DialogFragment df )
|
protected void show( DialogFragment df )
|
||||||
{
|
{
|
||||||
if ( m_activity instanceof MainActivity ) {
|
if ( m_activity instanceof MainActivity ) {
|
||||||
|
|
|
@ -46,6 +46,21 @@ public class DualpaneDelegate extends DelegateBase {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||||
|
{
|
||||||
|
Dialog dialog = null;
|
||||||
|
MainActivity main = (MainActivity)m_activity;
|
||||||
|
XWFragment[] frags = main.getVisibleFragments();
|
||||||
|
for ( XWFragment frag : frags ) {
|
||||||
|
dialog = frag.getDelegate().makeDialog( dlgID, params );
|
||||||
|
if ( null != dialog ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog( int id )
|
||||||
{
|
{
|
||||||
|
|
|
@ -581,13 +581,9 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
private GameListAdapter m_adapter;
|
private GameListAdapter m_adapter;
|
||||||
private Handler m_handler;
|
private Handler m_handler;
|
||||||
private String m_missingDict;
|
private String m_missingDict;
|
||||||
private String m_missingDictName;
|
|
||||||
private long m_missingDictRowId = DBUtils.ROWID_NOTFOUND;
|
private long m_missingDictRowId = DBUtils.ROWID_NOTFOUND;
|
||||||
private int m_missingDictMenuId;
|
private int m_missingDictMenuId;
|
||||||
private String[] m_sameLangDicts;
|
|
||||||
private int m_missingDictLang;
|
private int m_missingDictLang;
|
||||||
private long m_rowid;
|
|
||||||
private long m_groupid;
|
|
||||||
private String m_nameField;
|
private String m_nameField;
|
||||||
private NetLaunchInfo m_netLaunchInfo;
|
private NetLaunchInfo m_netLaunchInfo;
|
||||||
private Set<Long> m_launchedGames; // prevent problems with double-taps
|
private Set<Long> m_launchedGames; // prevent problems with double-taps
|
||||||
|
@ -610,52 +606,52 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
s_self = this;
|
s_self = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Dialog onCreateDialog( int id )
|
@Override
|
||||||
|
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||||
{
|
{
|
||||||
Dialog dialog = null;
|
Dialog dialog = null;
|
||||||
OnClickListener lstnr;
|
OnClickListener lstnr, lstnr2;
|
||||||
OnClickListener lstnr2;
|
|
||||||
LinearLayout layout;
|
|
||||||
|
|
||||||
AlertDialog.Builder ab;
|
AlertDialog.Builder ab;
|
||||||
DlgID dlgID = DlgID.values()[id];
|
|
||||||
switch ( dlgID ) {
|
switch ( dlgID ) {
|
||||||
case WARN_NODICT:
|
case WARN_NODICT:
|
||||||
case WARN_NODICT_NEW:
|
case WARN_NODICT_NEW:
|
||||||
case WARN_NODICT_SUBST:
|
case WARN_NODICT_SUBST: {
|
||||||
|
final long rowid = (Long)params[0];
|
||||||
|
final String missingDictName = (String)params[1];
|
||||||
|
final int missingDictLang = (Integer)params[2];
|
||||||
|
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
if ( null == missingDictName ) {
|
||||||
// no name, so user must pick
|
|
||||||
if ( null == m_missingDictName ) {
|
|
||||||
DictsDelegate
|
DictsDelegate
|
||||||
.downloadForResult( getDelegator(),
|
.downloadForResult( getDelegator(),
|
||||||
RequestCode
|
RequestCode
|
||||||
.REQUEST_LANG_GL,
|
.REQUEST_LANG_GL,
|
||||||
self.m_missingDictLang );
|
missingDictLang );
|
||||||
} else {
|
} else {
|
||||||
DwnldDelegate
|
DwnldDelegate
|
||||||
.downloadDictInBack( self.m_activity,
|
.downloadDictInBack( m_activity,
|
||||||
self.m_missingDictLang,
|
missingDictLang,
|
||||||
self.m_missingDictName,
|
missingDictName,
|
||||||
self );
|
GamesListDelegate.this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String message;
|
String message;
|
||||||
String langName =
|
String langName =
|
||||||
DictLangCache.getLangName( m_activity, m_missingDictLang );
|
DictLangCache.getLangName( m_activity, missingDictLang );
|
||||||
String locLang = xlateLang( langName );
|
String locLang = xlateLang( langName );
|
||||||
String gameName = GameUtils.getName( m_activity, m_missingDictRowId );
|
String gameName = GameUtils.getName( m_activity, rowid );
|
||||||
if ( DlgID.WARN_NODICT == dlgID ) {
|
if ( DlgID.WARN_NODICT == dlgID ) {
|
||||||
message = getString( R.string.no_dict_fmt, gameName, locLang );
|
message = getString( R.string.no_dict_fmt, gameName, locLang );
|
||||||
} else if ( DlgID.WARN_NODICT_NEW == dlgID ) {
|
} else if ( DlgID.WARN_NODICT_NEW == dlgID ) {
|
||||||
message = getString( R.string.invite_dict_missing_body_noname_fmt,
|
message = getString( R.string.invite_dict_missing_body_noname_fmt,
|
||||||
null, m_missingDictName, locLang );
|
null, missingDictName, locLang );
|
||||||
} else {
|
} else {
|
||||||
// WARN_NODICT_SUBST
|
// WARN_NODICT_SUBST
|
||||||
message = getString( R.string.no_dict_subst_fmt, gameName,
|
message = getString( R.string.no_dict_subst_fmt, gameName,
|
||||||
m_missingDictName, locLang );
|
missingDictName, locLang );
|
||||||
}
|
}
|
||||||
|
|
||||||
ab = makeAlertBuilder()
|
ab = makeAlertBuilder()
|
||||||
|
@ -667,30 +663,32 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
if ( DlgID.WARN_NODICT_SUBST == dlgID ) {
|
if ( DlgID.WARN_NODICT_SUBST == dlgID ) {
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
curThis().showDialog( DlgID.SHOW_SUBST );
|
showDialogFragment( DlgID.SHOW_SUBST, rowid,
|
||||||
|
missingDictName, missingDictLang );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ab.setNeutralButton( R.string.button_substdict, lstnr );
|
ab.setNeutralButton( R.string.button_substdict, lstnr );
|
||||||
}
|
}
|
||||||
dialog = ab.create();
|
dialog = ab.create();
|
||||||
setRemoveOnDismiss( dialog, dlgID );
|
}
|
||||||
break;
|
break;
|
||||||
case SHOW_SUBST:
|
case SHOW_SUBST: {
|
||||||
m_sameLangDicts =
|
final long rowid = (Long)params[0];
|
||||||
DictLangCache.getHaveLangCounts( m_activity, m_missingDictLang );
|
final String missingDict = (String)params[1];
|
||||||
|
final int lang = (Integer)params[2];
|
||||||
|
|
||||||
|
final String[] sameLangDicts =
|
||||||
|
DictLangCache.getHaveLangCounts( m_activity, lang );
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg,
|
public void onClick( DialogInterface dlg,
|
||||||
int which ) {
|
int which ) {
|
||||||
GamesListDelegate self = curThis();
|
|
||||||
int pos = ((AlertDialog)dlg).getListView().
|
int pos = ((AlertDialog)dlg).getListView().
|
||||||
getCheckedItemPosition();
|
getCheckedItemPosition();
|
||||||
String dict = self.m_sameLangDicts[pos];
|
String newDict = sameLangDicts[pos];
|
||||||
dict = DictLangCache.stripCount( dict );
|
newDict = DictLangCache.stripCount( newDict );
|
||||||
if ( GameUtils.replaceDicts( self.m_activity,
|
if ( GameUtils.replaceDicts( m_activity, rowid,
|
||||||
self.m_missingDictRowId,
|
missingDict, newDict ) ) {
|
||||||
self.m_missingDictName,
|
launchGameIf();
|
||||||
dict ) ) {
|
|
||||||
self.launchGameIf();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -698,60 +696,59 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
.setTitle( R.string.subst_dict_title )
|
.setTitle( R.string.subst_dict_title )
|
||||||
.setPositiveButton( R.string.button_substdict, lstnr )
|
.setPositiveButton( R.string.button_substdict, lstnr )
|
||||||
.setNegativeButton( android.R.string.cancel, null )
|
.setNegativeButton( android.R.string.cancel, null )
|
||||||
.setSingleChoiceItems( m_sameLangDicts, 0, null )
|
.setSingleChoiceItems( sameLangDicts, 0, null )
|
||||||
.create();
|
.create();
|
||||||
// Force destruction so onCreateDialog() will get
|
}
|
||||||
// called next time and we can insert a different
|
|
||||||
// list. There seems to be no way to change the list
|
|
||||||
// inside onPrepareDialog().
|
|
||||||
setRemoveOnDismiss( dialog, dlgID );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RENAME_GAME:
|
case RENAME_GAME: {
|
||||||
GameSummary summary = GameUtils.getSummary( m_activity, m_rowid );
|
final long rowid = (Long)params[0];
|
||||||
|
GameSummary summary = GameUtils.getSummary( m_activity, rowid );
|
||||||
int labelID = (summary.isMultiGame() && !summary.anyMissing())
|
int labelID = (summary.isMultiGame() && !summary.anyMissing())
|
||||||
? R.string.rename_label_caveat : R.string.rename_label;
|
? R.string.rename_label_caveat : R.string.rename_label;
|
||||||
final GameNamer namer1 =
|
final GameNamer namer =
|
||||||
buildNamer(GameUtils.getName( m_activity, m_rowid ), labelID );
|
buildNamer(GameUtils.getName( m_activity, rowid ), labelID );
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
String name = namer.getName();
|
||||||
String name = namer1.getName();
|
DBUtils.setName( m_activity, rowid,
|
||||||
DBUtils.setName( self.m_activity, self.m_rowid,
|
|
||||||
name );
|
name );
|
||||||
self.m_adapter.invalName( self.m_rowid );
|
m_adapter.invalName( rowid );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dialog = buildNamerDlg( namer1, R.string.game_rename_title,
|
dialog = buildNamerDlg( namer, R.string.game_rename_title,
|
||||||
lstnr, null, DlgID.RENAME_GAME );
|
lstnr, null, DlgID.RENAME_GAME );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RENAME_GROUP:
|
case RENAME_GROUP: {
|
||||||
final GameNamer namer2 = buildNamer( m_adapter.groupName(m_groupid),
|
final long groupID = (Long)params[0];
|
||||||
R.string.rename_group_label );
|
final GameNamer namer = buildNamer( m_adapter.groupName(groupID),
|
||||||
|
R.string.rename_group_label );
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
GamesListDelegate self = curThis();
|
||||||
String name = namer2.getName();
|
String name = namer.getName();
|
||||||
DBUtils.setGroupName( self.m_activity,
|
DBUtils.setGroupName( m_activity,
|
||||||
self.m_groupid, name );
|
groupID, name );
|
||||||
self.reloadGame( self.m_rowid );
|
// Don't have m_rowid any more. But what's this doing again?
|
||||||
|
// reloadGame( m_rowid );
|
||||||
self.mkListAdapter();
|
self.mkListAdapter();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dialog = buildNamerDlg( namer2, R.string.game_name_group_title,
|
dialog = buildNamerDlg( namer, R.string.game_name_group_title,
|
||||||
lstnr, null, DlgID.RENAME_GROUP );
|
lstnr, null, DlgID.RENAME_GROUP );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEW_GROUP:
|
case NEW_GROUP: {
|
||||||
final GameNamer namer3 = buildNamer( "", R.string.newgroup_label );
|
final GameNamer namer = buildNamer( "", R.string.newgroup_label );
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
String name = namer.getName();
|
||||||
String name = namer3.getName();
|
DBUtils.addGroup( m_activity, name );
|
||||||
DBUtils.addGroup( self.m_activity, name );
|
mkListAdapter();
|
||||||
self.mkListAdapter();
|
showNewGroupIf();
|
||||||
self.showNewGroupIf();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
lstnr2 = new OnClickListener() {
|
lstnr2 = new OnClickListener() {
|
||||||
|
@ -759,17 +756,18 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
curThis().showNewGroupIf();
|
curThis().showNewGroupIf();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dialog = buildNamerDlg( namer3,
|
dialog = buildNamerDlg( namer,
|
||||||
R.string.game_name_group_title,
|
R.string.game_name_group_title,
|
||||||
lstnr, lstnr2, DlgID.RENAME_GROUP );
|
lstnr, lstnr2, DlgID.RENAME_GROUP );
|
||||||
setRemoveOnDismiss( dialog, dlgID );
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CHANGE_GROUP:
|
case CHANGE_GROUP: {
|
||||||
|
long[] selGames = (long[])params[0];
|
||||||
long srcGroup = -1;
|
long srcGroup = -1;
|
||||||
// If all games are coming from the same group we can disable move
|
// If all games are coming from the same group we can disable move
|
||||||
// when that's the destination
|
// when that's the destination
|
||||||
for ( long rowid : m_selGames ) {
|
for ( long rowid : selGames ) {
|
||||||
long groupID = DBUtils.getGroupForGame( m_activity, rowid );
|
long groupID = DBUtils.getGroupForGame( m_activity, rowid );
|
||||||
if ( -1 == srcGroup ) {
|
if ( -1 == srcGroup ) {
|
||||||
srcGroup = groupID;
|
srcGroup = groupID;
|
||||||
|
@ -782,14 +780,13 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
final long fSrcGroup = srcGroup;;
|
final long fSrcGroup = srcGroup;;
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlgi, int item ) {
|
public void onClick( DialogInterface dlgi, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
|
||||||
selItem[0] = item;
|
selItem[0] = item;
|
||||||
AlertDialog dlg = (AlertDialog)dlgi;
|
AlertDialog dlg = (AlertDialog)dlgi;
|
||||||
Button btn =
|
Button btn =
|
||||||
dlg.getButton( AlertDialog.BUTTON_POSITIVE );
|
dlg.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||||
boolean enabled = fSrcGroup == -1;
|
boolean enabled = fSrcGroup == -1;
|
||||||
if ( !enabled ) {
|
if ( !enabled ) {
|
||||||
long newGroup = self.m_adapter.getGroupIDFor( item );
|
long newGroup = m_adapter.getGroupIDFor( item );
|
||||||
enabled = newGroup != fSrcGroup;
|
enabled = newGroup != fSrcGroup;
|
||||||
}
|
}
|
||||||
btn.setEnabled( enabled );
|
btn.setEnabled( enabled );
|
||||||
|
@ -797,18 +794,16 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
};
|
};
|
||||||
lstnr2 = new OnClickListener() {
|
lstnr2 = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
|
||||||
Assert.assertTrue( -1 != selItem[0] );
|
Assert.assertTrue( -1 != selItem[0] );
|
||||||
long gid = self.m_adapter.getGroupIDFor( selItem[0] );
|
long gid = m_adapter.getGroupIDFor( selItem[0] );
|
||||||
self.moveSelGamesTo( gid );
|
moveSelGamesTo( gid );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
OnClickListener lstnr3 =
|
OnClickListener lstnr3 =
|
||||||
new OnClickListener() {
|
new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
GamesListDelegate self = curThis();
|
m_moveAfterNewGroup = true;
|
||||||
self.m_moveAfterNewGroup = true;
|
showDialogFragment( DlgID.NEW_GROUP );
|
||||||
self.showDialog( DlgID.NEW_GROUP );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String[] groups = m_adapter.groupNames();
|
String[] groups = m_adapter.groupNames();
|
||||||
|
@ -820,11 +815,11 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
.setNeutralButton( R.string.button_newgroup, lstnr3 )
|
.setNeutralButton( R.string.button_newgroup, lstnr3 )
|
||||||
.setNegativeButton( android.R.string.cancel, null )
|
.setNegativeButton( android.R.string.cancel, null )
|
||||||
.create();
|
.create();
|
||||||
setRemoveOnDismiss( dialog, dlgID );
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GET_NAME:
|
case GET_NAME: {
|
||||||
layout = (LinearLayout)inflate( R.layout.dflt_name );
|
LinearLayout layout = (LinearLayout)inflate( R.layout.dflt_name );
|
||||||
final EditText etext =
|
final EditText etext =
|
||||||
(EditText)layout.findViewById( R.id.name_edit );
|
(EditText)layout.findViewById( R.id.name_edit );
|
||||||
etext.setText( CommonPrefs.getDefaultPlayerName( m_activity,
|
etext.setText( CommonPrefs.getDefaultPlayerName( m_activity,
|
||||||
|
@ -848,101 +843,103 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
makeThenLaunchOrConfigure();
|
makeThenLaunchOrConfigure();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GAMES_LIST_NEWGAME:
|
case GAMES_LIST_NEWGAME: {
|
||||||
|
boolean solo = (Boolean)params[0];
|
||||||
LinearLayout view = (LinearLayout)
|
LinearLayout view = (LinearLayout)
|
||||||
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
|
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
|
||||||
final EditText edit = (EditText)view.findViewById( R.id.edit );
|
final EditText edit = (EditText)view.findViewById( R.id.edit );
|
||||||
|
|
||||||
|
boolean canDoDefaults = solo ||
|
||||||
|
0 < XWPrefs.getAddrTypes( m_activity ).size();
|
||||||
|
int iconResID = solo ? R.drawable.sologame__gen : R.drawable.multigame__gen;
|
||||||
|
int titleID = solo ? R.string.new_game : R.string.new_game_networked;
|
||||||
|
|
||||||
|
String msg = getString( canDoDefaults ? R.string.new_game_message
|
||||||
|
: R.string.new_game_message_nodflt );
|
||||||
|
if ( !solo ) {
|
||||||
|
msg += "\n\n" + getString( R.string.new_game_message_net );
|
||||||
|
}
|
||||||
|
TextView tmpEdit = (TextView)view.findViewById( R.id.msg );
|
||||||
|
tmpEdit.setText( msg );
|
||||||
|
tmpEdit = (TextView)view.findViewById( R.id.edit );
|
||||||
|
tmpEdit.setText( GameUtils.makeDefaultName( m_activity ) );
|
||||||
|
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
curThis().makeThenLaunchOrConfigure( edit, true, false );
|
curThis().makeThenLaunchOrConfigure( edit, true, false );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
lstnr2 = new OnClickListener() {
|
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
|
||||||
curThis().makeThenLaunchOrConfigure( edit, false, false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog = makeAlertBuilder()
|
ab = makeAlertBuilder()
|
||||||
.setView( view )
|
.setView( view )
|
||||||
.setTitle( "foo" )// ditto, but can't be empty (!)
|
.setTitle( titleID )
|
||||||
.setIcon( R.drawable.sologame__gen ) // same for icon
|
.setIcon( iconResID )
|
||||||
.setPositiveButton( R.string.newgame_configure_first, lstnr )
|
.setPositiveButton( R.string.newgame_configure_first, lstnr );
|
||||||
.setNegativeButton( R.string.use_defaults, lstnr2 )
|
if ( canDoDefaults ) {
|
||||||
.create();
|
lstnr2 = new OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
|
curThis().makeThenLaunchOrConfigure( edit, false, false );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ab.setNegativeButton( R.string.use_defaults, lstnr2 );
|
||||||
|
}
|
||||||
|
dialog = ab.create();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GAMES_LIST_NAME_REMATCH:
|
case GAMES_LIST_NAME_REMATCH: {
|
||||||
view = (LinearLayout)
|
Bundle rematchExtras = (Bundle)params[0];
|
||||||
|
LinearLayout view = (LinearLayout)
|
||||||
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
|
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
|
||||||
|
int iconResID = R.drawable.sologame__gen;
|
||||||
|
if ( null != rematchExtras ) {
|
||||||
|
EditText edit = (EditText)view.findViewById( R.id.edit );
|
||||||
|
edit.setText( rematchExtras.getString( REMATCH_NEWNAME_EXTRA ));
|
||||||
|
boolean solo = rematchExtras.getBoolean( REMATCH_IS_SOLO, true );
|
||||||
|
if ( !solo ) {
|
||||||
|
iconResID = R.drawable.multigame__gen;
|
||||||
|
}
|
||||||
|
view.findViewById( R.id.msg ).setVisibility( View.GONE );
|
||||||
|
}
|
||||||
|
|
||||||
dialog = makeAlertBuilder()
|
dialog = makeAlertBuilder()
|
||||||
.setView( view )
|
.setView( view )
|
||||||
.setTitle( R.string.button_rematch )
|
.setTitle( R.string.button_rematch )
|
||||||
.setIcon( R.drawable.sologame__gen )
|
.setIcon( iconResID )
|
||||||
.setPositiveButton( android.R.string.ok, new OnClickListener() {
|
.setPositiveButton( android.R.string.ok, new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
EditText edit = (EditText)((Dialog)dlg)
|
EditText edit = (EditText)((Dialog)dlg)
|
||||||
.findViewById( R.id.edit );
|
.findViewById( R.id.edit );
|
||||||
String gameName = edit.getText().toString();
|
String gameName = edit.getText().toString();
|
||||||
curThis().startRematchWithName( gameName, true );
|
startRematchWithName( gameName, true );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.create();
|
.create();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dialog = super.onCreateDialog( id );
|
dialog = super.makeDialog( dlgID, params );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return dialog;
|
return dialog;
|
||||||
} // onCreateDialog
|
} // makeDialog
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareDialog( DlgID dlgID, Dialog dialog )
|
protected void prepareDialog( DlgID dlgID, Dialog dialog )
|
||||||
{
|
{
|
||||||
|
Assert.fail();
|
||||||
|
/*
|
||||||
AlertDialog ad = (AlertDialog)dialog;
|
AlertDialog ad = (AlertDialog)dialog;
|
||||||
switch( dlgID ) {
|
switch( dlgID ) {
|
||||||
case CHANGE_GROUP:
|
case CHANGE_GROUP:
|
||||||
ad.getButton( AlertDialog.BUTTON_POSITIVE ).setEnabled( false );
|
ad.getButton( AlertDialog.BUTTON_POSITIVE ).setEnabled( false );
|
||||||
break;
|
break;
|
||||||
case GAMES_LIST_NEWGAME:
|
|
||||||
boolean canDoDefaults = m_nextIsSolo
|
|
||||||
|| 0 < XWPrefs.getAddrTypes( m_activity ).size();
|
|
||||||
ad.getButton( AlertDialog.BUTTON_NEGATIVE )
|
|
||||||
.setVisibility( canDoDefaults ? View.VISIBLE : View.GONE );
|
|
||||||
|
|
||||||
ad.setIcon( m_nextIsSolo ? R.drawable.sologame__gen
|
|
||||||
: R.drawable.multigame__gen );
|
|
||||||
ad.setTitle( m_nextIsSolo ? R.string.new_game
|
|
||||||
: R.string.new_game_networked);
|
|
||||||
|
|
||||||
String msg = getString( canDoDefaults ? R.string.new_game_message
|
|
||||||
: R.string.new_game_message_nodflt );
|
|
||||||
if ( !m_nextIsSolo ) {
|
|
||||||
msg += "\n\n" + getString( R.string.new_game_message_net );
|
|
||||||
}
|
|
||||||
TextView edit = (TextView)dialog.findViewById( R.id.msg );
|
|
||||||
edit.setText( msg );
|
|
||||||
edit = (TextView)dialog.findViewById( R.id.edit );
|
|
||||||
edit.setText( GameUtils.makeDefaultName( m_activity ) );
|
|
||||||
edit.setVisibility( View.VISIBLE );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GAMES_LIST_NAME_REMATCH:
|
|
||||||
if ( null != m_rematchExtras ) {
|
|
||||||
edit = (TextView)dialog.findViewById( R.id.edit );
|
|
||||||
edit.setText( m_rematchExtras
|
|
||||||
.getString( REMATCH_NEWNAME_EXTRA ) );
|
|
||||||
boolean solo = m_rematchExtras.getBoolean( REMATCH_IS_SOLO, true );
|
|
||||||
ad.setIcon( solo ? R.drawable.sologame__gen
|
|
||||||
: R.drawable.multigame__gen );
|
|
||||||
((TextView)dialog.findViewById( R.id.msg ))
|
|
||||||
.setVisibility( View.GONE );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1044,9 +1041,6 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
protected void onSaveInstanceState( Bundle outState )
|
protected void onSaveInstanceState( Bundle outState )
|
||||||
{
|
{
|
||||||
// super.onSaveInstanceState( outState );
|
// super.onSaveInstanceState( outState );
|
||||||
outState.putLong( SAVE_ROWID, m_rowid );
|
|
||||||
outState.putLong( SAVE_GROUPID, m_groupid );
|
|
||||||
outState.putString( SAVE_DICTNAMES, m_missingDictName );
|
|
||||||
outState.putBoolean( SAVE_NEXTSOLO, m_nextIsSolo );
|
outState.putBoolean( SAVE_NEXTSOLO, m_nextIsSolo );
|
||||||
outState.putSerializable( SAVE_SELGAMES, (HashSet)m_selGames );
|
outState.putSerializable( SAVE_SELGAMES, (HashSet)m_selGames );
|
||||||
outState.putSerializable( SAVE_SELGROUPS, (HashSet)m_selGroupIDs );
|
outState.putSerializable( SAVE_SELGROUPS, (HashSet)m_selGroupIDs );
|
||||||
|
@ -1061,10 +1055,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
private void getBundledData( Bundle bundle )
|
private void getBundledData( Bundle bundle )
|
||||||
{
|
{
|
||||||
if ( null != bundle ) {
|
if ( null != bundle ) {
|
||||||
m_rowid = bundle.getLong( SAVE_ROWID );
|
|
||||||
m_groupid = bundle.getLong( SAVE_GROUPID );
|
|
||||||
m_netLaunchInfo = NetLaunchInfo.makeFrom( bundle );
|
m_netLaunchInfo = NetLaunchInfo.makeFrom( bundle );
|
||||||
m_missingDictName = bundle.getString( SAVE_DICTNAMES );
|
|
||||||
m_nextIsSolo = bundle.getBoolean( SAVE_NEXTSOLO );
|
m_nextIsSolo = bundle.getBoolean( SAVE_NEXTSOLO );
|
||||||
m_rematchExtras = bundle.getBundle( SAVE_REMATCHEXTRAS );
|
m_rematchExtras = bundle.getBundle( SAVE_REMATCHEXTRAS );
|
||||||
m_selGames = (HashSet)bundle.getSerializable( SAVE_SELGAMES );
|
m_selGames = (HashSet)bundle.getSerializable( SAVE_SELGAMES );
|
||||||
|
@ -1607,7 +1598,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
|
|
||||||
case R.id.games_menu_newgroup:
|
case R.id.games_menu_newgroup:
|
||||||
m_moveAfterNewGroup = false;
|
m_moveAfterNewGroup = false;
|
||||||
showDialog( DlgID.NEW_GROUP );
|
showDialogFragment( DlgID.NEW_GROUP );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.games_menu_dicts:
|
case R.id.games_menu_dicts:
|
||||||
|
@ -1839,7 +1830,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.games_game_move:
|
case R.id.games_game_move:
|
||||||
showDialog( DlgID.CHANGE_GROUP );
|
showDialogFragment( DlgID.CHANGE_GROUP, m_selGames );
|
||||||
break;
|
break;
|
||||||
case R.id.games_game_new_from:
|
case R.id.games_game_new_from:
|
||||||
dropSels = true; // will select the new game instead
|
dropSels = true; // will select the new game instead
|
||||||
|
@ -1879,8 +1870,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.games_game_rename:
|
case R.id.games_game_rename:
|
||||||
m_rowid = selRowIDs[0];
|
showDialogFragment( DlgID.RENAME_GAME, selRowIDs[0] );
|
||||||
showDialog( DlgID.RENAME_GAME );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// DEBUG only
|
// DEBUG only
|
||||||
|
@ -1943,8 +1933,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
XWPrefs.setDefaultNewGameGroup( m_activity, groupID );
|
XWPrefs.setDefaultNewGameGroup( m_activity, groupID );
|
||||||
break;
|
break;
|
||||||
case R.id.games_group_rename:
|
case R.id.games_group_rename:
|
||||||
m_groupid = groupID;
|
showDialogFragment( DlgID.RENAME_GROUP, groupID );
|
||||||
showDialog( DlgID.RENAME_GROUP );
|
|
||||||
break;
|
break;
|
||||||
case R.id.games_group_moveup:
|
case R.id.games_group_moveup:
|
||||||
moveGroup( groupID, true );
|
moveGroup( groupID, true );
|
||||||
|
@ -1982,7 +1971,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
private void handleNewGame( boolean solo )
|
private void handleNewGame( boolean solo )
|
||||||
{
|
{
|
||||||
m_nextIsSolo = solo;
|
m_nextIsSolo = solo;
|
||||||
showDialog( DlgID.GAMES_LIST_NEWGAME );
|
showDialogFragment( DlgID.GAMES_LIST_NEWGAME, solo );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNewGameButton( boolean solo )
|
private void handleNewGameButton( boolean solo )
|
||||||
|
@ -2039,10 +2028,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
DictLangCache.haveDict( m_activity, nli.lang, nli.dict );
|
DictLangCache.haveDict( m_activity, nli.lang, nli.dict );
|
||||||
}
|
}
|
||||||
if ( !haveDict ) {
|
if ( !haveDict ) {
|
||||||
m_netLaunchInfo = nli;
|
showDialogFragment( DlgID.WARN_NODICT_NEW, 0, nli.dict, nli.lang );
|
||||||
m_missingDictLang = nli.lang;
|
|
||||||
m_missingDictName = nli.dict;
|
|
||||||
showDialog( DlgID.WARN_NODICT_NEW );
|
|
||||||
}
|
}
|
||||||
return haveDict;
|
return haveDict;
|
||||||
}
|
}
|
||||||
|
@ -2067,23 +2053,22 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !hasDicts ) {
|
if ( !hasDicts ) {
|
||||||
m_missingDictLang = missingLang[0];
|
String missingDictName = null;
|
||||||
|
int missingDictLang = missingLang[0];
|
||||||
if ( 0 < missingNames[0].length ) {
|
if ( 0 < missingNames[0].length ) {
|
||||||
m_missingDictName = missingNames[0][0];
|
missingDictName = missingNames[0][0];
|
||||||
} else {
|
|
||||||
m_missingDictName = null;
|
|
||||||
}
|
}
|
||||||
m_missingDictRowId = rowid;
|
m_missingDictRowId = rowid;
|
||||||
m_missingDictMenuId = forMenu;
|
m_missingDictMenuId = forMenu;
|
||||||
if ( 0 == DictLangCache.getLangCount( m_activity, m_missingDictLang ) ) {
|
if ( 0 == DictLangCache.getLangCount( m_activity, missingDictLang ) ) {
|
||||||
showDialog( DlgID.WARN_NODICT );
|
showDialogFragment( DlgID.WARN_NODICT, rowid, missingDictName, missingDictLang );
|
||||||
} else if ( null != m_missingDictName ) {
|
} else if ( null != missingDictName ) {
|
||||||
showDialog( DlgID.WARN_NODICT_SUBST );
|
showDialogFragment( DlgID.WARN_NODICT_SUBST, rowid, missingDictName,
|
||||||
|
missingDictLang );
|
||||||
} else {
|
} else {
|
||||||
String dict =
|
String dict =
|
||||||
DictLangCache.getHaveLang( m_activity, m_missingDictLang)[0];
|
DictLangCache.getHaveLang( m_activity, missingDictLang)[0];
|
||||||
if ( GameUtils.replaceDicts( m_activity, m_missingDictRowId,
|
if ( GameUtils.replaceDicts( m_activity, rowid, null, dict ) ) {
|
||||||
null, dict ) ) {
|
|
||||||
launchGameIf();
|
launchGameIf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2215,7 +2200,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
{
|
{
|
||||||
if ( -1 != intent.getLongExtra( REMATCH_ROWID_EXTRA, -1 ) ) {
|
if ( -1 != intent.getLongExtra( REMATCH_ROWID_EXTRA, -1 ) ) {
|
||||||
m_rematchExtras = intent.getExtras();
|
m_rematchExtras = intent.getExtras();
|
||||||
showDialog( DlgID.GAMES_LIST_NAME_REMATCH );
|
showDialogFragment( DlgID.GAMES_LIST_NAME_REMATCH, intent.getExtras() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2310,7 +2295,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
{
|
{
|
||||||
String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true );
|
String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true );
|
||||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||||
showDialog( DlgID.GET_NAME );
|
showDialogFragment( DlgID.GET_NAME );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDictForLangIf()
|
private void getDictForLangIf()
|
||||||
|
@ -2391,7 +2376,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
{
|
{
|
||||||
if ( m_moveAfterNewGroup ) {
|
if ( m_moveAfterNewGroup ) {
|
||||||
m_moveAfterNewGroup = false;
|
m_moveAfterNewGroup = false;
|
||||||
showDialog( DlgID.CHANGE_GROUP );
|
showDialogFragment( DlgID.CHANGE_GROUP );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,6 +274,11 @@ public class XWActivity extends FragmentActivity
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||||
|
{
|
||||||
|
return m_dlgt.makeDialog( dlgID, params );
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// DlgClickNotify interface
|
// DlgClickNotify interface
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in a new issue