mirror of https://github.com/FongMi/TV.git
parent
c73fa2ebb5
commit
4cc76fea0a
@ -0,0 +1,71 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.bean.Result; |
||||
import com.fongmi.android.tv.databinding.AdapterQualityBinding; |
||||
|
||||
public class QualityAdapter extends RecyclerView.Adapter<QualityAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private Result mResult; |
||||
private int position; |
||||
|
||||
public QualityAdapter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
this.mResult = Result.empty(); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(Result result); |
||||
} |
||||
|
||||
public void addAll(Result result) { |
||||
mResult = result; |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
public int getPosition() { |
||||
return position; |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mResult.getUrl().getValues().size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterQualityBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
holder.binding.text.setText(mResult.getUrl().n(position)); |
||||
holder.binding.text.setOnClickListener(v -> onItemClick(position)); |
||||
holder.binding.text.setActivated(mResult.getUrl().getPosition() == position); |
||||
} |
||||
|
||||
private void onItemClick(int position) { |
||||
this.position = position; |
||||
mResult.getUrl().set(position); |
||||
mListener.onItemClick(mResult); |
||||
notifyItemRangeChanged(0, getItemCount()); |
||||
} |
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterQualityBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterQualityBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/text" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/selector_item" |
||||
android:ellipsize="marquee" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:nextFocusUp="@id/episode" |
||||
android:nextFocusDown="@id/array" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="16sp" |
||||
tools:text="20" /> |
||||
Loading…
Reference in new issue