mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-29 10:26:36 +01:00
go back to using XWListItem (with its delete-me X) and get rid of
delete context menu item.
This commit is contained in:
parent
2dbf1ac489
commit
75e41caf90
4 changed files with 52 additions and 45 deletions
|
@ -7,9 +7,6 @@
|
|||
<item android:id="@+id/dicts_item_select_robot"
|
||||
android:title="@string/dicts_item_select_robot"
|
||||
/>
|
||||
<item android:id="@+id/dicts_item_delete"
|
||||
android:title="@string/dicts_item_delete"
|
||||
/>
|
||||
<item android:id="@+id/dicts_item_details"
|
||||
android:title="@string/dicts_item_details"
|
||||
/>
|
||||
|
|
|
@ -53,7 +53,7 @@ import org.eehouse.android.xw4.jni.JNIUtilsImpl;
|
|||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
|
||||
public class DictsActivity extends ExpandableListActivity
|
||||
implements View.OnClickListener {
|
||||
implements View.OnClickListener, XWListItem.DeleteCallback {
|
||||
|
||||
private static final String DICT_DOLAUNCH = "do_launch";
|
||||
private static final String DICT_LANG_EXTRA = "use_lang";
|
||||
|
@ -66,6 +66,7 @@ public class DictsActivity extends ExpandableListActivity
|
|||
private String m_download;
|
||||
|
||||
private DlgDelegate m_delegate;
|
||||
LayoutInflater m_factory;
|
||||
|
||||
private class DictListAdapter implements ExpandableListAdapter {
|
||||
private Context m_context;
|
||||
|
@ -94,13 +95,21 @@ public class DictsActivity extends ExpandableListActivity
|
|||
int lang = (int)getGroupId( groupPosition );
|
||||
String[] dicts = DictLangCache.getHaveLang( m_context, lang );
|
||||
String text;
|
||||
boolean canDelete = false;
|
||||
if ( null != dicts && childPosition < dicts.length ) {
|
||||
text = dicts[childPosition];
|
||||
canDelete = !GameUtils.dictIsBuiltin( DictsActivity.this,
|
||||
text );
|
||||
} else {
|
||||
text = m_download;
|
||||
}
|
||||
TextView view = new TextView( m_context );
|
||||
XWListItem view =
|
||||
(XWListItem)m_factory.inflate( R.layout.list_item, null );
|
||||
view.setText( text );
|
||||
if ( canDelete ) {
|
||||
view.setDeleteCallback( DictsActivity.this );
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -108,7 +117,7 @@ public class DictsActivity extends ExpandableListActivity
|
|||
{
|
||||
int lang = (int)getGroupId( groupPosition );
|
||||
String[] dicts = DictLangCache.getHaveLang( m_context, lang );
|
||||
int result = 1; // for the download option
|
||||
int result = 0; // 1; // 1 for the download option
|
||||
if ( null != dicts ) {
|
||||
result += dicts.length;
|
||||
}
|
||||
|
@ -184,27 +193,28 @@ public class DictsActivity extends ExpandableListActivity
|
|||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog dialog = m_delegate.onCreateDialog( id );
|
||||
if ( null != dialog ) {
|
||||
switch( id ) {
|
||||
case PICK_STORAGE:
|
||||
DialogInterface.OnClickListener lstnrSD;
|
||||
Dialog dialog;
|
||||
switch( id ) {
|
||||
case PICK_STORAGE:
|
||||
DialogInterface.OnClickListener lstnrSD;
|
||||
|
||||
lstnrSD = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
startDownload( m_lang, m_name, item !=
|
||||
DialogInterface.BUTTON_POSITIVE );
|
||||
}
|
||||
};
|
||||
lstnrSD = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
startDownload( m_lang, m_name, item !=
|
||||
DialogInterface.BUTTON_POSITIVE );
|
||||
}
|
||||
};
|
||||
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.storeWhereTitle )
|
||||
.setMessage( R.string.storeWhereMsg )
|
||||
.setPositiveButton( R.string.button_internal, lstnrSD )
|
||||
.setNegativeButton( R.string.button_sd, lstnrSD )
|
||||
.create();
|
||||
break;
|
||||
}
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.storeWhereTitle )
|
||||
.setMessage( R.string.storeWhereMsg )
|
||||
.setPositiveButton( R.string.button_internal, lstnrSD )
|
||||
.setNegativeButton( R.string.button_sd, lstnrSD )
|
||||
.create();
|
||||
break;
|
||||
default:
|
||||
dialog = m_delegate.onCreateDialog( id );
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
@ -216,10 +226,12 @@ public class DictsActivity extends ExpandableListActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
m_delegate = new DlgDelegate( this );
|
||||
m_factory = LayoutInflater.from( this );
|
||||
|
||||
m_download = getString( R.string.download_dicts );
|
||||
m_langs = DictLangCache.listLangs( this );
|
||||
|
@ -294,20 +306,14 @@ public class DictsActivity extends ExpandableListActivity
|
|||
return false;
|
||||
}
|
||||
|
||||
TextView text = (TextView)info.targetView;
|
||||
XWListItem row = (XWListItem)info.targetView;
|
||||
int id = item.getItemId();
|
||||
switch( id ) {
|
||||
case R.id.dicts_item_select_human:
|
||||
setDefault( R.string.key_default_dict, text );
|
||||
setDefault( R.string.key_default_dict, row );
|
||||
break;
|
||||
case R.id.dicts_item_select_robot:
|
||||
setDefault( R.string.key_default_robodict, text );
|
||||
break;
|
||||
case R.id.dicts_item_delete:
|
||||
long packedPosition = info.packedPosition;
|
||||
int groupPosition = ExpandableListView.
|
||||
getPackedPositionGroup( packedPosition );
|
||||
deleteDict( groupPosition, text );
|
||||
setDefault( R.string.key_default_robodict, row );
|
||||
break;
|
||||
case R.id.dicts_item_details:
|
||||
Utils.notImpl( this );
|
||||
|
@ -317,24 +323,22 @@ public class DictsActivity extends ExpandableListActivity
|
|||
return handled;
|
||||
}
|
||||
|
||||
private void setDefault( int keyId, final TextView text )
|
||||
private void setDefault( int keyId, final XWListItem text )
|
||||
{
|
||||
SharedPreferences sp
|
||||
= PreferenceManager.getDefaultSharedPreferences( this );
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
String key = getString( keyId );
|
||||
String name = text.getText().toString();
|
||||
String name = text.getText();
|
||||
editor.putString( key, name );
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
// DeleteCallback interface
|
||||
private void deleteDict( int group, TextView text )
|
||||
public void deleteCalled( int myPosition, final String dict )
|
||||
{
|
||||
final String dict = text.getText().toString();
|
||||
Utils.logf( "deleteDict(%s)", dict );
|
||||
String lang = m_langs[group];
|
||||
int code = DictLangCache.getLangLangCode( this, lang );
|
||||
int code = DictLangCache.getDictLangCode( this, dict );
|
||||
String lang = DictLangCache.getLangName( this, code );
|
||||
int nGames = DBUtils.countGamesUsing( this, code );
|
||||
String msg = String.format( getString( R.string.confirm_delete_dictf ),
|
||||
dict );
|
||||
|
|
|
@ -501,7 +501,7 @@ public class GameConfig extends XWActivity
|
|||
}
|
||||
|
||||
// DeleteCallback interface
|
||||
public void deleteCalled( int myPosition )
|
||||
public void deleteCalled( int myPosition, final String name )
|
||||
{
|
||||
if ( m_gi.delete( myPosition ) ) {
|
||||
loadPlayers();
|
||||
|
|
|
@ -34,7 +34,7 @@ public class XWListItem extends LinearLayout {
|
|||
DeleteCallback m_cb;
|
||||
|
||||
public interface DeleteCallback {
|
||||
void deleteCalled( int myPosition );
|
||||
void deleteCalled( int myPosition, String name );
|
||||
}
|
||||
|
||||
public XWListItem( Context cx, AttributeSet as ) {
|
||||
|
@ -51,6 +51,12 @@ public class XWListItem extends LinearLayout {
|
|||
view.setText( text );
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
TextView view = (TextView)getChildAt( 0 );
|
||||
return view.getText().toString();
|
||||
}
|
||||
|
||||
public void setDeleteCallback( DeleteCallback cb )
|
||||
{
|
||||
m_cb = cb;
|
||||
|
@ -58,7 +64,7 @@ public class XWListItem extends LinearLayout {
|
|||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View view ) {
|
||||
m_cb.deleteCalled( m_position );
|
||||
m_cb.deleteCalled( m_position, getText() );
|
||||
}
|
||||
} );
|
||||
button.setVisibility( View.VISIBLE );
|
||||
|
|
Loading…
Reference in a new issue