diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 6c92974fc..c6347dc4d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -35,6 +35,12 @@ import org.eehouse.android.xw4.jni.*; public class DBUtils { + public static interface DBChangeListener { + public void pathSaved( String path ); + } + private static DBChangeListener[] s_listeners = + new DBChangeListener[]{ null }; + private static SQLiteOpenHelper s_dbHelper = null; public static class Obit { @@ -213,6 +219,7 @@ public class DBUtils { values, selection, null ); Assert.assertTrue( result >= 0 ); } + notifyListeners( path ); db.close(); } } // saveSummary @@ -250,6 +257,7 @@ public class DBUtils { values, selection, null ); Assert.assertTrue( result == 1 ); db.close(); + notifyListeners( path ); } } @@ -433,6 +441,7 @@ public class DBUtils { Assert.assertTrue( row >= 0 ); } db.close(); + notifyListeners( path ); } } @@ -559,6 +568,14 @@ public class DBUtils { saveChatHistory( context, path, null ); } + public static void setDBChangeListener( DBChangeListener listener ) + { + synchronized( s_listeners ) { + Assert.assertTrue( listener != s_listeners[0] ); + s_listeners[0] = listener; + } + } + private static void saveChatHistory( Context context, String path, String history ) { @@ -615,4 +632,13 @@ public class DBUtils { } } + private static void notifyListeners( String path ) + { + synchronized( s_listeners ) { + if ( null != s_listeners[0] ) { + s_listeners[0].pathSaved( path ); + } + } + } + } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 421f4ccfa..38c679916 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -50,7 +50,8 @@ import org.eehouse.android.xw4.jni.*; public class GamesList extends XWListActivity implements DispatchNotify.HandleRelaysIface, - RefreshMsgsTask.RefreshMsgsIface { + RefreshMsgsTask.RefreshMsgsIface, + DBUtils.DBChangeListener { private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1; private static final int WARN_NODICT_SUBST = WARN_NODICT + 1; @@ -236,6 +237,7 @@ public class GamesList extends XWListActivity { super.onStart(); DispatchNotify.SetRelayIDsHandler( this ); + DBUtils.setDBChangeListener( this ); // TelephonyManager mgr = // (TelephonyManager)getSystemService( Context.TELEPHONY_SERVICE ); @@ -251,7 +253,7 @@ public class GamesList extends XWListActivity // (TelephonyManager)getSystemService( Context.TELEPHONY_SERVICE ); // mgr.listen( m_phoneStateListener, PhoneStateListener.LISTEN_NONE ); // m_phoneStateListener = null; - + DBUtils.setDBChangeListener( null ); DispatchNotify.SetRelayIDsHandler( null ); super.onStop(); @@ -273,6 +275,17 @@ public class GamesList extends XWListActivity HandleRelaysIDs( relayIDs ); } + // DBUtils.DBChangeListener interface + public void pathSaved( final String path ) + { + m_handler.post( new Runnable() { + public void run() { + m_adapter.inval( path ); + onContentChanged(); + } + } ); + } + @Override public void onWindowFocusChanged( boolean hasFocus ) {