modify item text after the db backing it is modified by covering edit

activity.
This commit is contained in:
Eric House 2014-05-16 22:11:18 -07:00
parent dfbb1bae71
commit 018424e6e8
5 changed files with 47 additions and 21 deletions

View file

@ -427,7 +427,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
} }
public void onWindowFocusChanged( boolean hasFocus ) protected void onWindowFocusChanged( boolean hasFocus )
{ {
// super.onWindowFocusChanged( hasFocus ); // super.onWindowFocusChanged( hasFocus );
if ( hasFocus ) { if ( hasFocus ) {

View file

@ -47,4 +47,11 @@ public class LocActivity extends XWListActivity {
super.onBackPressed(); super.onBackPressed();
} }
} }
@Override
public void onWindowFocusChanged( boolean hasFocus )
{
m_dlgt.onWindowFocusChanged( hasFocus );
super.onWindowFocusChanged( hasFocus );
}
} }

View file

@ -46,6 +46,7 @@ public class LocDelegate extends ListDelegateBase
private ImageButton m_searchButton; private ImageButton m_searchButton;
private LocSearcher m_searcher; private LocSearcher m_searcher;
private String m_curSearch; private String m_curSearch;
private LocListItem m_lastItem;
protected LocDelegate( ListActivity activity, Bundle savedInstanceState ) protected LocDelegate( ListActivity activity, Bundle savedInstanceState )
{ {
@ -63,18 +64,32 @@ public class LocDelegate extends ListDelegateBase
@Override @Override
public void onClick( View view ) public void onClick( View view )
{ {
String newText = m_searchField.getText().toString(); if ( view instanceof LocListItem ) {
if ( null == m_curSearch || ! m_curSearch.equals( newText ) ) { m_lastItem = (LocListItem)view;
m_curSearch = newText; LocItemEditDelegate.launch( m_activity, m_lastItem.getPair() );
m_searcher.start( newText ); // synchronous for now } else if ( view == m_searchButton ) {
makeNewAdapter(); 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() private void makeNewAdapter()
{ {
ListView listview = getListView(); 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 ); m_activity.setListAdapter( m_adapter );
} }

View file

@ -33,13 +33,16 @@ public class LocListAdapter extends XWListAdapter {
private Context m_context; private Context m_context;
private ListView m_listView; private ListView m_listView;
private LocSearcher m_searcher; private LocSearcher m_searcher;
private View.OnClickListener m_listener;
protected LocListAdapter( Context context, ListView listView, protected LocListAdapter( Context context, ListView listView,
LocSearcher searcher ) LocSearcher searcher,
View.OnClickListener listener )
{ {
m_context = context; m_context = context;
m_listView = listView; m_listView = listView;
m_searcher = searcher; m_searcher = searcher;
m_listener = listener;
} }
@Override @Override
@ -54,6 +57,8 @@ public class LocListAdapter extends XWListAdapter {
{ {
// DbgUtils.logf( "LocListAdapter.getView(position=%d)", position ); // DbgUtils.logf( "LocListAdapter.getView(position=%d)", position );
LocSearcher.Pair pair = m_searcher.getNthMatch( 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;
} }
} }

View file

@ -35,8 +35,7 @@ import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.DbgUtils; import org.eehouse.android.xw4.DbgUtils;
public class LocListItem extends LinearLayout public class LocListItem extends LinearLayout {
implements View.OnClickListener {
private static final int LOCAL_COLOR = Color.argb( 0xFF, 0x7f, 0x00, 0x00 ); private static final int LOCAL_COLOR = Color.argb( 0xFF, 0x7f, 0x00, 0x00 );
@ -55,7 +54,16 @@ public class LocListItem extends LinearLayout
{ {
super.onFinishInflate(); super.onFinishInflate();
m_xlated = (TextView)findViewById( R.id.xlated_view ); m_xlated = (TextView)findViewById( R.id.xlated_view );
setOnClickListener( this ); }
protected void update()
{
setXlated();
}
protected LocSearcher.Pair getPair()
{
return m_pair;
} }
private void setEnglish() 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, protected static LocListItem create( Context context,
LocSearcher.Pair pair, LocSearcher.Pair pair,
int position ) int position )