mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
move ints from res to code so exist in one place only
Debug ids were in one place, non- in another. Now they're all together.
This commit is contained in:
parent
d22ffbec3f
commit
733567c949
5 changed files with 59 additions and 71 deletions
|
@ -387,14 +387,10 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
boolean setField( String newField )
|
||||
boolean setField( int newID )
|
||||
{
|
||||
boolean changed = false;
|
||||
int newID = fieldToID( newField );
|
||||
if ( -1 == newID ) {
|
||||
Log.d( TAG, "setField(): unable to match fieldName %s",
|
||||
newField );
|
||||
} else if ( m_fieldID != newID ) {
|
||||
if ( 0 != newID && m_fieldID != newID ) {
|
||||
m_fieldID = newID;
|
||||
// return true so caller will do onContentChanged.
|
||||
// There's no other way to signal GameListItem instances
|
||||
|
@ -548,29 +544,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int fieldToID( String fieldName )
|
||||
{
|
||||
int[] ids = {
|
||||
R.string.game_summary_field_empty,
|
||||
R.string.game_summary_field_language,
|
||||
R.string.game_summary_field_opponents,
|
||||
R.string.game_summary_field_state,
|
||||
R.string.game_summary_field_rowid,
|
||||
R.string.game_summary_field_gameid,
|
||||
R.string.game_summary_field_npackets,
|
||||
R.string.title_addrs_pref,
|
||||
R.string.game_summary_field_created,
|
||||
};
|
||||
int result = ids[0]; // need a default in case set changes
|
||||
for ( int id : ids ) {
|
||||
if ( LocUtils.getString( m_activity, id ).equals( fieldName )){
|
||||
result = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // class GameListAdapter
|
||||
|
||||
private static final int[] DEBUG_ITEMS = {
|
||||
|
@ -2738,7 +2711,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
|
||||
private void updateField()
|
||||
{
|
||||
String newField = CommonPrefs.getSummaryField( m_activity );
|
||||
int newField = CommonPrefs.getSummaryFieldId( m_activity );
|
||||
if ( m_adapter.setField( newField ) ) {
|
||||
// The adapter should be able to decide whether full
|
||||
// content change is required. PENDING
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
|
||||
/*
|
||||
* Copyright 2010 - 2016 by Eric House (xwords@eehouse.org). All rights
|
||||
* Copyright 2010 - 2022 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
|
@ -27,7 +27,14 @@ import org.eehouse.android.xw4.loc.LocUtils;
|
|||
|
||||
public class XWSumListPreference extends XWListPreference {
|
||||
|
||||
private static final int[] s_ADDROWS = {
|
||||
private static int[] _s_game_summary_values = {
|
||||
R.string.game_summary_field_empty,
|
||||
R.string.game_summary_field_language,
|
||||
R.string.game_summary_field_opponents,
|
||||
R.string.game_summary_field_state,
|
||||
};
|
||||
|
||||
private static int[] _s_game_summary_values_dbg = {
|
||||
R.string.game_summary_field_npackets,
|
||||
R.string.game_summary_field_rowid,
|
||||
R.string.game_summary_field_gameid,
|
||||
|
@ -35,6 +42,30 @@ public class XWSumListPreference extends XWListPreference {
|
|||
R.string.game_summary_field_created,
|
||||
};
|
||||
|
||||
private static int[] s_game_summary_values = null;
|
||||
public static int[] getFieldIDs( Context context )
|
||||
{
|
||||
if ( null == s_game_summary_values ) {
|
||||
int len = _s_game_summary_values.length;
|
||||
boolean addDbg = BuildConfig.NON_RELEASE
|
||||
|| XWPrefs.getDebugEnabled( context );
|
||||
if ( addDbg ) {
|
||||
len += _s_game_summary_values_dbg.length;
|
||||
}
|
||||
s_game_summary_values = new int[len];
|
||||
int ii = 0;
|
||||
for ( int id : _s_game_summary_values ) {
|
||||
s_game_summary_values[ii++] = id;
|
||||
}
|
||||
if ( addDbg ) {
|
||||
for ( int id : _s_game_summary_values_dbg ) {
|
||||
s_game_summary_values[ii++] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s_game_summary_values;
|
||||
}
|
||||
|
||||
public XWSumListPreference( Context context, AttributeSet attrs )
|
||||
{
|
||||
super( context, attrs );
|
||||
|
@ -46,36 +77,13 @@ public class XWSumListPreference extends XWListPreference {
|
|||
{
|
||||
super.onAttached();
|
||||
|
||||
CharSequence[] entries = getEntries();
|
||||
CharSequence[] newEntries = LocUtils.xlateStrings( m_context, entries );
|
||||
if ( ! newEntries.equals( entries ) ) {
|
||||
setEntries( newEntries );
|
||||
setEntryValues( newEntries );
|
||||
int[] ids = getFieldIDs( m_context );
|
||||
CharSequence[] rows = new String[ids.length];
|
||||
for ( int ii = 0; ii < ids.length; ++ii ) {
|
||||
rows[ii] = LocUtils.getString( m_context, ids[ii] );
|
||||
}
|
||||
|
||||
if ( BuildConfig.DEBUG || XWPrefs.getDebugEnabled( m_context ) ) {
|
||||
entries = getEntries();
|
||||
CharSequence lastRow = entries[entries.length - 1];
|
||||
boolean done = false;
|
||||
|
||||
String[] addRows = new String[s_ADDROWS.length];
|
||||
for ( int ii = 0; !done && ii < s_ADDROWS.length; ++ii ) {
|
||||
String addRow = LocUtils.getString( m_context, s_ADDROWS[ii] );
|
||||
done = lastRow.equals( addRow );
|
||||
addRows[ii] = addRow;
|
||||
}
|
||||
|
||||
if ( !done ) {
|
||||
newEntries = new CharSequence[entries.length + addRows.length];
|
||||
System.arraycopy( entries, 0, newEntries, 0,
|
||||
entries.length );
|
||||
System.arraycopy( addRows, 0, newEntries, entries.length,
|
||||
addRows.length );
|
||||
setEntries( newEntries );
|
||||
|
||||
setEntryValues( newEntries );
|
||||
}
|
||||
}
|
||||
setEntries( rows );
|
||||
setEntryValues( rows );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
|
||||
/*
|
||||
* Copyright 2009 - 2011 by Eric House (xwords@eehouse.org). All
|
||||
* Copyright 2009 - 2022 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -35,6 +35,7 @@ import org.eehouse.android.xw4.NetUtils;
|
|||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.Utils;
|
||||
import org.eehouse.android.xw4.XWPrefs;
|
||||
import org.eehouse.android.xw4.XWSumListPreference;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class CommonPrefs extends XWPrefs {
|
||||
|
@ -339,6 +340,20 @@ public class CommonPrefs extends XWPrefs {
|
|||
return getPrefsString( context, R.string.key_summary_field );
|
||||
}
|
||||
|
||||
public static int getSummaryFieldId( Context context )
|
||||
{
|
||||
int result = 0;
|
||||
String str = getSummaryField( context );
|
||||
int[] ids = XWSumListPreference.getFieldIDs( context );
|
||||
for ( int id : ids ) {
|
||||
if ( LocUtils.getString( context, id ).equals( str )){
|
||||
result = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public enum ColorTheme {
|
||||
LIGHT(R.array.color_ids_light),
|
||||
DARK(R.array.color_ids_dark);
|
||||
|
|
|
@ -313,13 +313,6 @@
|
|||
<item>http://www.google.com/search?nl=%1$s\u0026q=%2$s</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="game_summary_values">
|
||||
<item>@string/game_summary_field_empty</item>
|
||||
<item>@string/game_summary_field_language</item>
|
||||
<item>@string/game_summary_field_opponents</item>
|
||||
<item>@string/game_summary_field_state</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="confirm_sms_reasons">
|
||||
<item>@string/confirm_sms_leave</item>
|
||||
<item>@string/confirm_sms_unlimited</item>
|
||||
|
|
|
@ -13,11 +13,10 @@
|
|||
android:defaultValue="30"
|
||||
/>
|
||||
|
||||
<!-- Fields are listed/added in XWSumListPreference.java -->
|
||||
<org.eehouse.android.xw4.XWSumListPreference
|
||||
android:key="@string/key_summary_field"
|
||||
android:title="@string/summary_field"
|
||||
android:entries="@array/game_summary_values"
|
||||
android:entryValues="@array/game_summary_values"
|
||||
android:defaultValue="@string/game_summary_field_opponents"
|
||||
/>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue