From 754d7b06ef28aeaab753451b1fc46fd24b6c8a05 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 4 Mar 2011 07:22:08 -0800 Subject: [PATCH] add boolean 'wait' to getSummary() allowing it to return null if it can't get a read lock. Fix GameListAdapter to handle that null. --- .../XWords4/src/org/eehouse/android/xw4/DBUtils.java | 11 ++++++++--- .../src/org/eehouse/android/xw4/GameListAdapter.java | 2 +- .../src/org/eehouse/android/xw4/GamesList.java | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) 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 7788ce29a..9307eb560 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -64,18 +64,23 @@ public class DBUtils { boolean sourceLocal; } - public static GameSummary getSummary( Context context, String file ) + public static GameSummary getSummary( Context context, String file, + boolean wait ) { GameSummary result = null; GameUtils.GameLock lock = new GameUtils.GameLock( file, false ); - if ( lock.tryLock() ) { + if ( wait ) { + result = getSummary( context, lock.lock() ); + lock.unlock(); + } else if ( lock.tryLock() ) { result = getSummary( context, lock ); lock.unlock(); } return result; } - public static GameSummary getSummary( Context context, GameUtils.GameLock lock ) + public static GameSummary getSummary( Context context, + GameUtils.GameLock lock ) { initDB( context ); GameSummary summary = null; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java index 0f1a1895b..82a361c17 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java @@ -76,7 +76,7 @@ public class GameListAdapter extends XWListAdapter { // If we can't read the summary right now we still need to // return a view but shouldn't cache it - GameSummary summary = DBUtils.getSummary( m_context, path ); + GameSummary summary = DBUtils.getSummary( m_context, path, false ); if ( null != summary ) { TextView view; 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 2e5677c58..5ad02b410 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -364,7 +364,7 @@ public class GamesList extends XWListActivity // We need a way to let the user get back to the basic-config // dialog in case it was dismissed. That way it to check for // an empty room name. - GameSummary summary = DBUtils.getSummary( this, path ); + GameSummary summary = DBUtils.getSummary( this, path, true ); if ( summary.conType == CommsAddrRec.CommsConnType.COMMS_CONN_RELAY && summary.roomName.length() == 0 ) { // If it's unconfigured and of the type RelayGameActivity @@ -420,7 +420,7 @@ public class GamesList extends XWListActivity break; case R.id.list_item_copy: - GameSummary summary = DBUtils.getSummary( this, path ); + GameSummary summary = DBUtils.getSummary( this, path, true ); if ( summary.inNetworkGame() ) { showOKOnlyDialog( R.string.no_copy_network ); } else {