save sms-invite contacts across uses of the dialog

This commit is contained in:
Eric House 2012-03-21 06:54:25 -07:00
parent 84496b3012
commit ba44f1355c
3 changed files with 56 additions and 5 deletions

View file

@ -61,6 +61,8 @@
<string name="key_closed_langs">key_closed_langs</string> <string name="key_closed_langs">key_closed_langs</string>
<string name="key_bt_names">key_bt_names</string> <string name="key_bt_names">key_bt_names</string>
<string name="key_bt_addrs">key_bt_addrs</string> <string name="key_bt_addrs">key_bt_addrs</string>
<string name="key_nbs_names">key_nbs_names</string>
<string name="key_nbs_phones">key_nbs_phones</string>
<string name="key_notagain_sync">key_notagain_sync</string> <string name="key_notagain_sync">key_notagain_sync</string>
<string name="key_notagain_chat">key_notagain_chat</string> <string name="key_notagain_chat">key_notagain_chat</string>

View file

@ -35,9 +35,10 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.Assert; import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CommonPrefs;
public class NBSInviteActivity extends InviteActivity public class NBSInviteActivity extends InviteActivity
implements View.OnClickListener { implements View.OnClickListener {
public static final String DEVS = "DEVS"; 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_invite, R.id.button_add,
R.id.button_clear, R.id.invite_desc, R.id.button_clear, R.id.invite_desc,
R.string.invite_nbs_descf ); R.string.invite_nbs_descf );
getSavedState();
m_names = new ArrayList<String>(); rebuildList();
m_phones = new ArrayList<String>();
} }
@Override @Override
@ -93,6 +93,7 @@ public class NBSInviteActivity extends InviteActivity
m_names.remove( ii ); m_names.remove( ii );
} }
} }
saveState();
rebuildList(); rebuildList();
// int index = m_phones.size(); // int index = m_phones.size();
// while ( index-- > 0 ) { // while ( index-- > 0 ) {
@ -151,6 +152,7 @@ public class NBSInviteActivity extends InviteActivity
} }
} }
if ( len_before != m_phones.size() ) { if ( len_before != m_phones.size() ) {
saveState();
rebuildList(); rebuildList();
} }
} }
@ -165,6 +167,18 @@ public class NBSInviteActivity extends InviteActivity
tryEnable(); 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 class NBSPhonesAdapter extends XWListAdapter {
private NBSListItem[] m_items; private NBSListItem[] m_items;

View file

@ -26,6 +26,7 @@ import android.content.res.Resources;
import android.graphics.Paint; import android.graphics.Paint;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.ArrayList;
import junit.framework.Assert; import junit.framework.Assert;
import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.R;
@ -348,11 +349,33 @@ public class CommonPrefs {
setPrefsStringArray( context, R.string.key_bt_names, names ); setPrefsStringArray( context, R.string.key_bt_names, names );
} }
public static void setNBSNames( Context context, ArrayList<String> names )
{
String[] array = names.toArray( new String[names.size()] );
setPrefsStringArray( context, R.string.key_nbs_names, array );
}
public static void setNBSPhones( Context context, ArrayList<String> names )
{
String[] array = names.toArray( new String[names.size()] );
setPrefsStringArray( context, R.string.key_nbs_phones, array );
}
public static String[] getBTNames( Context context ) public static String[] getBTNames( Context context )
{ {
return getPrefsStringArray( context, R.string.key_bt_names ); return getPrefsStringArray( context, R.string.key_bt_names );
} }
public static ArrayList<String> getNBSNames( Context context )
{
return getPrefsStringArrayList( context, R.string.key_nbs_names );
}
public static ArrayList<String> getNBSPhones( Context context )
{
return getPrefsStringArrayList( context, R.string.key_nbs_phones );
}
public static void setBTAddresses( Context context, String[] addrs ) public static void setBTAddresses( Context context, String[] addrs )
{ {
setPrefsStringArray( context, R.string.key_bt_addrs, addrs ); setPrefsStringArray( context, R.string.key_bt_addrs, addrs );
@ -402,7 +425,6 @@ public class CommonPrefs {
editor.commit(); editor.commit();
} }
private static String[] getPrefsStringArray( Context context, int keyID ) private static String[] getPrefsStringArray( Context context, int keyID )
{ {
String asStr = getString( context, keyID ); String asStr = getString( context, keyID );
@ -410,6 +432,19 @@ public class CommonPrefs {
return result; return result;
} }
private static ArrayList<String> getPrefsStringArrayList( Context context,
int keyID )
{
ArrayList<String> list = new ArrayList<String>();
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, private static void setPrefsStringArray( Context context, int keyID,
String[] value ) String[] value )
{ {