diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 3d51d2df5..685df2046 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -427,7 +427,7 @@ public class GamesListDelegate extends ListDelegateBase } } - public void onWindowFocusChanged( boolean hasFocus ) + protected void onWindowFocusChanged( boolean hasFocus ) { // super.onWindowFocusChanged( hasFocus ); if ( hasFocus ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocActivity.java index 556ebb712..458666f19 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocActivity.java @@ -47,4 +47,11 @@ public class LocActivity extends XWListActivity { super.onBackPressed(); } } + + @Override + public void onWindowFocusChanged( boolean hasFocus ) + { + m_dlgt.onWindowFocusChanged( hasFocus ); + super.onWindowFocusChanged( hasFocus ); + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java index a52311149..e41f8d234 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocDelegate.java @@ -46,6 +46,7 @@ public class LocDelegate extends ListDelegateBase private ImageButton m_searchButton; private LocSearcher m_searcher; private String m_curSearch; + private LocListItem m_lastItem; protected LocDelegate( ListActivity activity, Bundle savedInstanceState ) { @@ -63,18 +64,32 @@ public class LocDelegate extends ListDelegateBase @Override public void onClick( View view ) { - String newText = m_searchField.getText().toString(); - if ( null == m_curSearch || ! m_curSearch.equals( newText ) ) { - m_curSearch = newText; - m_searcher.start( newText ); // synchronous for now - makeNewAdapter(); + if ( view instanceof LocListItem ) { + m_lastItem = (LocListItem)view; + LocItemEditDelegate.launch( m_activity, m_lastItem.getPair() ); + } else if ( view == m_searchButton ) { + String newText = m_searchField.getText().toString(); + if ( null == m_curSearch || ! m_curSearch.equals( newText ) ) { + m_curSearch = newText; + m_searcher.start( newText ); // synchronous for now + makeNewAdapter(); + } + } + } + + protected void onWindowFocusChanged( boolean hasFocus ) + { + if ( hasFocus && null != m_lastItem ) { + DbgUtils.logf( "updating LocListItem instance %H", m_lastItem ); + m_lastItem.update(); + m_lastItem = null; } } private void makeNewAdapter() { ListView listview = getListView(); - m_adapter = new LocListAdapter( m_activity, listview, m_searcher ); + m_adapter = new LocListAdapter( m_activity, listview, m_searcher, this ); m_activity.setListAdapter( m_adapter ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java index bc7e8d671..da70c2f27 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListAdapter.java @@ -33,13 +33,16 @@ public class LocListAdapter extends XWListAdapter { private Context m_context; private ListView m_listView; private LocSearcher m_searcher; + private View.OnClickListener m_listener; protected LocListAdapter( Context context, ListView listView, - LocSearcher searcher ) + LocSearcher searcher, + View.OnClickListener listener ) { m_context = context; m_listView = listView; m_searcher = searcher; + m_listener = listener; } @Override @@ -54,6 +57,8 @@ public class LocListAdapter extends XWListAdapter { { // DbgUtils.logf( "LocListAdapter.getView(position=%d)", position ); LocSearcher.Pair pair = m_searcher.getNthMatch( position ); - return LocListItem.create( m_context, pair, position ); + View view = LocListItem.create( m_context, pair, position ); + view.setOnClickListener( m_listener ); + return view; } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java index 3b4c9e3e2..7ebba02c5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocListItem.java @@ -35,8 +35,7 @@ import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.DbgUtils; -public class LocListItem extends LinearLayout - implements View.OnClickListener { +public class LocListItem extends LinearLayout { private static final int LOCAL_COLOR = Color.argb( 0xFF, 0x7f, 0x00, 0x00 ); @@ -55,7 +54,16 @@ public class LocListItem extends LinearLayout { super.onFinishInflate(); m_xlated = (TextView)findViewById( R.id.xlated_view ); - setOnClickListener( this ); + } + + protected void update() + { + setXlated(); + } + + protected LocSearcher.Pair getPair() + { + return m_pair; } private void setEnglish() @@ -84,15 +92,6 @@ public class LocListItem extends LinearLayout } } - ////////////////////////////////////////////////// - // View.OnClickListener interface - ////////////////////////////////////////////////// - @Override - public void onClick( View view ) - { - LocItemEditDelegate.launch( getContext(), m_pair ); - } - protected static LocListItem create( Context context, LocSearcher.Pair pair, int position )