mirror of https://github.com/FongMi/TV.git
parent
811f8e7a77
commit
8c2d98a1cd
@ -0,0 +1,67 @@ |
||||
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.Epg; |
||||
import com.fongmi.android.tv.databinding.AdapterEpgBinding; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class EpgAdapter extends RecyclerView.Adapter<EpgAdapter.ViewHolder> { |
||||
|
||||
private final List<Epg> mItems; |
||||
|
||||
public EpgAdapter() { |
||||
this.mItems = new ArrayList<>(); |
||||
} |
||||
|
||||
public void clear() { |
||||
mItems.clear(); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
public void addAll(List<Epg> items) { |
||||
mItems.clear(); |
||||
mItems.addAll(items); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
public int getPosition() { |
||||
for (int i = 0; i < mItems.size(); i++) if (mItems.get(i).isInRange()) return i; |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterEpgBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Epg item = mItems.get(position); |
||||
holder.binding.time.setText(item.getTime()); |
||||
holder.binding.title.setText(item.getTitle()); |
||||
holder.binding.getRoot().setSelected(item.isInRange()); |
||||
} |
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterEpgBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterEpgBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,6 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:color="@color/white" android:state_focused="true" android:state_selected="true" /> |
||||
<item android:color="@color/yellow_500" android:state_selected="true" /> |
||||
<item android:color="@color/white" /> |
||||
</selector> |
||||
@ -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="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:paddingStart="8dp" |
||||
android:paddingTop="6dp" |
||||
android:paddingEnd="8dp" |
||||
android:paddingBottom="6dp"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:duplicateParentState="true" |
||||
android:ellipsize="marquee" |
||||
android:shadowColor="@color/grey_900" |
||||
android:shadowDx="2" |
||||
android:shadowDy="2" |
||||
android:shadowRadius="1" |
||||
android:singleLine="true" |
||||
android:textColor="@color/epg" |
||||
android:textSize="14sp" |
||||
tools:text="七龍珠" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:duplicateParentState="true" |
||||
android:ellipsize="marquee" |
||||
android:shadowColor="@color/grey_900" |
||||
android:shadowDx="2" |
||||
android:shadowDy="2" |
||||
android:shadowRadius="1" |
||||
android:singleLine="true" |
||||
android:textColor="@color/epg" |
||||
android:textSize="14sp" |
||||
tools:text="18:00 ~ 19:00" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue