Android TV: Add row listing all games

This commit is contained in:
sigmabeta 2015-07-20 20:15:26 -04:00 committed by sigmabeta
parent 7c14996e3e
commit 0b1212b77d
2 changed files with 94 additions and 52 deletions

View File

@ -78,22 +78,57 @@ public final class TvMainActivity extends Activity
{
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
// For each row
for (int platformIndex = 0; platformIndex <= Game.PLATFORM_WII_WARE; ++platformIndex)
// For each platform
for (int platformIndex = 0; platformIndex <= Game.PLATFORM_ALL; ++platformIndex)
{
ListRow row = buildGamesRow(platformIndex);
// Add row to the adapter only if it is not empty.
if (row != null)
{
mRowsAdapter.add(row);
}
}
mBrowseFragment.setAdapter(mRowsAdapter);
}
private ListRow buildGamesRow(int platform)
{
// Create an adapter for this row.
CursorObjectAdapter row = new CursorObjectAdapter(new GamePresenter(platformIndex));
CursorObjectAdapter row = new CursorObjectAdapter(new GamePresenter(platform));
// Add items to the adapter.
Cursor games = getContentResolver().query(
Cursor games;
if (platform == Game.PLATFORM_ALL)
{
// Get all games.
games = getContentResolver().query(
GameProvider.URI_GAME, // URI of table to query
null, // Return all columns
null, // Return all games
null, // Return all games
GameDatabase.KEY_GAME_TITLE + " asc" // Sort by game name, ascending order
);
}
else
{
// Get games for this particular platform.
games = getContentResolver().query(
GameProvider.URI_GAME, // URI of table to query
null, // Return all columns
GameDatabase.KEY_GAME_PLATFORM + " = ?", // Select by platform
new String[]{Integer.toString(platformIndex)}, // Platform id
new String[]{Integer.toString(platform)}, // Platform id
GameDatabase.KEY_GAME_TITLE + " asc" // Sort by game name, ascending order
);
}
row.swapCursor(games);
// If cursor is empty, don't return a Row.
if (!games.moveToFirst())
{
return null;
}
row.changeCursor(games);
row.setMapper(new CursorMapper()
{
@Override
@ -110,7 +145,7 @@ public final class TvMainActivity extends Activity
});
String headerName;
switch (platformIndex)
switch (platform)
{
case Game.PLATFORM_GC:
headerName = "GameCube Games";
@ -124,18 +159,24 @@ public final class TvMainActivity extends Activity
headerName = "WiiWare";
break;
case Game.PLATFORM_ALL:
headerName = "All Games";
break;
default:
headerName = "Error";
break;
}
// Create a header for this row.
HeaderItem header = new HeaderItem(platformIndex, headerName);
HeaderItem header = new HeaderItem(platform, headerName);
// Create the row, passing it the filled adapter and the header, and give it to the master adapter.
mRowsAdapter.add(new ListRow(header, row));
return new ListRow(header, row);
}
mBrowseFragment.setAdapter(mRowsAdapter);
}
/*private ListRow buildSettingsRow()
{
}*/
}

View File

@ -8,6 +8,7 @@ public final class Game
public static final int PLATFORM_GC = 0;
public static final int PLATFORM_WII = 1;
public static final int PLATFORM_WII_WARE = 2;
public static final int PLATFORM_ALL = 3;
// Copied from IVolume::ECountry. Update these if that is ever modified.
public static final int COUNTRY_EUROPE = 0;