mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
generalize confirm-delete-all dialog into confirm-then-do
This commit is contained in:
parent
3ffc93a637
commit
4c17ea8802
3 changed files with 48 additions and 35 deletions
|
@ -41,13 +41,15 @@ public class DlgDelegate {
|
|||
public static final int DIALOG_OKONLY = 2;
|
||||
public static final int DIALOG_NOTAGAIN = 3;
|
||||
public static final int WARN_NODICT = 4;
|
||||
public static final int DIALOG_LAST = WARN_NODICT;
|
||||
public static final int CONFIRM_THEN = 5;
|
||||
public static final int DIALOG_LAST = CONFIRM_THEN;
|
||||
|
||||
private int m_msgID;
|
||||
private Runnable m_proc = null;
|
||||
private int m_prefsKey;
|
||||
private Activity m_activity;
|
||||
private String m_dictName = null;
|
||||
DialogInterface.OnClickListener m_then;
|
||||
|
||||
public DlgDelegate( Activity activity ) {
|
||||
m_activity = activity;
|
||||
|
@ -69,6 +71,9 @@ public class DlgDelegate {
|
|||
case WARN_NODICT:
|
||||
dialog = createNoDictDialog();
|
||||
break;
|
||||
case CONFIRM_THEN:
|
||||
dialog = createConfirmThenDialog();
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
@ -90,7 +95,12 @@ public class DlgDelegate {
|
|||
case WARN_NODICT:
|
||||
String format = m_activity.getString( R.string.no_dictf );
|
||||
String msg = String.format( format, m_dictName );
|
||||
((AlertDialog)dialog).setMessage( msg );
|
||||
ad.setMessage( msg );
|
||||
break;
|
||||
case CONFIRM_THEN:
|
||||
ad.setMessage( m_activity.getString(m_msgID) );
|
||||
ad.setButton( AlertDialog.BUTTON_POSITIVE,
|
||||
m_activity.getString( R.string.button_ok ), m_then );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +139,13 @@ public class DlgDelegate {
|
|||
m_activity.showDialog( WARN_NODICT );
|
||||
}
|
||||
|
||||
public void showConfirmThen( int id, DialogInterface.OnClickListener then )
|
||||
{
|
||||
m_msgID = id;
|
||||
m_then = then;
|
||||
m_activity.showDialog( CONFIRM_THEN );
|
||||
}
|
||||
|
||||
private Dialog createAboutDialog()
|
||||
{
|
||||
LayoutInflater factory = LayoutInflater.from( m_activity );
|
||||
|
@ -223,4 +240,15 @@ public class DlgDelegate {
|
|||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private Dialog createConfirmThenDialog()
|
||||
{
|
||||
Dialog dialog = new AlertDialog.Builder( m_activity )
|
||||
.setTitle( R.string.query_title )
|
||||
.setMessage( "" )
|
||||
.setPositiveButton( R.string.button_ok, null ) // will change
|
||||
.setNegativeButton( R.string.button_cancel, null )
|
||||
.create();
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,38 +57,6 @@ public class GamesList extends XWListActivity
|
|||
private String m_missingDict;
|
||||
private Handler m_handler;
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
if ( null == dialog ) {
|
||||
switch( id ) {
|
||||
case CONFIRM_DELETE_ALL:
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
for( String game:GameUtils.gamesList(GamesList.this)) {
|
||||
GameUtils.deleteGame( GamesList.this, game );
|
||||
}
|
||||
m_adapter = new GameListAdapter( GamesList.this );
|
||||
setListAdapter( m_adapter );
|
||||
}
|
||||
};
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.query_title )
|
||||
.setMessage( R.string.confirm_delete_all )
|
||||
.setPositiveButton( R.string.button_ok, lstnr )
|
||||
.setNegativeButton( R.string.button_cancel, null )
|
||||
.create();
|
||||
break;
|
||||
default:
|
||||
Assert.assertTrue(false);
|
||||
// dialog = Utils.onCreateDialog( this, id, m_dlgObjects );
|
||||
}
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -241,7 +209,17 @@ public class GamesList extends XWListActivity
|
|||
switch (item.getItemId()) {
|
||||
case R.id.gamel_menu_delete_all:
|
||||
if ( GameUtils.gamesList( this ).length > 0 ) {
|
||||
showDialog( CONFIRM_DELETE_ALL );
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
for( String game:GameUtils.gamesList(GamesList.this)) {
|
||||
GameUtils.deleteGame( GamesList.this, game );
|
||||
}
|
||||
m_adapter = new GameListAdapter( GamesList.this );
|
||||
setListAdapter( m_adapter );
|
||||
}
|
||||
};
|
||||
showConfirmThen( R.string.confirm_delete_all, lstnr );
|
||||
}
|
||||
handled = true;
|
||||
break;
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.app.ListActivity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
|
@ -90,4 +91,10 @@ public class XWListActivity extends ListActivity {
|
|||
m_delegate.showNoDict( name, lang );
|
||||
}
|
||||
|
||||
protected void showConfirmThen( int msgID,
|
||||
DialogInterface.OnClickListener action )
|
||||
{
|
||||
m_delegate.showConfirmThen( msgID, action );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue