mirror of https://github.com/FongMi/TV.git
parent
31a3dedc87
commit
991bde743e
@ -0,0 +1,64 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.LinearLayoutManager; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.bean.Filter; |
||||
import com.fongmi.android.tv.databinding.AdapterFilterBinding; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class FilterAdapter extends RecyclerView.Adapter<FilterAdapter.ViewHolder> { |
||||
|
||||
private final ValueAdapter.OnClickListener mListener; |
||||
private final List<Filter> mItems; |
||||
|
||||
public FilterAdapter(ValueAdapter.OnClickListener listener) { |
||||
this.mListener = listener; |
||||
this.mItems = new ArrayList<>(); |
||||
} |
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterFilterBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterFilterBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
|
||||
public void addAll(List<Filter> items) { |
||||
mItems.addAll(items); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
public void clear() { |
||||
mItems.clear(); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterFilterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Filter item = mItems.get(position); |
||||
holder.binding.recycler.setHasFixedSize(true); |
||||
holder.binding.recycler.setLayoutManager(new LinearLayoutManager(holder.itemView.getContext(), LinearLayoutManager.HORIZONTAL, false)); |
||||
holder.binding.recycler.setAdapter(new ValueAdapter(mListener, item)); |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@ |
||||
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.Filter; |
||||
import com.fongmi.android.tv.databinding.AdapterValueBinding; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ValueAdapter extends RecyclerView.Adapter<ValueAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<Filter.Value> mItems; |
||||
private final String mKey; |
||||
|
||||
public ValueAdapter(OnClickListener listener, Filter filter) { |
||||
this.mListener = listener; |
||||
this.mItems = filter.getValue(); |
||||
this.mKey = filter.getKey(); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
void onItemClick(String key, Filter.Value item); |
||||
} |
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterValueBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterValueBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterValueBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Filter.Value item = mItems.get(position); |
||||
holder.binding.text.setText(item.getN()); |
||||
holder.binding.text.setActivated(item.isActivated()); |
||||
holder.binding.getRoot().setOnClickListener(v -> mListener.onItemClick(mKey, item)); |
||||
} |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:padding="8dp" /> |
||||
@ -0,0 +1,12 @@ |
||||
<?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:layout_marginStart="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:background="@drawable/selector_item_round" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" |
||||
tools:text="全部" /> |
||||
@ -1,18 +1,41 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<com.fongmi.android.tv.ui.custom.ProgressLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:id="@+id/progressLayout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler" |
||||
<androidx.core.widget.NestedScrollView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:paddingStart="16dp" |
||||
android:paddingTop="8dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="16dp" /> |
||||
android:fillViewport="true"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/filter" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:nestedScrollingEnabled="false" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:nestedScrollingEnabled="false" |
||||
android:paddingStart="16dp" |
||||
android:paddingTop="8dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="16dp" /> |
||||
|
||||
</LinearLayout> |
||||
</androidx.core.widget.NestedScrollView> |
||||
</com.fongmi.android.tv.ui.custom.ProgressLayout> |
||||
Loading…
Reference in new issue