mirror of https://github.com/FongMi/TV.git
parent
81a0127de2
commit
5c7ab5e2fb
@ -0,0 +1,68 @@ |
||||
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.Channel; |
||||
import com.fongmi.android.tv.bean.Group; |
||||
import com.fongmi.android.tv.databinding.AdapterLiveChannelBinding; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ViewHolder> { |
||||
|
||||
private final List<Channel> mItems; |
||||
private Group group; |
||||
|
||||
public ChannelAdapter() { |
||||
this.mItems = new ArrayList<>(); |
||||
} |
||||
|
||||
public Group getGroup() { |
||||
return group; |
||||
} |
||||
|
||||
public void setGroup(Group group) { |
||||
this.group = group; |
||||
} |
||||
|
||||
public void addAll(Group group) { |
||||
setGroup(group); |
||||
mItems.clear(); |
||||
mItems.addAll(group.getChannel()); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterLiveChannelBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Channel item = mItems.get(position); |
||||
holder.binding.name.setText(item.getName()); |
||||
holder.binding.number.setText(item.getNumber()); |
||||
holder.binding.icon.setVisibility(item.getVisible()); |
||||
} |
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterLiveChannelBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterLiveChannelBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@ |
||||
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.Group; |
||||
import com.fongmi.android.tv.databinding.AdapterLiveGroupBinding; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class GroupAdapter extends RecyclerView.Adapter<GroupAdapter.ViewHolder> { |
||||
|
||||
private final List<Group> mItems; |
||||
private final List<Group> mHides; |
||||
|
||||
public GroupAdapter() { |
||||
this.mItems = new ArrayList<>(); |
||||
this.mHides = new ArrayList<>(); |
||||
} |
||||
|
||||
public void addAll(List<Group> items) { |
||||
mItems.clear(); |
||||
addGroup(items); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
private void addGroup(List<Group> items) { |
||||
for (Group item : items) if (item.isHidden()) mHides.add(item);else mItems.add(item); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterLiveGroupBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Group item = mItems.get(position); |
||||
holder.binding.name.setText(item.getName()); |
||||
holder.binding.icon.setVisibility(item.getVisible()); |
||||
} |
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterLiveGroupBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterLiveGroupBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -1,4 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:drawable="@drawable/shape_live_channel" android:state_selected="true" /> |
||||
<item android:drawable="@drawable/shape_live_channel" android:state_focused="true" /> |
||||
</selector> |
||||
@ -1,4 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:drawable="@drawable/shape_live_group" android:state_selected="true" /> |
||||
<item android:drawable="@drawable/shape_live_group" android:state_focused="true" /> |
||||
</selector> |
||||
@ -0,0 +1,106 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.view.View; |
||||
import android.widget.ImageView; |
||||
|
||||
import com.fongmi.android.tv.utils.ImgUtil; |
||||
|
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
public class Channel { |
||||
|
||||
private List<String> urls; |
||||
private String number; |
||||
private String icon; |
||||
private String name; |
||||
private Group type; |
||||
private String ua; |
||||
private boolean select; |
||||
|
||||
public static Channel create(String number) { |
||||
return new Channel(String.format(Locale.getDefault(), "%03d", Integer.valueOf(number))); |
||||
} |
||||
|
||||
public Channel(String number) { |
||||
this.number = number; |
||||
} |
||||
|
||||
public Channel(String number, String name) { |
||||
this.number = number; |
||||
this.name = name; |
||||
} |
||||
|
||||
public List<String> getUrls() { |
||||
return urls; |
||||
} |
||||
|
||||
public void setUrls(List<String> urls) { |
||||
this.urls = urls; |
||||
} |
||||
|
||||
public String getNumber() { |
||||
return number; |
||||
} |
||||
|
||||
public void setNumber(String number) { |
||||
this.number = number; |
||||
} |
||||
|
||||
public String getIcon() { |
||||
return TextUtils.isEmpty(icon) ? "" : icon; |
||||
} |
||||
|
||||
public void setIcon(String icon) { |
||||
this.icon = icon; |
||||
} |
||||
|
||||
public String getName() { |
||||
return TextUtils.isEmpty(name) ? "" : name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public Group getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(Group type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getUa() { |
||||
return TextUtils.isEmpty(ua) ? "" : ua; |
||||
} |
||||
|
||||
public void setUa(String ua) { |
||||
this.ua = ua; |
||||
} |
||||
|
||||
public boolean isSelect() { |
||||
return select; |
||||
} |
||||
|
||||
public void setSelect(boolean select) { |
||||
this.select = select; |
||||
} |
||||
|
||||
public int getVisible() { |
||||
return getIcon().isEmpty() ? View.GONE : View.VISIBLE; |
||||
} |
||||
|
||||
public void loadIcon(ImageView view) { |
||||
if (!getIcon().isEmpty()) ImgUtil.load(getIcon(), view); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) return true; |
||||
if (!(obj instanceof Channel)) return false; |
||||
Channel it = (Channel) obj; |
||||
return getNumber().equals(it.getNumber()); |
||||
} |
||||
} |
||||
@ -0,0 +1,96 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.view.View; |
||||
import android.widget.ImageView; |
||||
|
||||
import com.fongmi.android.tv.utils.ImgUtil; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class Group { |
||||
|
||||
private List<Channel> channel; |
||||
private String icon; |
||||
private String name; |
||||
private String pass; |
||||
private boolean select; |
||||
private int position; |
||||
|
||||
public Group(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public List<Channel> getChannel() { |
||||
return channel; |
||||
} |
||||
|
||||
public void setChannel(List<Channel> channel) { |
||||
this.channel = channel; |
||||
} |
||||
|
||||
public String getIcon() { |
||||
return TextUtils.isEmpty(icon) ? "" : icon; |
||||
} |
||||
|
||||
public void setIcon(String icon) { |
||||
this.icon = icon; |
||||
} |
||||
|
||||
public String getName() { |
||||
return TextUtils.isEmpty(name) ? "" : name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getPass() { |
||||
return TextUtils.isEmpty(pass) ? "" : pass; |
||||
} |
||||
|
||||
public void setPass(String pass) { |
||||
this.pass = pass; |
||||
} |
||||
|
||||
public boolean isSelect() { |
||||
return select; |
||||
} |
||||
|
||||
public void setSelect(boolean select) { |
||||
this.select = select; |
||||
} |
||||
|
||||
public int getPosition() { |
||||
return position; |
||||
} |
||||
|
||||
public void setPosition(int position) { |
||||
this.position = position; |
||||
} |
||||
|
||||
public boolean isHidden() { |
||||
return !TextUtils.isEmpty(getPass()); |
||||
} |
||||
|
||||
public int getVisible() { |
||||
return getIcon().isEmpty() ? View.GONE : View.VISIBLE; |
||||
} |
||||
|
||||
public void loadIcon(ImageView view) { |
||||
if (!getIcon().isEmpty()) ImgUtil.load(getIcon(), view); |
||||
} |
||||
|
||||
public int find(String number) { |
||||
return getChannel().lastIndexOf(Channel.create(number)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (obj == null) return false; |
||||
if (this == obj) return true; |
||||
if (!(obj instanceof Group)) return false; |
||||
Group it = (Group) obj; |
||||
return getName().equals(it.getName()); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue