improve move-to-group dialog: add title and disabled Move button when

radio is current group.
This commit is contained in:
Eric House 2012-12-21 17:06:04 -08:00
parent a3b24be661
commit 2375f86f61

View file

@ -243,29 +243,34 @@ public class GamesList extends XWExpandableListActivity
break; break;
case CHANGE_GROUP: case CHANGE_GROUP:
final long startGroup = DBUtils.getGroupForGame( this, m_rowid );
final int[] selItem = {-1}; // hack!!!! final int[] selItem = {-1}; // hack!!!!
lstnr = new DialogInterface.OnClickListener() { lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlgi, int item ) {
selItem[0] = item; selItem[0] = item;
AlertDialog dlg = (AlertDialog)dlgi;
Button btn =
dlg.getButton( AlertDialog.BUTTON_POSITIVE );
long newGroup = m_adapter.getGroupIDFor( item );
btn.setEnabled( newGroup != startGroup );
} }
}; };
lstnr2 = new DialogInterface.OnClickListener() { lstnr2 = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
if ( -1 != selItem[0] ) { Assert.assertTrue( -1 != selItem[0] );
long groupid = long gid = m_adapter.getGroupIDFor( selItem[0] );
m_adapter.getGroupIDFor( selItem[0] ); DBUtils.moveGame( GamesList.this, m_rowid, gid );
DBUtils.moveGame( GamesList.this, m_rowid, onContentChanged();
groupid );
onContentChanged();
}
} }
}; };
String[] groups = m_adapter.groupNames(); String[] groups = m_adapter.groupNames();
long groupid = DBUtils.getGroupForGame( this, m_rowid ); int curGroupPos = m_adapter.getGroupPosition( startGroup );
int curGroupPos = m_adapter.getGroupPosition( groupid ); String name = GameUtils.getName( this, m_rowid );
dialog = new AlertDialog.Builder( this ) dialog = new AlertDialog.Builder( this )
.setTitle( getString( R.string.change_groupf, name ) )
.setSingleChoiceItems( groups, curGroupPos, lstnr ) .setSingleChoiceItems( groups, curGroupPos, lstnr )
.setPositiveButton( R.string.button_ok, lstnr2 ) .setPositiveButton( R.string.button_move, lstnr2 )
.setNegativeButton( R.string.button_cancel, null )
.create(); .create();
Utils.setRemoveOnDismiss( this, dialog, id ); Utils.setRemoveOnDismiss( this, dialog, id );
break; break;
@ -306,6 +311,16 @@ public class GamesList extends XWExpandableListActivity
return dialog; return dialog;
} // onCreateDialog } // onCreateDialog
@Override protected void onPrepareDialog( int id, Dialog dialog )
{
super.onPrepareDialog( id, dialog );
if ( CHANGE_GROUP == id ) {
((AlertDialog)dialog).getButton( AlertDialog.BUTTON_POSITIVE )
.setEnabled( false );
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {