From 2d740147fecb4ff4d2296b27fa48886374ddf232 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Thu, 21 Sep 2017 21:48:48 -0700 Subject: [PATCH 1/4] remove dupe log tag --- .../main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java index aba310363e..98a751a3ca 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java @@ -264,7 +264,7 @@ public final class GameDatabase extends SQLiteOpenHelper @Override public void call(Subscriber subscriber) { - Log.info("[GameDatabase] [GameDatabase] Reading games list..."); + Log.info("[GameDatabase] Reading games list..."); String whereClause = null; String[] whereArgs = null; From 487591c76040f3599b37b667a7b181318aadda61 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Sun, 24 Sep 2017 16:12:21 -0700 Subject: [PATCH 2/4] Change from using tags in ImageCardView to setting a per-platform background. This allows us to use a real ImageCardView instead of extending the class. --- .../dolphinemu/adapters/GameRowPresenter.java | 53 ++++++------------- .../viewholders/TvGameViewHolder.java | 2 - .../drawable/tv_card_background_gamecube.xml | 8 +++ .../res/drawable/tv_card_background_wii.xml | 8 +++ .../drawable/tv_card_background_wiiware.xml | 8 +++ 5 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 Source/Android/app/src/main/res/drawable/tv_card_background_gamecube.xml create mode 100644 Source/Android/app/src/main/res/drawable/tv_card_background_wii.xml create mode 100644 Source/Android/app/src/main/res/drawable/tv_card_background_wiiware.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java index 2cfc5545af..cd10e4a4ae 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java @@ -1,7 +1,10 @@ package org.dolphinemu.dolphinemu.adapters; +import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.v17.leanback.widget.ImageCardView; import android.support.v17.leanback.widget.Presenter; +import android.support.v4.content.ContextCompat; import android.view.ViewGroup; import android.widget.ImageView; @@ -16,18 +19,11 @@ import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder; */ public final class GameRowPresenter extends Presenter { + @Override public ViewHolder onCreateViewHolder(ViewGroup parent) { // Create a new view. - ImageCardView gameCard = new ImageCardView(parent.getContext()) - { - @Override - public void setSelected(boolean selected) - { - setCardBackground(this, selected); - super.setSelected(selected); - } - }; + ImageCardView gameCard = new ImageCardView(parent.getContext()); gameCard.setMainImageAdjustViewBounds(true); gameCard.setMainImageDimensions(480, 320); @@ -36,12 +32,11 @@ public final class GameRowPresenter extends Presenter gameCard.setFocusable(true); gameCard.setFocusableInTouchMode(true); - setCardBackground(gameCard, false); - // Use that view to create a ViewHolder. return new TvGameViewHolder(gameCard); } + @Override public void onBindViewHolder(ViewHolder viewHolder, Object item) { TvGameViewHolder holder = (TvGameViewHolder) viewHolder; @@ -64,45 +59,29 @@ public final class GameRowPresenter extends Presenter holder.company = game.getCompany(); holder.screenshotPath = game.getScreenshotPath(); + // Set the platform-dependent background color of the card + int backgroundId; switch (game.getPlatform()) { case Game.PLATFORM_GC: - holder.cardParent.setTag(R.color.dolphin_accent_gamecube); + backgroundId = R.drawable.tv_card_background_gamecube; break; - case Game.PLATFORM_WII: - holder.cardParent.setTag(R.color.dolphin_accent_wii); + backgroundId = R.drawable.tv_card_background_wii; break; - case Game.PLATFORM_WII_WARE: - holder.cardParent.setTag(R.color.dolphin_accent_wiiware); - break; - - default: - holder.cardParent.setTag(android.R.color.holo_red_dark); + default: // This shouldn't happen, but set the default to WiiWare colors. + backgroundId = R.drawable.tv_card_background_wiiware; break; } + Context context = holder.cardParent.getContext(); + Drawable background = ContextCompat.getDrawable(context, backgroundId); + holder.cardParent.setInfoAreaBackground(background); } + @Override public void onUnbindViewHolder(ViewHolder viewHolder) { // no op } - - public void setCardBackground(ImageCardView view, boolean selected) - { - int backgroundColor; - - if (selected) - { - // TODO: 7/20/15 Try using view tag to set color - backgroundColor = (int) view.getTag(); - } - else - { - backgroundColor = R.color.tv_card_unselected; - } - - view.setInfoAreaBackgroundColor(view.getResources().getColor(backgroundColor)); - } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/TvGameViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/TvGameViewHolder.java index d27a671c2f..dbd018be78 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/TvGameViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/TvGameViewHolder.java @@ -25,8 +25,6 @@ public final class TvGameViewHolder extends Presenter.ViewHolder public String company; public String screenshotPath; - public int backgroundColor; - public TvGameViewHolder(View itemView) { super(itemView); diff --git a/Source/Android/app/src/main/res/drawable/tv_card_background_gamecube.xml b/Source/Android/app/src/main/res/drawable/tv_card_background_gamecube.xml new file mode 100644 index 0000000000..341cf5535f --- /dev/null +++ b/Source/Android/app/src/main/res/drawable/tv_card_background_gamecube.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/Source/Android/app/src/main/res/drawable/tv_card_background_wii.xml b/Source/Android/app/src/main/res/drawable/tv_card_background_wii.xml new file mode 100644 index 0000000000..19c69512a7 --- /dev/null +++ b/Source/Android/app/src/main/res/drawable/tv_card_background_wii.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/Source/Android/app/src/main/res/drawable/tv_card_background_wiiware.xml b/Source/Android/app/src/main/res/drawable/tv_card_background_wiiware.xml new file mode 100644 index 0000000000..cfff5fee45 --- /dev/null +++ b/Source/Android/app/src/main/res/drawable/tv_card_background_wiiware.xml @@ -0,0 +1,8 @@ + + + + + From cc77a4963f51ec6054e99473643a79df502801b3 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Mon, 25 Sep 2017 09:32:25 -0700 Subject: [PATCH 3/4] Convert platform ints to a proper enum Platform. This is good practice (see Effective Java chapter 6), and adds compile-time checks. --- .../activities/EmulationActivity.java | 3 +- .../dolphinemu/adapters/GameRowPresenter.java | 6 +-- .../adapters/PlatformPagerAdapter.java | 3 +- .../org/dolphinemu/dolphinemu/model/Game.java | 19 ++++---- .../dolphinemu/model/GameDatabase.java | 19 +++----- .../dolphinemu/ui/main/MainActivity.java | 12 +++-- .../dolphinemu/ui/main/MainPresenter.java | 8 ++-- .../dolphinemu/ui/main/MainView.java | 6 ++- .../dolphinemu/ui/main/TvMainActivity.java | 38 ++++----------- .../dolphinemu/ui/platform/Platform.java | 48 +++++++++++++++++++ .../ui/platform/PlatformGamesFragment.java | 6 +-- .../ui/platform/PlatformGamesPresenter.java | 4 +- 12 files changed, 100 insertions(+), 72 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 74c0eab9cb..56e2226325 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -41,6 +41,7 @@ import org.dolphinemu.dolphinemu.fragments.LoadStateFragment; import org.dolphinemu.dolphinemu.fragments.MenuFragment; import org.dolphinemu.dolphinemu.fragments.SaveStateFragment; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.utils.Animations; import org.dolphinemu.dolphinemu.utils.Java_GCAdapter; import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter; @@ -298,7 +299,7 @@ public final class EmulationActivity extends AppCompatActivity mPreferences = PreferenceManager.getDefaultSharedPreferences(this); - mIsGameCubeGame = (NativeLibrary.GetPlatform(path) == 0); + mIsGameCubeGame = Platform.fromNativeInt(NativeLibrary.GetPlatform(path)) == Platform.GAMECUBE; } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java index cd10e4a4ae..5086e95a2d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java @@ -63,13 +63,13 @@ public final class GameRowPresenter extends Presenter int backgroundId; switch (game.getPlatform()) { - case Game.PLATFORM_GC: + case GAMECUBE: backgroundId = R.drawable.tv_card_background_gamecube; break; - case Game.PLATFORM_WII: + case WII: backgroundId = R.drawable.tv_card_background_wii; break; - case Game.PLATFORM_WII_WARE: + case WIIWARE: default: // This shouldn't happen, but set the default to WiiWare colors. backgroundId = R.drawable.tv_card_background_wiiware; break; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java index 8972ac95bd..afdf67f34e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java @@ -10,6 +10,7 @@ import android.text.SpannableString; import android.text.style.ImageSpan; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesFragment; public class PlatformPagerAdapter extends FragmentPagerAdapter @@ -32,7 +33,7 @@ public class PlatformPagerAdapter extends FragmentPagerAdapter @Override public Fragment getItem(int position) { - return PlatformGamesFragment.newInstance(position); + return PlatformGamesFragment.newInstance(Platform.fromPosition(position)); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/Game.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/Game.java index 5fd25a2354..c38bcef2e1 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/Game.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/Game.java @@ -4,13 +4,10 @@ import android.content.ContentValues; import android.database.Cursor; import android.os.Environment; +import org.dolphinemu.dolphinemu.ui.platform.Platform; + 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; public static final int COUNTRY_JAPAN = 1; @@ -36,10 +33,10 @@ public final class Game private String mScreenshotPath; private String mCompany; - private int mPlatform; + private Platform mPlatform; private int mCountry; - public Game(int platform, String title, String description, int country, String path, String gameId, String company, String screenshotPath) + public Game(Platform platform, String title, String description, int country, String path, String gameId, String company, String screenshotPath) { mPlatform = platform; mTitle = title; @@ -51,7 +48,7 @@ public final class Game mScreenshotPath = screenshotPath; } - public int getPlatform() + public Platform getPlatform() { return mPlatform; } @@ -91,13 +88,13 @@ public final class Game return mScreenshotPath; } - public static ContentValues asContentValues(int platform, String title, String description, int country, String path, String gameId, String company) + public static ContentValues asContentValues(Platform platform, String title, String description, int country, String path, String gameId, String company) { ContentValues values = new ContentValues(); String screenPath = PATH_SCREENSHOT_FOLDER + gameId + "/" + gameId + "-1.png"; - values.put(GameDatabase.KEY_GAME_PLATFORM, platform); + values.put(GameDatabase.KEY_GAME_PLATFORM, platform.toInt()); values.put(GameDatabase.KEY_GAME_TITLE, title); values.put(GameDatabase.KEY_GAME_DESCRIPTION, description); values.put(GameDatabase.KEY_GAME_COUNTRY, company); @@ -111,7 +108,7 @@ public final class Game public static Game fromCursor(Cursor cursor) { - return new Game(cursor.getInt(GameDatabase.GAME_COLUMN_PLATFORM), + return new Game(Platform.fromInt(cursor.getInt(GameDatabase.GAME_COLUMN_PLATFORM)), cursor.getString(GameDatabase.GAME_COLUMN_TITLE), cursor.getString(GameDatabase.GAME_COLUMN_DESCRIPTION), cursor.getInt(GameDatabase.GAME_COLUMN_COUNTRY), diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java index 98a751a3ca..2ab05172e2 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java @@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.utils.Log; import java.io.File; @@ -200,12 +201,7 @@ public final class GameDatabase extends SQLiteOpenHelper gameId = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf(".")); } - // If the game's platform field is empty, file under Wiiware. // TODO Something less dum - int platform = NativeLibrary.GetPlatform(filePath); - if (platform == -1) - { - platform = Game.PLATFORM_WII_WARE; - } + Platform platform = Platform.fromNativeInt(NativeLibrary.GetPlatform(filePath)); ContentValues game = Game.asContentValues(platform, name, @@ -257,7 +253,7 @@ public final class GameDatabase extends SQLiteOpenHelper database.close(); } - public Observable getGamesForPlatform(final int platform) + public Observable getGamesForPlatform(final Platform platform) { return Observable.create(new Observable.OnSubscribe() { @@ -266,18 +262,17 @@ public final class GameDatabase extends SQLiteOpenHelper { Log.info("[GameDatabase] Reading games list..."); + + // Only add a WHERE clause if we have a specific platform String whereClause = null; String[] whereArgs = null; - - // If -1 passed in, return all games. Else, return games for one platform only. - if (platform >= 0) + if (platform != Platform.ALL) { whereClause = KEY_GAME_PLATFORM + " = ?"; - whereArgs = new String[]{Integer.toString(platform)}; + whereArgs = new String[]{Integer.toString(platform.toInt())}; } SQLiteDatabase database = getReadableDatabase(); - Cursor resultCursor = database.query( TABLE_NAME_GAMES, null, diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 14e9d1758a..10d76b4e42 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -20,6 +20,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.AddDirectoryActivity; import org.dolphinemu.dolphinemu.adapters.PlatformPagerAdapter; import org.dolphinemu.dolphinemu.model.GameProvider; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView; import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity; import org.dolphinemu.dolphinemu.utils.PermissionsHandler; @@ -114,7 +115,8 @@ public final class MainActivity extends AppCompatActivity implements MainView public void refreshFragmentScreenshot(int fragmentPosition) { // Invalidate Picasso image so that the new screenshot is animated in. - PlatformGamesView fragment = getPlatformGamesView(mViewPager.getCurrentItem()); + Platform platform = Platform.fromPosition(mViewPager.getCurrentItem()); + PlatformGamesView fragment = getPlatformGamesView(platform); if (fragment != null) { @@ -135,7 +137,7 @@ public final class MainActivity extends AppCompatActivity implements MainView } @Override - public void showGames(int platformIndex, Cursor games) + public void showGames(Platform platform, Cursor games) { // no-op. Handled by PlatformGamesFragment. } @@ -189,7 +191,9 @@ public final class MainActivity extends AppCompatActivity implements MainView private void refreshFragment() { - PlatformGamesView fragment = getPlatformGamesView(mViewPager.getCurrentItem()); + + Platform platform = Platform.fromPosition(mViewPager.getCurrentItem()); + PlatformGamesView fragment = getPlatformGamesView(platform); if (fragment != null) { fragment.refresh(); @@ -197,7 +201,7 @@ public final class MainActivity extends AppCompatActivity implements MainView } @Nullable - private PlatformGamesView getPlatformGamesView(int platform) + private PlatformGamesView getPlatformGamesView(Platform platform) { String fragmentTag = "android:switcher:" + mViewPager.getId() + ":" + platform; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index 24878ab244..de9796243b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -2,10 +2,12 @@ package org.dolphinemu.dolphinemu.ui.main; import android.database.Cursor; + import org.dolphinemu.dolphinemu.BuildConfig; import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.GameDatabase; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.utils.SettingsFile; import rx.android.schedulers.AndroidSchedulers; @@ -87,11 +89,11 @@ public final class MainPresenter } } - public void loadGames(final int platformIndex) + public void loadGames(final Platform platform) { GameDatabase databaseHelper = DolphinApplication.databaseHelper; - databaseHelper.getGamesForPlatform(platformIndex) + databaseHelper.getGamesForPlatform(platform) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1() @@ -99,7 +101,7 @@ public final class MainPresenter @Override public void call(Cursor games) { - mView.showGames(platformIndex, games); + mView.showGames(platform, games); } } ); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java index 5fa0368ee8..fdaef5eefa 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java @@ -2,6 +2,8 @@ package org.dolphinemu.dolphinemu.ui.main; import android.database.Cursor; +import org.dolphinemu.dolphinemu.ui.platform.Platform; + /** * Abstraction for the screen that shows on application launch. * Implementations will differ primarily to target touch-screen @@ -39,8 +41,8 @@ public interface MainView * To be called when an asynchronous database read completes. Passes the * result, in this case a {@link Cursor} to the view. * - * @param platformIndex Which platform contains these games. + * @param platform Which platform to show games for. * @param games A Cursor containing the games read from the database. */ - void showGames(int platformIndex, Cursor games); + void showGames(Platform platform, Cursor games); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index c579190456..567e2ca492 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -27,6 +27,7 @@ import org.dolphinemu.dolphinemu.adapters.GameRowPresenter; import org.dolphinemu.dolphinemu.adapters.SettingsRowPresenter; import org.dolphinemu.dolphinemu.model.Game; import org.dolphinemu.dolphinemu.model.TvSettingsItem; +import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity; import org.dolphinemu.dolphinemu.utils.PermissionsHandler; import org.dolphinemu.dolphinemu.utils.StartupHandler; @@ -130,9 +131,9 @@ public final class TvMainActivity extends Activity implements MainView } @Override - public void showGames(int platformIndex, Cursor games) + public void showGames(Platform platform, Cursor games) { - ListRow row = buildGamesRow(platformIndex, games); + ListRow row = buildGamesRow(platform, games); // Add row to the adapter only if it is not empty. if (row != null) @@ -187,13 +188,12 @@ public final class TvMainActivity extends Activity implements MainView } private void loadGames() { - // For each platform - for (int platformIndex = 0; platformIndex <= Game.PLATFORM_ALL; ++platformIndex) { - mPresenter.loadGames(platformIndex); + for (Platform platform : Platform.values()) { + mPresenter.loadGames(platform); } } - private ListRow buildGamesRow(int platform, Cursor games) + private ListRow buildGamesRow(Platform platform, Cursor games) { // Create an adapter for this row. CursorObjectAdapter row = new CursorObjectAdapter(new GameRowPresenter()); @@ -220,32 +220,10 @@ public final class TvMainActivity extends Activity implements MainView } }); - String headerName; - switch (platform) - { - case Game.PLATFORM_GC: - headerName = "GameCube Games"; - break; - - case Game.PLATFORM_WII: - headerName = "Wii Games"; - break; - - case Game.PLATFORM_WII_WARE: - headerName = "WiiWare"; - break; - - case Game.PLATFORM_ALL: - headerName = "All Games"; - break; - - default: - headerName = "Error"; - break; - } + String headerName = platform.getHeaderName(); // Create a header for this row. - HeaderItem header = new HeaderItem(platform, headerName); + HeaderItem header = new HeaderItem(platform.toInt(), platform.getHeaderName()); // Create the row, passing it the filled adapter and the header, and give it to the master adapter. return new ListRow(header, row); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java new file mode 100644 index 0000000000..7db7b61bbc --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java @@ -0,0 +1,48 @@ +package org.dolphinemu.dolphinemu.ui.platform; + +/** Enum to represent platform (eg GameCube, Wii). */ +public enum Platform +{ + GAMECUBE(0, "GameCube Games"), + WII(1, "Wii Games"), + WIIWARE(2, "WiiWare Games"), + ALL(3, "All Games"); + + private final int value; + private final String headerName; + + Platform(int value, String headerName) + { + this.value = value; + this.headerName = headerName; + } + + public static Platform fromInt(int i) + { + return values()[i]; + } + + public static Platform fromNativeInt(int i) + { + // If the game's platform field is empty, file under Wiiware. // TODO Something less dum + if (i == -1) { + return Platform.WIIWARE; + } + return values()[i]; + } + + public static Platform fromPosition(int position) + { + return values()[position]; + } + + public int toInt() + { + return value; + } + + public String getHeaderName() + { + return headerName; + } +} \ No newline at end of file diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java index ec6d55db5f..45bfee591b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java @@ -22,12 +22,12 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam private GameAdapter mAdapter; private RecyclerView mRecyclerView; - public static PlatformGamesFragment newInstance(int platform) + public static PlatformGamesFragment newInstance(Platform platform) { PlatformGamesFragment fragment = new PlatformGamesFragment(); Bundle args = new Bundle(); - args.putInt(ARG_PLATFORM, platform); + args.putSerializable(ARG_PLATFORM, platform); fragment.setArguments(args); return fragment; @@ -38,7 +38,7 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam { super.onCreate(savedInstanceState); - mPresenter.onCreate(getArguments().getInt(ARG_PLATFORM)); + mPresenter.onCreate((Platform) getArguments().getSerializable(ARG_PLATFORM)); } @Nullable diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesPresenter.java index 403ba4ef18..3320943643 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesPresenter.java @@ -15,14 +15,14 @@ public final class PlatformGamesPresenter { private final PlatformGamesView mView; - private int mPlatform; + private Platform mPlatform; public PlatformGamesPresenter(PlatformGamesView view) { mView = view; } - public void onCreate(int platform) + public void onCreate(Platform platform) { mPlatform = platform; } From 3c3d0fa6f58a3d7f28f1b170571107526a490974 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Wed, 27 Sep 2017 11:16:48 -0700 Subject: [PATCH 4/4] Remove 'all' as a Platform enum. This will remove the 'all games' row on the TV view. --- .../dolphinemu/adapters/GameRowPresenter.java | 3 ++- .../dolphinemu/dolphinemu/model/GameDatabase.java | 12 ++---------- .../dolphinemu/dolphinemu/ui/platform/Platform.java | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java index 5086e95a2d..b6b173d4c3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java @@ -70,9 +70,10 @@ public final class GameRowPresenter extends Presenter backgroundId = R.drawable.tv_card_background_wii; break; case WIIWARE: - default: // This shouldn't happen, but set the default to WiiWare colors. backgroundId = R.drawable.tv_card_background_wiiware; break; + default: + throw new AssertionError("Not reachable."); } Context context = holder.cardParent.getContext(); Drawable background = ContextCompat.getDrawable(context, backgroundId); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java index 2ab05172e2..1a4f872330 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java @@ -262,21 +262,13 @@ public final class GameDatabase extends SQLiteOpenHelper { Log.info("[GameDatabase] Reading games list..."); - - // Only add a WHERE clause if we have a specific platform - String whereClause = null; - String[] whereArgs = null; - if (platform != Platform.ALL) - { - whereClause = KEY_GAME_PLATFORM + " = ?"; - whereArgs = new String[]{Integer.toString(platform.toInt())}; - } + String[] whereArgs = new String[]{Integer.toString(platform.toInt())}; SQLiteDatabase database = getReadableDatabase(); Cursor resultCursor = database.query( TABLE_NAME_GAMES, null, - whereClause, + KEY_GAME_PLATFORM + " = ?", whereArgs, null, null, diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java index 7db7b61bbc..b161a1cde4 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java @@ -5,8 +5,7 @@ public enum Platform { GAMECUBE(0, "GameCube Games"), WII(1, "Wii Games"), - WIIWARE(2, "WiiWare Games"), - ALL(3, "All Games"); + WIIWARE(2, "WiiWare Games"); private final int value; private final String headerName;