fix case where several patterns call for choice

Null-out patterns so if we have a pattern later we know it came from the
user choosing.
This commit is contained in:
Eric House 2020-08-16 16:08:09 -07:00
parent 6567f6ffcf
commit 1ce9267381
4 changed files with 50 additions and 31 deletions

View file

@ -151,21 +151,25 @@ public class DictBrowseDelegate extends DelegateBase
super(); super();
m_nWords = XwJNI.di_wordCount( m_diClosure ); m_nWords = XwJNI.di_wordCount( m_diClosure );
Log.d( TAG, "making DictListAdapter; have %d words", m_nWords ); // Log.d( TAG, "making DictListAdapter; have %d words", m_nWords );
} }
public Object getItem( int position ) public Object getItem( int position )
{ {
TextView text = (TextView) TextView text = (TextView)
inflate( android.R.layout.simple_list_item_1 ); inflate( android.R.layout.simple_list_item_1 );
text.setOnClickListener( DictBrowseDelegate.this );
String str = XwJNI.di_nthWord( m_diClosure, position, m_browseState.m_delim ); String str = XwJNI.di_nthWord( m_diClosure, position, m_browseState.m_delim );
if ( null != str ) { if ( null != str ) {
if ( SHOW_NUM ) { if ( SHOW_NUM ) {
// Yep, 7 digits. Polish. str = String.format( "%1$d %2$s", 1+position, str );
str = String.format( "%1$7d %2$s", 1+position, str );
} }
} else if ( SHOW_NUM ) {
str = String.format( "%1$d <null>", 1+position );
}
if ( null != str ) {
text.setText( str ); text.setText( str );
text.setOnClickListener( DictBrowseDelegate.this );
} }
return text; return text;
} }
@ -276,14 +280,6 @@ public class DictBrowseDelegate extends DelegateBase
{ {
scrapeBrowseState(); scrapeBrowseState();
storeBrowseState(); storeBrowseState();
// if ( null != m_browseState ) {
// if ( null != m_list ) { // there are words? (don't NPE on empty dict)
// m_browseState.m_pos = m_list.getFirstVisiblePosition();
// View view = m_list.getChildAt( 0 );
// m_browseState.m_top = (view == null) ? 0 : view.getTop();
// }
// storeBrowseState();
// }
super.onPause(); super.onPause();
} }
@ -292,10 +288,6 @@ public class DictBrowseDelegate extends DelegateBase
{ {
super.onResume(); super.onResume();
loadBrowseState(); loadBrowseState();
// if ( null == m_browseState ) {
// m_browseState = DBUtils.dictsGetOffset( m_activity, m_name, m_loc );
// here
// }
setFindPats( m_browseState.m_pats ); setFindPats( m_browseState.m_pats );
} }
@ -312,6 +304,8 @@ public class DictBrowseDelegate extends DelegateBase
for ( int ii = 0; ii < choices.length; ++ii ) { for ( int ii = 0; ii < choices.length; ++ii ) {
strs[ii] = XwJNI.dict_tilesToStr( m_dict, choices[ii], DELIM ); strs[ii] = XwJNI.dict_tilesToStr( m_dict, choices[ii], DELIM );
} }
String title = getString( R.string.pick_tiles_title_fmt,
m_rows[indx].getFieldName() );
final int[] chosen = {0}; final int[] chosen = {0};
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
.setSingleChoiceItems( strs, chosen[0], new DialogInterface.OnClickListener() { .setSingleChoiceItems( strs, chosen[0], new DialogInterface.OnClickListener() {
@ -332,7 +326,7 @@ public class DictBrowseDelegate extends DelegateBase
} }
} }
} ) } )
.setTitle( R.string.pick_tiles_title ) .setTitle( title )
.create(); .create();
break; break;
case SHOW_TILES: case SHOW_TILES:
@ -341,7 +335,7 @@ public class DictBrowseDelegate extends DelegateBase
addTileRows( tilesView, info ); addTileRows( tilesView, info );
String langName = DictLangCache.getLangName( m_activity, m_lang ); String langName = DictLangCache.getLangName( m_activity, m_lang );
String title = getString( R.string.show_tiles_title_fmt, langName ); title = getString( R.string.show_tiles_title_fmt, langName );
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
.setView( tilesView ) .setView( tilesView )
.setPositiveButton( android.R.string.ok, null ) .setPositiveButton( android.R.string.ok, null )
@ -400,9 +394,13 @@ public class DictBrowseDelegate extends DelegateBase
addBlankButtonClicked(); addBlankButtonClicked();
break; break;
default: default:
TextView text = (TextView)view; if ( view instanceof TextView ) {
String[] words = { text.getText().toString() }; TextView text = (TextView)view;
launchLookup( words, m_lang, true ); String[] words = { text.getText().toString() };
launchLookup( words, m_lang, true );
} else {
Assert.failDbg();
}
break; break;
} }
} }
@ -519,15 +517,16 @@ public class DictBrowseDelegate extends DelegateBase
Serializable obj = DBUtils.getSerializableFor( m_activity, getStateKey() ); Serializable obj = DBUtils.getSerializableFor( m_activity, getStateKey() );
if ( null != obj && obj instanceof DictBrowseState ) { if ( null != obj && obj instanceof DictBrowseState ) {
m_browseState = (DictBrowseState)obj; m_browseState = (DictBrowseState)obj;
if ( null == m_browseState.m_pats ) { if ( null == m_browseState.m_pats ) { // remove if unneeded
m_browseState = null; m_browseState = null;
Assert.failDbg();
} }
} }
if ( null == m_browseState ) { if ( null == m_browseState ) {
m_browseState = new DictBrowseState(); m_browseState = new DictBrowseState();
} }
} }
Log.d( TAG, "loadBrowseState() => %s", m_browseState ); // Log.d( TAG, "loadBrowseState() => %s", m_browseState );
} }
private void storeBrowseState() private void storeBrowseState()
@ -541,11 +540,19 @@ public class DictBrowseDelegate extends DelegateBase
private void useButtonClicked( int justFixed, byte[] fixedTiles ) private void useButtonClicked( int justFixed, byte[] fixedTiles )
{ {
scrapeBrowseState(); if ( -1 == justFixed ) {
Log.d( TAG, "useButtonClicked(): m_browseState: %s", m_browseState ); // Hungarian fix: when we're called via button, clear state so we
// can know later when we have a tile pattern that it came from
// the user making a choice and we needn't offer it
// again. Otherwise if more than one of the lines is ambiguous
// (results in CHOOSE_TILES call) we loop forever.
scrapeBrowseState();
for ( PatDesc desc : m_browseState.m_pats ) {
desc.tilePat = null;
}
}
boolean pending = false; boolean pending = false;
if ( m_browseState.m_chosenMin > m_browseState.m_chosenMax ) { if ( m_browseState.m_chosenMin > m_browseState.m_chosenMax ) {
pending = true; pending = true;
makeOkOnlyBuilder( R.string.error_min_gt_max ).show(); makeOkOnlyBuilder( R.string.error_min_gt_max ).show();
@ -554,8 +561,9 @@ public class DictBrowseDelegate extends DelegateBase
PatDesc[] pats = m_browseState.m_pats; PatDesc[] pats = m_browseState.m_pats;
for ( int ii = 0; ii < pats.length && !pending; ++ii ) { for ( int ii = 0; ii < pats.length && !pending; ++ii ) {
if ( justFixed == ii ) { if ( justFixed == ii ) {
Assert.assertTrueNR( null != fixedTiles );
pats[ii].tilePat = fixedTiles; pats[ii].tilePat = fixedTiles;
} else { } else if ( null == pats[ii].tilePat ) {
String strPat = pats[ii].strPat; String strPat = pats[ii].strPat;
if ( null != strPat && 0 < strPat.length() ) { if ( null != strPat && 0 < strPat.length() ) {
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat ); byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
@ -574,8 +582,6 @@ public class DictBrowseDelegate extends DelegateBase
showDialogFragment( DlgID.CHOOSE_TILES, (Object)choices, ii ); showDialogFragment( DlgID.CHOOSE_TILES, (Object)choices, ii );
pending = true; pending = true;
} }
} else {
pats[ii].tilePat = null;
} }
} }
} }

View file

@ -25,6 +25,7 @@ import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TableRow; import android.widget.TableRow;
import android.widget.TextView;
import org.eehouse.android.xw4.jni.XwJNI.PatDesc; import org.eehouse.android.xw4.jni.XwJNI.PatDesc;
@ -73,6 +74,18 @@ public class PatTableRow extends TableRow {
return handled; return handled;
} }
// Return the label (the first column)
public String getFieldName()
{
String result = "";
TextView tv = (TextView)Utils.getChildInstanceOf( this, TextView.class );
Assert.assertTrueNR( null != tv );
if ( null != tv ) {
result = tv.getText().toString();
}
return result;
}
void setOnFocusGained( final Runnable proc ) void setOnFocusGained( final Runnable proc )
{ {
getFields(); getFields();

View file

@ -2594,7 +2594,7 @@
browser. Displayed below are the possible browser. Displayed below are the possible
spellings. Currently this can only happen with Hungarian spellings. Currently this can only happen with Hungarian
wordlists. --> wordlists. -->
<string name="pick_tiles_title">Pick a tile “spelling”</string> <string name="pick_tiles_title_fmt">Pick a tile “spelling” for “%1$s”</string>
<!-- Shown when user types a string that contains non-tiles, <!-- Shown when user types a string that contains non-tiles,
e.g. a Q alone when the langauge has only QU. First e.g. a Q alone when the langauge has only QU. First
substituted is user's string; second substitution is name of substituted is user's string; second substitution is name of

View file

@ -124,7 +124,7 @@
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:maxLines">1</item> <item name="android:maxLines">1</item>
<item name="android:maxLength">15</item> <item name="android:maxLength">15</item>
<item name="android:inputType">text</item> <item name="android:inputType">textNoSuggestions</item>
<item name="android:layout_weight">1</item> <item name="android:layout_weight">1</item>
</style> </style>