Android: Convert SettingsRowPresenter to Kotlin
This commit is contained in:
parent
e4935d4b12
commit
a1d027fe07
|
@ -1,57 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.leanback.widget.ImageCardView;
|
||||
import androidx.leanback.widget.Presenter;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.TvSettingsItem;
|
||||
import org.dolphinemu.dolphinemu.viewholders.TvSettingsViewHolder;
|
||||
|
||||
public final class SettingsRowPresenter extends Presenter
|
||||
{
|
||||
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent)
|
||||
{
|
||||
// Create a new view.
|
||||
ImageCardView settingsCard = new ImageCardView(parent.getContext());
|
||||
|
||||
settingsCard.setMainImageAdjustViewBounds(true);
|
||||
settingsCard.setMainImageDimensions(192, 160);
|
||||
|
||||
settingsCard.setFocusable(true);
|
||||
settingsCard.setFocusableInTouchMode(true);
|
||||
|
||||
// Use that view to create a ViewHolder.
|
||||
return new TvSettingsViewHolder(settingsCard);
|
||||
}
|
||||
|
||||
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item)
|
||||
{
|
||||
TvSettingsViewHolder holder = (TvSettingsViewHolder) viewHolder;
|
||||
Context context = holder.cardParent.getContext();
|
||||
TvSettingsItem settingsItem = (TvSettingsItem) item;
|
||||
|
||||
Resources resources = holder.cardParent.getResources();
|
||||
|
||||
holder.itemId = settingsItem.getItemId();
|
||||
|
||||
holder.cardParent.setTitleText(resources.getString(settingsItem.getLabelId()));
|
||||
holder.cardParent.setMainImage(resources.getDrawable(settingsItem.getIconId()));
|
||||
|
||||
// Set the background color of the card
|
||||
Drawable background = ContextCompat.getDrawable(context, R.drawable.tv_card_background);
|
||||
holder.cardParent.setInfoAreaBackground(background);
|
||||
}
|
||||
|
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder)
|
||||
{
|
||||
// no op
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.adapters
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.leanback.widget.ImageCardView
|
||||
import androidx.leanback.widget.Presenter
|
||||
import org.dolphinemu.dolphinemu.R
|
||||
import org.dolphinemu.dolphinemu.model.TvSettingsItem
|
||||
import org.dolphinemu.dolphinemu.viewholders.TvSettingsViewHolder
|
||||
|
||||
class SettingsRowPresenter : Presenter() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder {
|
||||
// Create a new view.
|
||||
val settingsCard = ImageCardView(parent.context)
|
||||
settingsCard.apply {
|
||||
setMainImageAdjustViewBounds(true)
|
||||
setMainImageDimensions(192, 160)
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
|
||||
// Use that view to create a ViewHolder.
|
||||
return TvSettingsViewHolder(settingsCard)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, item: Any) {
|
||||
val holder = viewHolder as TvSettingsViewHolder
|
||||
val context = holder.cardParent.context
|
||||
val settingsItem = item as TvSettingsItem
|
||||
val resources = holder.cardParent.resources
|
||||
holder.apply {
|
||||
itemId = settingsItem.itemId
|
||||
cardParent.titleText = resources.getString(settingsItem.labelId)
|
||||
cardParent.mainImage = ContextCompat.getDrawable(context, settingsItem.iconId)
|
||||
|
||||
// Set the background color of the card
|
||||
val background = ContextCompat.getDrawable(context, R.drawable.tv_card_background)
|
||||
cardParent.infoAreaBackground = background
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUnbindViewHolder(viewHolder: ViewHolder) {
|
||||
// no op
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue