mirror of https://github.com/FongMi/TV.git
parent
1a06a887cb
commit
33338cb0fb
@ -0,0 +1,49 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class Url { |
||||
|
||||
private List<Value> values; |
||||
private int position; |
||||
|
||||
public List<Value> getValues() { |
||||
return values = values == null ? new ArrayList<>() : values; |
||||
} |
||||
|
||||
public int getPosition() { |
||||
return position; |
||||
} |
||||
|
||||
public String v() { |
||||
return v(getPosition()); |
||||
} |
||||
|
||||
public String n() { |
||||
return n(getPosition()); |
||||
} |
||||
|
||||
public String v(int position) { |
||||
return position >= getValues().size() ? "" : getValues().get(position).getV(); |
||||
} |
||||
|
||||
public String n(int position) { |
||||
return position >= getValues().size() ? "" : getValues().get(position).getN(); |
||||
} |
||||
|
||||
public Url set(int position) { |
||||
this.position = Math.min(position, getValues().size() - 1); |
||||
return this; |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return getValues().isEmpty() || TextUtils.isEmpty(v()); |
||||
} |
||||
|
||||
public boolean isOnly() { |
||||
return getValues().size() == 1; |
||||
} |
||||
} |
||||
@ -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.AdapterUrlBinding; |
||||
|
||||
public class UrlAdapter extends RecyclerView.Adapter<UrlAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private Result mResult; |
||||
private int position; |
||||
|
||||
public UrlAdapter(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(AdapterUrlBinding.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 AdapterUrlBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterUrlBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
<?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/shape_item" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="14sp" |
||||
tools:text="1080P" /> |
||||
Loading…
Reference in new issue