mirror of https://github.com/FongMi/TV.git
parent
7a3d38224d
commit
943ec03e16
@ -0,0 +1,64 @@ |
||||
package com.fongmi.android.tv.ui.presenter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.leanback.widget.Presenter; |
||||
|
||||
import com.fongmi.android.tv.bean.Vod; |
||||
import com.fongmi.android.tv.databinding.AdapterSuggestBinding; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
public class SuggestPresenter extends Presenter { |
||||
|
||||
private final OnClickListener mListener; |
||||
private int width; |
||||
|
||||
public SuggestPresenter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
setLayoutSize(); |
||||
} |
||||
|
||||
private void setLayoutSize() { |
||||
int space = ResUtil.dp2px(24) + ResUtil.dp2px(8 * 5); |
||||
int base = ResUtil.getScreenWidthPx() - space; |
||||
width = base / 5; |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(Vod item); |
||||
} |
||||
|
||||
@Override |
||||
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { |
||||
ViewHolder holder = new ViewHolder(AdapterSuggestBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
holder.binding.getRoot().getLayoutParams().width = width; |
||||
return holder; |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object object) { |
||||
Vod item = (Vod) object; |
||||
ViewHolder holder = (ViewHolder) viewHolder; |
||||
holder.binding.name.setText(item.getVodName()); |
||||
holder.binding.site.setText(item.getSiteName()); |
||||
holder.binding.remark.setText(item.getVodRemarks()); |
||||
setOnClickListener(holder, view -> mListener.onItemClick(item)); |
||||
} |
||||
|
||||
@Override |
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { |
||||
} |
||||
|
||||
public static class ViewHolder extends Presenter.ViewHolder { |
||||
|
||||
private final AdapterSuggestBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterSuggestBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="150dp" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:nextFocusUp="@id/part" |
||||
android:orientation="vertical"> |
||||
|
||||
<TextView |
||||
android:id="@+id/name" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="蜘蛛人" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/site" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="2dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/green_a_400" |
||||
android:textSize="14sp" |
||||
tools:text="泥巴" |
||||
tools:visibility="visible" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/remark" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="2dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/yellow_500" |
||||
android:textSize="14sp" |
||||
tools:text="1080p" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue