mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
add menuitem and dialog it triggers to rename games. Add new DB field
to hold game name, and getter and setter. Replace existing gameName() method with call to new getter.
This commit is contained in:
parent
173e2e8423
commit
9aeb8858fe
11 changed files with 141 additions and 13 deletions
27
xwords4/android/XWords4/res/layout/rename_game.xml
Normal file
27
xwords4/android/XWords4/res/layout/rename_game.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:text="@string/rename_label"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_marginLeft="20dip"
|
||||
android:layout_marginRight="20dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
<EditText android:id="@+id/name_edit"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_marginLeft="30dip"
|
||||
android:layout_marginRight="30dip"
|
||||
android:autoText="false"
|
||||
android:singleLine="true"
|
||||
android:selectAllOnFocus="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
|
@ -7,6 +7,9 @@
|
|||
<!-- <item android:id="@+id/list_item_netconfig" -->
|
||||
<!-- android:title="net (remove me)" -->
|
||||
<!-- /> -->
|
||||
<item android:id="@+id/list_item_rename"
|
||||
android:title="@string/list_item_rename"
|
||||
/>
|
||||
<item android:id="@+id/list_item_copy"
|
||||
android:title="@string/list_item_copy"
|
||||
/>
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<string name="button_new_game">Add game</string>
|
||||
|
||||
<string name="list_item_config">Game settings...</string>
|
||||
<string name="list_item_rename">Rename...</string>
|
||||
<string name="game_rename_title">Rename game</string>
|
||||
<string name="rename_label">Change the name of this game to:</string>
|
||||
<string name="list_item_hide">Hide</string>
|
||||
<string name="list_item_delete">Delete</string>
|
||||
<string name="list_item_copy">Copy</string>
|
||||
|
|
|
@ -1108,7 +1108,7 @@ public class BoardActivity extends XWActivity
|
|||
m_jniThread.handle( JNICmd.CMD_START );
|
||||
|
||||
if ( !CommonPrefs.getHideTitleBar( this ) ) {
|
||||
setTitle( GameUtils.gameName( this, m_rowid ) );
|
||||
setTitle( DBUtils.getName( this, m_rowid ) );
|
||||
}
|
||||
m_toolbar = new Toolbar( this );
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
|||
((Button)findViewById( R.id.send_button )).setOnClickListener( this );
|
||||
|
||||
String fmt = getString( R.string.chat_titlef );
|
||||
setTitle( String.format( fmt, GameUtils.gameName( this, m_rowid ) ) );
|
||||
setTitle( String.format( fmt, DBUtils.getName( this, m_rowid ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,9 +29,10 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String TABLE_NAME_SUM = "summaries";
|
||||
public static final String TABLE_NAME_OBITS = "obits";
|
||||
private static final String DB_NAME = "xwdb";
|
||||
private static final int DB_VERSION = 8;
|
||||
private static final int DB_VERSION = 9;
|
||||
|
||||
public static final String FILE_NAME = "FILE_NAME";
|
||||
public static final String GAME_NAME = "GAME_NAME";
|
||||
public static final String NUM_MOVES = "NUM_MOVES";
|
||||
public static final String TURN = "TURN";
|
||||
public static final String GIFLAGS = "GIFLAGS";
|
||||
|
@ -71,6 +72,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
{
|
||||
db.execSQL( "CREATE TABLE " + TABLE_NAME_SUM + " ("
|
||||
+ FILE_NAME + " TEXT PRIMARY KEY,"
|
||||
+ GAME_NAME + " TEXT,"
|
||||
+ NUM_MOVES + " INTEGER,"
|
||||
+ TURN + " INTEGER,"
|
||||
+ GIFLAGS + " INTEGER,"
|
||||
|
@ -133,6 +135,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
} else if ( newVersion == 8 && oldVersion == 7 ) {
|
||||
db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM +
|
||||
" ADD COLUMN " + MISSINGPLYRS + " INTEGER;" );
|
||||
} else if ( newVersion == 9 && oldVersion == 8 ) {
|
||||
db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM +
|
||||
" ADD COLUMN " + GAME_NAME + " TEXT;" );
|
||||
} else {
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" );
|
||||
if ( oldVersion >= 6 ) {
|
||||
|
|
|
@ -593,6 +593,57 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
// Get either the file name or game name, preferring the latter.
|
||||
public static String getName( Context context, long rowid )
|
||||
{
|
||||
String result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
|
||||
String[] columns = { DBHelper.FILE_NAME, DBHelper.GAME_NAME };
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.GAME_NAME));
|
||||
if ( null == result || 0 == result.length() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.FILE_NAME));
|
||||
if ( null == result || 0 == result.length() ) {
|
||||
String fmt = context.getString( R.string.gamef );
|
||||
result = String.format( fmt, rowid );
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
Utils.logf( "getName(%d)=>%s", rowid, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setName( Context context, long rowid, String name )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.GAME_NAME, name );
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
db.close();
|
||||
if ( 0 == result ) {
|
||||
Utils.logf( "setName(%d,%s) failed", rowid, name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static HistoryPair[] getChatHistory( Context context, long rowid )
|
||||
{
|
||||
HistoryPair[] result = null;
|
||||
|
|
|
@ -974,7 +974,7 @@ public class GameConfig extends XWActivity
|
|||
String fmt = getString( m_notNetworkedGame ?
|
||||
R.string.title_game_configf
|
||||
: R.string.title_gamenet_configf );
|
||||
setTitle( String.format( fmt, GameUtils.gameName( this, m_rowid ) ) );
|
||||
setTitle( String.format( fmt, DBUtils.getName( this, m_rowid ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class GameListAdapter extends XWListAdapter {
|
|||
if ( hideTitle ) {
|
||||
view.setVisibility( View.GONE );
|
||||
} else {
|
||||
String name = GameUtils.gameName( m_context, m_rowid );
|
||||
String name = DBUtils.getName( m_context, m_rowid );
|
||||
String format =
|
||||
m_context.getString( R.string.str_game_namef );
|
||||
String lang =
|
||||
|
@ -172,7 +172,7 @@ public class GameListAdapter extends XWListAdapter {
|
|||
if ( hideTitle ) {
|
||||
view.setVisibility( View.GONE );
|
||||
} else {
|
||||
String text = GameUtils.gameName( m_context, rowid );
|
||||
String text = DBUtils.getName( m_context, rowid );
|
||||
view.setText( text );
|
||||
}
|
||||
|
||||
|
|
|
@ -735,12 +735,6 @@ public class GameUtils {
|
|||
return file.endsWith( XWConstants.DICT_EXTN );
|
||||
}
|
||||
|
||||
public static String gameName( Context context, long rowid )
|
||||
{
|
||||
return String.format( "Row %d", rowid );
|
||||
// return path.substring( 0, path.lastIndexOf( XWConstants.GAME_EXTN ) );
|
||||
}
|
||||
|
||||
public static void launchGame( Activity activity, long rowid,
|
||||
boolean invited )
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ public class GamesList extends XWListActivity
|
|||
private static final int WARN_NODICT_SUBST = WARN_NODICT + 1;
|
||||
private static final int SHOW_SUBST = WARN_NODICT + 2;
|
||||
private static final int GET_NAME = WARN_NODICT + 3;
|
||||
private static final int RENAME_GAME = WARN_NODICT + 4;
|
||||
|
||||
private GameListAdapter m_adapter;
|
||||
private String m_missingDict;
|
||||
|
@ -67,6 +68,7 @@ public class GamesList extends XWListActivity
|
|||
private long m_missingDictRowId;
|
||||
private String[] m_sameLangDicts;
|
||||
private int m_missingDictLang;
|
||||
private long m_rowid;
|
||||
|
||||
// private XWPhoneStateListener m_phoneStateListener;
|
||||
// private class XWPhoneStateListener extends PhoneStateListener {
|
||||
|
@ -84,6 +86,8 @@ public class GamesList extends XWListActivity
|
|||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
DialogInterface.OnClickListener lstnr;
|
||||
LinearLayout layout;
|
||||
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
if ( null == dialog ) {
|
||||
AlertDialog.Builder ab;
|
||||
|
@ -161,8 +165,30 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case RENAME_GAME:
|
||||
layout =
|
||||
(LinearLayout)Utils.inflate( this, R.layout.rename_game );
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlgi, int item ) {
|
||||
Dialog dlg = (Dialog)dlgi;
|
||||
EditText txt =
|
||||
(EditText)dlg.findViewById( R.id.name_edit );
|
||||
String name = txt.getText().toString();
|
||||
DBUtils.setName( GamesList.this, m_rowid, name );
|
||||
m_adapter.inval( m_rowid );
|
||||
}
|
||||
};
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.game_rename_title )
|
||||
.setNegativeButton( R.string.button_cancel, null )
|
||||
.setPositiveButton( R.string.button_ok, lstnr )
|
||||
.setView( layout )
|
||||
.create();
|
||||
break;
|
||||
|
||||
case GET_NAME:
|
||||
LinearLayout layout =
|
||||
layout =
|
||||
(LinearLayout)Utils.inflate( this, R.layout.dflt_name );
|
||||
final EditText etext =
|
||||
(EditText)layout.findViewById( R.id.name_edit );
|
||||
|
@ -196,6 +222,21 @@ public class GamesList extends XWListActivity
|
|||
return dialog;
|
||||
} // onCreateDialog
|
||||
|
||||
@Override
|
||||
public void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
switch( id ) {
|
||||
case RENAME_GAME:
|
||||
String name = DBUtils.getName( this, m_rowid );
|
||||
EditText txt = (EditText)dialog.findViewById( R.id.name_edit );
|
||||
txt.setText( name );
|
||||
break;
|
||||
default:
|
||||
super.onPrepareDialog( id, dialog );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -480,6 +521,10 @@ public class GamesList extends XWListActivity
|
|||
case R.id.list_item_config:
|
||||
GameUtils.doConfig( this, rowid, GameConfig.class );
|
||||
break;
|
||||
case R.id.list_item_rename:
|
||||
m_rowid = rowid;
|
||||
showDialog( RENAME_GAME );
|
||||
break;
|
||||
|
||||
case R.id.list_item_new_from:
|
||||
Runnable proc = new Runnable() {
|
||||
|
|
Loading…
Reference in a new issue