diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java
index dbdbe4626..27f54c1fb 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java
@@ -23,6 +23,7 @@ package org.eehouse.android.xw4;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothDevice;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
@@ -53,6 +54,8 @@ public class BTInviteDelegate extends InviteDelegate {
private static final boolean ENABLE_FAKER = false;
private static final int SCAN_SECONDS = 5;
+ private static Persisted sPersisted;
+
private Activity m_activity;
private ProgressBar mProgressBar;
private Handler m_handler = new Handler();
@@ -107,7 +110,6 @@ public class BTInviteDelegate extends InviteDelegate {
});
}
}
- private Persisted mPersisted;
public static void launchForResult( Activity activity, int nMissing,
SentInvitesInfo info,
@@ -142,11 +144,11 @@ public class BTInviteDelegate extends InviteDelegate {
addButtonBar( R.layout.bt_buttons, BUTTONIDS );
- load();
- if ( mPersisted.empty() ) {
+ load( m_activity );
+ if ( sPersisted.empty() ) {
scan();
} else {
- updateListAdapter( mPersisted.pairs );
+ updateListAdapter( sPersisted.pairs );
}
}
@@ -180,7 +182,7 @@ public class BTInviteDelegate extends InviteDelegate {
public void run() {
hideProgress();
- if ( mPersisted.empty() || 0 == mNDevsThisScan ) {
+ if ( sPersisted.empty() || 0 == mNDevsThisScan ) {
makeNotAgainBuilder( R.string.not_again_emptybtscan,
R.string.key_notagain_emptybtscan )
.show();
@@ -207,9 +209,9 @@ public class BTInviteDelegate extends InviteDelegate {
String devName = ((TwoStringPair)data).str2;
String msg = null;
- if ( mPersisted.stamps.containsKey( devName ) ) {
+ if ( sPersisted.stamps.containsKey( devName ) ) {
CharSequence elapsed = DateUtils
- .getRelativeTimeSpanString( mPersisted.stamps.get( devName ),
+ .getRelativeTimeSpanString( sPersisted.stamps.get( devName ),
System.currentTimeMillis(),
DateUtils.SECOND_IN_MILLIS );
msg = getString( R.string.bt_scan_age_fmt, elapsed );
@@ -232,7 +234,7 @@ public class BTInviteDelegate extends InviteDelegate {
private void scan()
{
if ( ENABLE_FAKER && Utils.nextRandomInt() % 5 == 0 ) {
- mPersisted.add( "00:00:00:00:00:00", "Do Not Invite Me" );
+ sPersisted.add( "00:00:00:00:00:00", "Do Not Invite Me" );
}
int count = BTService.getPairedCount( m_activity );
@@ -253,10 +255,10 @@ public class BTInviteDelegate extends InviteDelegate {
DbgUtils.assertOnUIThread();
++mNDevsThisScan;
- mPersisted.add( dev.getAddress(), dev.getName() );
- store();
+ sPersisted.add( dev.getAddress(), dev.getName() );
+ store( m_activity );
- updateListAdapter( mPersisted.pairs );
+ updateListAdapter( sPersisted.pairs );
tryEnable();
}
@@ -298,23 +300,25 @@ public class BTInviteDelegate extends InviteDelegate {
}, 1000 * inSeconds );
}
- private void load()
+ private synchronized static void load( Context context )
{
- try {
- String str64 = DBUtils.getStringFor( m_activity, KEY_PERSIST, null );
- mPersisted = (Persisted)Utils.string64ToSerializable( str64 );
- } catch ( Exception ex ) {} // NPE, de-serialization problems, etc.
+ if ( null == sPersisted ) {
+ try {
+ String str64 = DBUtils.getStringFor( context, KEY_PERSIST, null );
+ sPersisted = (Persisted)Utils.string64ToSerializable( str64 );
+ } catch ( Exception ex ) {} // NPE, de-serialization problems, etc.
- if ( null == mPersisted ) {
- mPersisted = new Persisted();
+ if ( null == sPersisted ) {
+ sPersisted = new Persisted();
+ }
}
}
- private void store()
+ private synchronized static void store( Context context )
{
- String str64 = mPersisted == null
- ? "" : Utils.serializableToString64( mPersisted );
- DBUtils.setStringFor( m_activity, KEY_PERSIST, str64 );
+ String str64 = sPersisted == null
+ ? "" : Utils.serializableToString64( sPersisted );
+ DBUtils.setStringFor( context, KEY_PERSIST, str64 );
}
// DlgDelegate.DlgClickNotify interface
@@ -327,11 +331,11 @@ public class BTInviteDelegate extends InviteDelegate {
BTService.openBTSettings( m_activity );
break;
case CLEAR_ACTION:
- mPersisted.remove( getChecked() );
- store();
+ sPersisted.remove( getChecked() );
+ store( m_activity );
clearChecked();
- updateListAdapter( mPersisted.pairs );
+ updateListAdapter( sPersisted.pairs );
tryEnable();
break;
default:
@@ -339,4 +343,11 @@ public class BTInviteDelegate extends InviteDelegate {
}
return handled;
}
+
+ public static void onHeardFromDev( Context context, BluetoothDevice dev )
+ {
+ load( context );
+ sPersisted.add( dev.getAddress(), dev.getName() );
+ store( context );
+ }
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java
index f438d8d2b..dc898fe66 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java
@@ -576,6 +576,8 @@ public class BTService extends XWJIService {
byte proto = inStream.readByte();
if ( proto == BT_PROTO_BATCH || proto == BT_PROTO_JSONS ) {
resetSenderFor( socket ); // still looks good here?
+ BTInviteDelegate.onHeardFromDev( XWApp.getContext(),
+ socket.getRemoteDevice() );
new PacketParser( proto )
.dispatchAll( inStream, socket, BTListenerThread.this );
diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml
index 9c91cfa3c..98e02f407 100644
--- a/xwords4/android/app/src/main/res/values/strings.xml
+++ b/xwords4/android/app/src/main/res/values/strings.xml
@@ -2453,8 +2453,9 @@
within Bluetooth range and that CrossWords is installed on
it.
-
- Last scan response: %1$s
+
+ Last heard from: %1$s
Default language