diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index 45b1beeae..d5b161fd7 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -61,6 +61,8 @@ key_closed_langs key_bt_names key_bt_addrs + key_nbs_names + key_nbs_phones key_notagain_sync key_notagain_chat diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSInviteActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSInviteActivity.java index 82a4459f8..44543fbec 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSInviteActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSInviteActivity.java @@ -35,9 +35,10 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import java.util.ArrayList; - import junit.framework.Assert; +import org.eehouse.android.xw4.jni.CommonPrefs; + public class NBSInviteActivity extends InviteActivity implements View.OnClickListener { public static final String DEVS = "DEVS"; @@ -56,9 +57,8 @@ public class NBSInviteActivity extends InviteActivity R.id.button_invite, R.id.button_add, R.id.button_clear, R.id.invite_desc, R.string.invite_nbs_descf ); - - m_names = new ArrayList(); - m_phones = new ArrayList(); + getSavedState(); + rebuildList(); } @Override @@ -93,6 +93,7 @@ public class NBSInviteActivity extends InviteActivity m_names.remove( ii ); } } + saveState(); rebuildList(); // int index = m_phones.size(); // while ( index-- > 0 ) { @@ -151,6 +152,7 @@ public class NBSInviteActivity extends InviteActivity } } if ( len_before != m_phones.size() ) { + saveState(); rebuildList(); } } @@ -165,6 +167,18 @@ public class NBSInviteActivity extends InviteActivity tryEnable(); } + private void getSavedState() + { + m_names = CommonPrefs.getNBSNames( this ); + m_phones = CommonPrefs.getNBSPhones( this ); + } + + private void saveState() + { + CommonPrefs.setNBSNames( this, m_names ); + CommonPrefs.setNBSPhones( this, m_phones ); + } + private class NBSPhonesAdapter extends XWListAdapter { private NBSListItem[] m_items; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index 5b5f9e3d4..a2e497860 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -26,6 +26,7 @@ import android.content.res.Resources; import android.graphics.Paint; import android.preference.PreferenceManager; import android.text.TextUtils; +import java.util.ArrayList; import junit.framework.Assert; import org.eehouse.android.xw4.R; @@ -348,11 +349,33 @@ public class CommonPrefs { setPrefsStringArray( context, R.string.key_bt_names, names ); } + public static void setNBSNames( Context context, ArrayList names ) + { + String[] array = names.toArray( new String[names.size()] ); + setPrefsStringArray( context, R.string.key_nbs_names, array ); + } + + public static void setNBSPhones( Context context, ArrayList names ) + { + String[] array = names.toArray( new String[names.size()] ); + setPrefsStringArray( context, R.string.key_nbs_phones, array ); + } + public static String[] getBTNames( Context context ) { return getPrefsStringArray( context, R.string.key_bt_names ); } + public static ArrayList getNBSNames( Context context ) + { + return getPrefsStringArrayList( context, R.string.key_nbs_names ); + } + + public static ArrayList getNBSPhones( Context context ) + { + return getPrefsStringArrayList( context, R.string.key_nbs_phones ); + } + public static void setBTAddresses( Context context, String[] addrs ) { setPrefsStringArray( context, R.string.key_bt_addrs, addrs ); @@ -402,7 +425,6 @@ public class CommonPrefs { editor.commit(); } - private static String[] getPrefsStringArray( Context context, int keyID ) { String asStr = getString( context, keyID ); @@ -410,6 +432,19 @@ public class CommonPrefs { return result; } + private static ArrayList getPrefsStringArrayList( Context context, + int keyID ) + { + ArrayList list = new ArrayList(); + String[] strs = getPrefsStringArray( context, keyID ); + if ( null != strs ) { + for ( int ii = 0; ii < strs.length; ++ii ) { + list.add( strs[ii] ); + } + } + return list; + } + private static void setPrefsStringArray( Context context, int keyID, String[] value ) {