mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
replace array[1] with HashSet to support more than one db change listener
This commit is contained in:
parent
c31e964ce4
commit
b57b6b1b31
1 changed files with 17 additions and 6 deletions
|
@ -28,6 +28,8 @@ import java.util.StringTokenizer;
|
|||
import android.content.ContentValues;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
|
@ -38,8 +40,8 @@ public class DBUtils {
|
|||
public static interface DBChangeListener {
|
||||
public void pathSaved( String path );
|
||||
}
|
||||
private static DBChangeListener[] s_listeners =
|
||||
new DBChangeListener[]{ null };
|
||||
private static HashSet<DBChangeListener> s_listeners =
|
||||
new HashSet<DBChangeListener>();
|
||||
|
||||
private static SQLiteOpenHelper s_dbHelper = null;
|
||||
|
||||
|
@ -569,8 +571,16 @@ public class DBUtils {
|
|||
public static void setDBChangeListener( DBChangeListener listener )
|
||||
{
|
||||
synchronized( s_listeners ) {
|
||||
Assert.assertTrue( listener != s_listeners[0] );
|
||||
s_listeners[0] = listener;
|
||||
Assert.assertNotNull( listener );
|
||||
s_listeners.add( listener );
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearDBChangeListener( DBChangeListener listener )
|
||||
{
|
||||
synchronized( s_listeners ) {
|
||||
Assert.assertTrue( s_listeners.contains( listener ) );
|
||||
s_listeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -633,8 +643,9 @@ public class DBUtils {
|
|||
private static void notifyListeners( String path )
|
||||
{
|
||||
synchronized( s_listeners ) {
|
||||
if ( null != s_listeners[0] ) {
|
||||
s_listeners[0].pathSaved( path );
|
||||
Iterator<DBChangeListener> iter = s_listeners.iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
iter.next().pathSaved( path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue