tweaks to tile picker

Fix to auto-exit for blank- but not tray-picking and to not show Del
button for blank case (dumb since we're exiting anyway.)
This commit is contained in:
Eric House 2017-03-14 19:47:45 -07:00
parent 58fc0e9b81
commit fc438a4bcf
3 changed files with 60 additions and 46 deletions

View file

@ -106,25 +106,25 @@ public class TilePickAlert extends XWDialogFragment
m_view = (TilePickView)LocUtils.inflate( activity, R.layout.tile_picker );
m_view.init( this, m_state, sis );
AlertDialog.Builder ab = LocUtils.makeAlertBuilder( activity )
.setTitle( String.format( "Pick %d", m_state.nToPick ) )
.setView( m_view );
if ( null != m_state.counts ) {
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
@Override
public void onClick( DialogInterface dialog, int which ) {
onDonePressed();
onDone();
}
};
m_dialog = LocUtils.makeAlertBuilder( activity )
.setTitle( String.format( "Pick %d", m_state.nToPick ) )
.setView( m_view )
.setPositiveButton( R.string.tilepick_all, lstnr )
.create();
ab.setPositiveButton( R.string.tilepick_all, lstnr );
}
m_dialog = ab.create();
return m_dialog;
}
// TilePickView.TilePickListener
@Override
public void onDonePressed()
private void onDone()
{
Activity activity = getActivity();
if ( activity instanceof DlgClickNotify ) {
@ -136,12 +136,15 @@ public class TilePickAlert extends XWDialogFragment
dismiss();
}
// TilePickView.TilePickListener
@Override
public void onTilesChanged( int nToPick, int[] newTiles )
{
m_selTiles = newTiles;
if ( null != m_dialog ) {
boolean done = nToPick == newTiles.length;
if ( done && null == m_state.counts ) {
onDone();
} else if ( null != m_dialog ) {
int msgID = done ? android.R.string.ok : R.string.tilepick_all;
Button button = m_dialog.getButton( AlertDialog.BUTTON_POSITIVE );
button.setText( LocUtils.getString( getContext(), msgID ) );

View file

@ -21,30 +21,22 @@
package org.eehouse.android.xw4;
import android.text.TextUtils;
// import android.app.Dialog;
import android.content.Context;
// import android.content.DialogInterface;
// import android.content.Intent;
// import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
// import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
// import android.widget.AdapterView;
// import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
// import android.widget.ListView;
import android.widget.TextView;
// import junit.framework.Assert;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.TilePickAlert.TilePickState;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
@ -54,14 +46,13 @@ public class TilePickView extends LinearLayout {
private static final boolean SHOW_UNAVAIL = false;
public interface TilePickListener {
void onDonePressed();
void onTilesChanged( int nToPick, int[] newTiles );
}
private ArrayList<Integer> m_pendingTiles;
private TilePickListener m_listner;
private TilePickState m_state;
private List<Button> m_pendingButtons;
private Map<Integer, Button> m_buttons = new HashMap<Integer, Button>();
public TilePickView( Context context, AttributeSet as ) {
super( context, as );
@ -90,6 +81,8 @@ public class TilePickView extends LinearLayout {
m_listner.onTilesChanged( m_state.nToPick, getPending() );
}
} );
m_listner.onTilesChanged( m_state.nToPick, getPending() );
}
// NOT @Override!!!
@ -112,7 +105,6 @@ public class TilePickView extends LinearLayout {
Context context = getContext();
LinearLayout container = (LinearLayout)
findViewById( R.id.button_bar_container );
m_pendingButtons = new ArrayList<Button>();
LinearLayout bar = null;
int barLen = 0;
@ -132,8 +124,9 @@ public class TilePickView extends LinearLayout {
}
Button button = (Button)bar.getChildAt( visIndex % barLen );
m_buttons.put( dataIndex, button );
button.setVisibility( View.VISIBLE );
updateButton( button, dataIndex, 0 );
updateButton( dataIndex, 0 );
button.setOnClickListener( new OnClickListener() {
@Override
public void onClick( View view ) {
@ -143,16 +136,16 @@ public class TilePickView extends LinearLayout {
}
}
private void onTileClicked( View view, int index ) {
private void onTileClicked( View view, int index )
{
// replace the last pick if we don't have room to add a new one
if ( m_pendingTiles.size() == m_state.nToPick ) {
removePending();
}
Button button = (Button)view;
m_pendingTiles.add( index );
m_pendingButtons.add( button );
updateDelButton();
updateButton( button, index, -1 );
updateButton( index, -1 );
showPending();
m_listner.onTilesChanged( m_state.nToPick, getPending() );
@ -160,22 +153,39 @@ public class TilePickView extends LinearLayout {
private void showPending()
{
TextView text = (TextView)findViewById( R.id.pending_desc );
TextView desc = (TextView)findViewById( R.id.pending_desc );
if ( null == m_state.counts ) {
desc.setVisibility( View.GONE );
} else {
List<String> faces = new ArrayList<String>();
for ( int indx : m_pendingTiles ) {
faces.add( m_state.faces[indx] );
}
String msg = "Current selection: " + TextUtils.join( ",", faces );
text.setText( msg );
desc.setText( LocUtils.getString( getContext(),
R.string.tile_pick_summary_fmt,
TextUtils.join( ",", faces ) ) );
}
}
private void updateButton( Button button, int index, int adjust )
private int pendingCount( int dataIndex )
{
int count = 0;
for ( int index : m_pendingTiles ) {
if ( index == dataIndex ) {
++count;
}
}
return count;
}
private void updateButton( int index, int adjust )
{
Button button = m_buttons.get( index );
Context context = getContext();
String face = m_state.faces[index];
if ( null != m_state.counts ) {
m_state.counts[index] += adjust;
int count = m_state.counts[index];
int count = m_state.counts[index] - pendingCount( index );
face = LocUtils.getString( context, R.string.tile_button_txt_fmt,
face, count );
@ -188,14 +198,14 @@ public class TilePickView extends LinearLayout {
private void removePending()
{
int tile = m_pendingTiles.remove( m_pendingTiles.size() - 1 );
Button button = m_pendingButtons.remove( m_pendingButtons.size() - 1 );
updateButton( button, tile, 1 );
updateButton( tile, 1 );
showPending();
}
private void updateDelButton()
{
int vis = m_pendingTiles.size() == 0 ? View.INVISIBLE : View.VISIBLE;
int vis = null == m_state.counts || m_pendingTiles.size() == 0
? View.INVISIBLE : View.VISIBLE;
findViewById( R.id.del ).setVisibility( vis );
}
}

View file

@ -1538,6 +1538,7 @@
<string name="title_tile_picker">Letter for blank</string>
<string name="tile_button_txt_fmt">%1$s (%2$d)</string>
<string name="tile_pick_summary_fmt">Current pick: %1$s</string>
<!-- title of dialog brought up in response to the
board_menu_game_left menu. The dialog lists all tiles