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.
This commit is contained in:
parent
2d740147fe
commit
487591c760
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_selected="true"
|
||||
android:drawable="@color/dolphin_accent_gamecube" />
|
||||
<item
|
||||
android:drawable="@color/tv_card_unselected" />
|
||||
</selector>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_selected="true"
|
||||
android:drawable="@color/dolphin_accent_wii" />
|
||||
<item
|
||||
android:drawable="@color/tv_card_unselected" />
|
||||
</selector>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_selected="true"
|
||||
android:drawable="@color/dolphin_accent_wiiware" />
|
||||
<item
|
||||
android:drawable="@color/tv_card_unselected" />
|
||||
</selector>
|
Loading…
Reference in New Issue