mirror of https://github.com/FongMi/TV.git
parent
e3c0b3b83d
commit
b00c29c6aa
@ -0,0 +1,113 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.api.ApiConfig; |
||||
import com.fongmi.android.tv.bean.History; |
||||
import com.fongmi.android.tv.databinding.AdapterVodBinding; |
||||
import com.fongmi.android.tv.utils.ImgUtil; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<History> mItems; |
||||
private int width, height; |
||||
private boolean delete; |
||||
|
||||
public HistoryAdapter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
this.mItems = new ArrayList<>(); |
||||
setLayoutSize(3); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(History item); |
||||
|
||||
void onItemDelete(History item); |
||||
|
||||
boolean onLongClick(); |
||||
} |
||||
|
||||
public boolean isDelete() { |
||||
return delete; |
||||
} |
||||
|
||||
public void setDelete(boolean delete) { |
||||
this.delete = delete; |
||||
} |
||||
|
||||
private void setLayoutSize(int spanCount) { |
||||
int space = ResUtil.dp2px(32 + ((spanCount - 1) * 16)); |
||||
int base = ResUtil.getScreenWidthPx() - space; |
||||
width = base / spanCount; |
||||
height = (int) (width / 0.75f); |
||||
} |
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { |
||||
|
||||
private final AdapterVodBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterVodBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
binding.getRoot().setOnClickListener(this); |
||||
binding.getRoot().setOnLongClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View view) { |
||||
History item = mItems.get(getLayoutPosition()); |
||||
if (isDelete()) mListener.onItemDelete(item); |
||||
else mListener.onItemClick(item); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onLongClick(View v) { |
||||
return mListener.onLongClick(); |
||||
} |
||||
} |
||||
|
||||
public void addAll(List<History> items) { |
||||
mItems.clear(); |
||||
mItems.addAll(items); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
ViewHolder holder = new ViewHolder(AdapterVodBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
holder.binding.getRoot().getLayoutParams().width = width; |
||||
holder.binding.getRoot().getLayoutParams().height = height; |
||||
return holder; |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
History item = mItems.get(position); |
||||
holder.binding.name.setText(item.getVodName()); |
||||
holder.binding.site.setText(ApiConfig.getSiteName(item.getSiteKey())); |
||||
holder.binding.remark.setText(ResUtil.getString(R.string.vod_last, item.getVodRemarks())); |
||||
holder.binding.name.setVisibility(delete ? View.GONE : View.VISIBLE); |
||||
holder.binding.site.setVisibility(delete ? View.GONE : View.VISIBLE); |
||||
holder.binding.remark.setVisibility(delete ? View.GONE : View.VISIBLE); |
||||
holder.binding.delete.setVisibility(!delete ? View.GONE : View.VISIBLE); |
||||
ImgUtil.load(item.getVodPic(), holder.binding.image); |
||||
} |
||||
} |
||||
@ -0,0 +1,88 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.bean.Vod; |
||||
import com.fongmi.android.tv.databinding.AdapterVodBinding; |
||||
import com.fongmi.android.tv.utils.ImgUtil; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class VodAdapter extends RecyclerView.Adapter<VodAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<Vod> mItems; |
||||
private int width, height; |
||||
|
||||
public VodAdapter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
this.mItems = new ArrayList<>(); |
||||
setLayoutSize(3); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(Vod item); |
||||
} |
||||
|
||||
private void setLayoutSize(int spanCount) { |
||||
int space = ResUtil.dp2px(32 + ((spanCount - 1) * 16)); |
||||
int base = ResUtil.getScreenWidthPx() - space; |
||||
width = base / spanCount; |
||||
height = (int) (width / 0.75f); |
||||
} |
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
||||
|
||||
private final AdapterVodBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterVodBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
binding.getRoot().setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View view) { |
||||
mListener.onItemClick(mItems.get(getLayoutPosition())); |
||||
} |
||||
} |
||||
|
||||
public void addAll(List<Vod> items) { |
||||
mItems.clear(); |
||||
mItems.addAll(items); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
ViewHolder holder = new ViewHolder(AdapterVodBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
holder.binding.getRoot().getLayoutParams().width = width; |
||||
holder.binding.getRoot().getLayoutParams().height = height; |
||||
return holder; |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Vod item = mItems.get(position); |
||||
holder.binding.name.setText(item.getVodName()); |
||||
holder.binding.year.setText(item.getVodYear()); |
||||
holder.binding.remark.setText(item.getVodRemarks()); |
||||
holder.binding.year.setVisibility(item.getYearVisible()); |
||||
holder.binding.remark.setVisibility(item.getRemarkVisible()); |
||||
ImgUtil.load(item.getVodName(), item.getVodPic(), holder.binding.image); |
||||
} |
||||
} |
||||
@ -0,0 +1,85 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="150dp" |
||||
android:layout_height="200dp" |
||||
android:background="@color/black_20"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/image" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:scaleType="center" |
||||
tools:src="@drawable/ic_img_loading" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/delete" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_gravity="center" |
||||
android:background="@color/white_30" |
||||
android:scaleType="center" |
||||
android:src="@drawable/ic_delete" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/year" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:background="#CC2196F3" |
||||
android:ellipsize="end" |
||||
android:padding="4dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" |
||||
android:visibility="gone" |
||||
tools:text="2022" |
||||
tools:visibility="visible" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/site" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:background="#CCF44336" |
||||
android:ellipsize="end" |
||||
android:padding="4dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" |
||||
android:visibility="gone" |
||||
tools:text="泥巴" |
||||
tools:visibility="visible" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/remark" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_above="@+id/name" |
||||
android:background="#CC177535" |
||||
android:ellipsize="end" |
||||
android:padding="4dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" |
||||
tools:text="1080p" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/name" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentBottom="true" |
||||
android:background="@color/black_60" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:marqueeRepeatLimit="marquee_forever" |
||||
android:padding="6dp" |
||||
android:scrollHorizontally="true" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="蜘蛛人" /> |
||||
|
||||
</RelativeLayout> |
||||
@ -1,6 +1,51 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
</FrameLayout> |
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/white" |
||||
android:textSize="20sp" |
||||
android:textStyle="bold" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:text="最近觀看" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/history" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:nestedScrollingEnabled="false" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:text="更新推薦" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recommend" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:nestedScrollingEnabled="false" /> |
||||
|
||||
</LinearLayout> |
||||
</androidx.core.widget.NestedScrollView> |
||||
@ -1,22 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:id="@+id/nav_main" |
||||
android:id="@+id/nav_graph" |
||||
app:startDestination="@id/home"> |
||||
|
||||
<fragment |
||||
android:id="@+id/home" |
||||
android:name="com.fongmi.android.tv.ui.fragment.HomeFragment" |
||||
android:label="@string/main_home" /> |
||||
android:label="@string/nav_home" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/vod" |
||||
android:name="com.fongmi.android.tv.ui.fragment.VodFragment" |
||||
android:label="@string/main_vod" /> |
||||
android:label="@string/nav_vod" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/setting" |
||||
android:name="com.fongmi.android.tv.ui.fragment.SettingFragment" |
||||
android:label="@string/main_setting" /> |
||||
android:label="@string/nav_setting" /> |
||||
|
||||
</navigation> |
||||
@ -1,8 +1,8 @@ |
||||
<resources> |
||||
|
||||
<!-- Main --> |
||||
<string name="main_home">首页</string> |
||||
<string name="main_vod">片库</string> |
||||
<string name="main_setting">设定</string> |
||||
<!-- Nav --> |
||||
<string name="nav_home">首页</string> |
||||
<string name="nav_vod">片库</string> |
||||
<string name="nav_setting">设定</string> |
||||
|
||||
</resources> |
||||
@ -1,8 +1,8 @@ |
||||
<resources> |
||||
|
||||
<!-- Main --> |
||||
<string name="main_home">首頁</string> |
||||
<string name="main_vod">片庫</string> |
||||
<string name="main_setting">設定</string> |
||||
<!-- Nav --> |
||||
<string name="nav_home">首頁</string> |
||||
<string name="nav_vod">片庫</string> |
||||
<string name="nav_setting">設定</string> |
||||
|
||||
</resources> |
||||
@ -1,8 +1,8 @@ |
||||
<resources> |
||||
|
||||
<!-- Main --> |
||||
<string name="main_home">Home</string> |
||||
<string name="main_vod">Vod</string> |
||||
<string name="main_setting">Setting</string> |
||||
<!-- Nav --> |
||||
<string name="nav_home">Home</string> |
||||
<string name="nav_vod">Vod</string> |
||||
<string name="nav_setting">Setting</string> |
||||
|
||||
</resources> |
||||
Loading…
Reference in new issue