Android: Split up GameFileCacheService.onHandleIntent
This commit is contained in:
parent
7292ac0ce5
commit
31bfbca923
|
@ -132,8 +132,9 @@ public final class GameFileCacheService extends IntentService
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously loads the game file cache from disk without checking
|
* Asynchronously loads the game file cache from disk, without checking
|
||||||
* which games are present on the file system.
|
* if the games are still present in the user's configured folders.
|
||||||
|
* If this has already been called, calling it again has no effect.
|
||||||
*/
|
*/
|
||||||
public static void startLoad(Context context)
|
public static void startLoad(Context context)
|
||||||
{
|
{
|
||||||
|
@ -182,8 +183,32 @@ public final class GameFileCacheService extends IntentService
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent)
|
protected void onHandleIntent(Intent intent)
|
||||||
{
|
{
|
||||||
// Load the game list cache if it isn't already loaded, otherwise do nothing
|
if (ACTION_LOAD.equals(intent.getAction()))
|
||||||
if (ACTION_LOAD.equals(intent.getAction()) && gameFileCache == null)
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ACTION_RESCAN.equals(intent.getAction()))
|
||||||
|
{
|
||||||
|
rescan();
|
||||||
|
unhandledRescanIntents.decrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
int intentsLeft = unhandledIntents.decrementAndGet();
|
||||||
|
if (intentsLeft == 0)
|
||||||
|
{
|
||||||
|
sendBroadcast(DONE_LOADING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the game file cache from disk, without checking if the
|
||||||
|
* games are still present in the user's configured folders.
|
||||||
|
* If this has already been called, calling it again has no effect.
|
||||||
|
*/
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
if (gameFileCache == null)
|
||||||
{
|
{
|
||||||
GameFileCache temp = new GameFileCache();
|
GameFileCache temp = new GameFileCache();
|
||||||
synchronized (temp)
|
synchronized (temp)
|
||||||
|
@ -197,9 +222,14 @@ public final class GameFileCacheService extends IntentService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rescan the file system and update the game list cache with the results
|
/**
|
||||||
if (ACTION_RESCAN.equals(intent.getAction()))
|
* Scans for games in the user's configured folders,
|
||||||
|
* updating the game file cache with the results.
|
||||||
|
* If load hasn't been called before this, this has no effect.
|
||||||
|
*/
|
||||||
|
private void rescan()
|
||||||
{
|
{
|
||||||
if (gameFileCache != null)
|
if (gameFileCache != null)
|
||||||
{
|
{
|
||||||
|
@ -228,15 +258,6 @@ public final class GameFileCacheService extends IntentService
|
||||||
gameFileCache.save();
|
gameFileCache.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unhandledRescanIntents.decrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
int intentsLeft = unhandledIntents.decrementAndGet();
|
|
||||||
if (intentsLeft == 0)
|
|
||||||
{
|
|
||||||
sendBroadcast(DONE_LOADING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGameFileArray()
|
private void updateGameFileArray()
|
||||||
|
|
Loading…
Reference in New Issue