From 487591c76040f3599b37b667a7b181318aadda61 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Sun, 24 Sep 2017 16:12:21 -0700 Subject: [PATCH] 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 @@ + + + + +