mirror of https://github.com/FongMi/TV.git
parent
d999e37da5
commit
4daecbe1a7
@ -0,0 +1,96 @@ |
||||
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.databinding.AdapterKeyboardIconBinding; |
||||
import com.fongmi.android.tv.databinding.AdapterKeyboardTextBinding; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
public class KeyboardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<Object> mItems; |
||||
|
||||
public KeyboardAdapter(OnClickListener listener) { |
||||
this.mItems = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", R.drawable.ic_keyboard_left, R.drawable.ic_keyboard_right, R.drawable.ic_keyboard_back, R.drawable.ic_keyboard_enter); |
||||
this.mListener = listener; |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onTextClick(String text); |
||||
|
||||
void onIconClick(int resId); |
||||
} |
||||
|
||||
class TextHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
||||
|
||||
private final AdapterKeyboardTextBinding binding; |
||||
|
||||
TextHolder(@NonNull AdapterKeyboardTextBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
itemView.setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View view) { |
||||
mListener.onTextClick(mItems.get(getLayoutPosition()).toString()); |
||||
} |
||||
} |
||||
|
||||
class IconHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
||||
|
||||
private final AdapterKeyboardIconBinding binding; |
||||
|
||||
IconHolder(@NonNull AdapterKeyboardIconBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
itemView.setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View view) { |
||||
mListener.onIconClick((int) mItems.get(getLayoutPosition())); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getItemViewType(int position) { |
||||
return mItems.get(position) instanceof String ? 0 : 1; |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
if (viewType == 0) return new TextHolder(AdapterKeyboardTextBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
else return new IconHolder(AdapterKeyboardIconBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
||||
switch (getItemViewType(position)) { |
||||
case 0: |
||||
TextHolder text = (TextHolder) holder; |
||||
text.binding.text.setText(mItems.get(position).toString()); |
||||
break; |
||||
case 1: |
||||
IconHolder icon = (IconHolder) holder; |
||||
icon.binding.icon.setImageResource((int) mItems.get(position)); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
package com.fongmi.android.tv.ui.custom; |
||||
|
||||
import android.graphics.Rect; |
||||
import android.view.View; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
public class SpaceItemDecoration extends RecyclerView.ItemDecoration { |
||||
|
||||
private final int spanCount; |
||||
private final int spacing; |
||||
|
||||
public SpaceItemDecoration(int spanCount, int spacing) { |
||||
this.spanCount = spanCount; |
||||
this.spacing = ResUtil.dp2px(spacing); |
||||
} |
||||
|
||||
@Override |
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, RecyclerView parent, @NonNull RecyclerView.State state) { |
||||
int position = parent.getChildAdapterPosition(view); |
||||
if (position >= 0) { |
||||
int column = position % spanCount; |
||||
outRect.left = column * spacing / spanCount; |
||||
outRect.right = spacing - (column + 1) * spacing / spanCount; |
||||
if (position >= spanCount) outRect.top = spacing; |
||||
} else { |
||||
outRect.left = 0; |
||||
outRect.right = 0; |
||||
outRect.top = 0; |
||||
outRect.bottom = 0; |
||||
} |
||||
} |
||||
} |
||||
@ -1,63 +0,0 @@ |
||||
package com.fongmi.android.tv.ui.presenter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.leanback.widget.Presenter; |
||||
|
||||
import com.fongmi.android.tv.databinding.AdapterKeyboardBinding; |
||||
|
||||
public class KeyboardPresenter extends Presenter { |
||||
|
||||
private final OnClickListener mListener; |
||||
|
||||
public KeyboardPresenter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onTextClick(String text); |
||||
|
||||
void onIconClick(int resId); |
||||
} |
||||
|
||||
@Override |
||||
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { |
||||
return new ViewHolder(AdapterKeyboardBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object object) { |
||||
ViewHolder holder = (ViewHolder) viewHolder; |
||||
if (object instanceof String) { |
||||
String text = (String) object; |
||||
holder.binding.text.setText(text); |
||||
holder.binding.icon.setVisibility(View.GONE); |
||||
holder.binding.text.setVisibility(View.VISIBLE); |
||||
setOnClickListener(holder, view -> mListener.onTextClick(text)); |
||||
} else { |
||||
int resId = (int) object; |
||||
holder.binding.icon.setImageResource(resId); |
||||
holder.binding.text.setVisibility(View.GONE); |
||||
holder.binding.icon.setVisibility(View.VISIBLE); |
||||
setOnClickListener(holder, view -> mListener.onIconClick(resId)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { |
||||
} |
||||
|
||||
public static class ViewHolder extends Presenter.ViewHolder { |
||||
|
||||
private final AdapterKeyboardBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterKeyboardBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
package com.fongmi.android.tv.ui.presenter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.leanback.widget.Presenter; |
||||
|
||||
import com.fongmi.android.tv.databinding.AdapterWordBinding; |
||||
|
||||
public class WordPresenter extends Presenter { |
||||
|
||||
private OnClickListener mListener; |
||||
|
||||
public WordPresenter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
void onItemClick(String text); |
||||
} |
||||
|
||||
public void setOnClickListener(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
} |
||||
|
||||
@Override |
||||
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { |
||||
return new ViewHolder(AdapterWordBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object object) { |
||||
ViewHolder holder = (ViewHolder) viewHolder; |
||||
holder.binding.text.setText(object.toString()); |
||||
setOnClickListener(holder, view -> mListener.onItemClick(object.toString())); |
||||
} |
||||
|
||||
@Override |
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { |
||||
} |
||||
|
||||
public static class ViewHolder extends Presenter.ViewHolder { |
||||
|
||||
private final AdapterWordBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterWordBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
<vector android:height="24dp" android:tint="#FFFFFF" |
||||
android:viewportHeight="24" android:viewportWidth="24" |
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<path android:fillColor="@android:color/white" android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z"/> |
||||
</vector> |
||||
@ -1,6 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:drawable="@drawable/shape_type_focused" android:state_focused="true" /> |
||||
<item android:drawable="@drawable/shape_type_activated" android:state_activated="true" /> |
||||
<item android:drawable="@drawable/shape_type_normal" /> |
||||
</selector> |
||||
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:drawable="@drawable/shape_keyboard_focused" android:state_focused="true" /> |
||||
<item android:drawable="@drawable/shape_keyboard_normal" /> |
||||
</selector> |
||||
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:drawable="@drawable/shape_mic_focused" android:state_focused="true" /> |
||||
<item android:drawable="@drawable/shape_mic_normal" /> |
||||
</selector> |
||||
@ -0,0 +1,13 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shape="rectangle"> |
||||
|
||||
<solid android:color="@color/black_30" /> |
||||
|
||||
<corners android:radius="4dp" /> |
||||
|
||||
<stroke |
||||
android:width="1dp" |
||||
android:color="@color/white" /> |
||||
|
||||
</shape> |
||||
@ -0,0 +1,9 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shape="rectangle"> |
||||
|
||||
<solid android:color="@color/black_20" /> |
||||
|
||||
<corners android:radius="4dp" /> |
||||
|
||||
</shape> |
||||
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shape="oval"> |
||||
|
||||
<solid android:color="@color/black_30" /> |
||||
|
||||
<stroke |
||||
android:width="1dp" |
||||
android:color="@color/white" /> |
||||
|
||||
</shape> |
||||
@ -0,0 +1,7 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shape="oval"> |
||||
|
||||
<solid android:color="@color/black_20" /> |
||||
|
||||
</shape> |
||||
@ -1,27 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="40dp" |
||||
android:layout_height="40dp" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:padding="8dp"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:gravity="center" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="0" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/icon" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:scaleType="fitCenter" |
||||
android:src="@drawable/ic_keyboard_back" /> |
||||
|
||||
</FrameLayout> |
||||
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/icon" |
||||
android:layout_width="44dp" |
||||
android:layout_height="44dp" |
||||
android:background="@drawable/selector_keyboard" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:padding="6dp" |
||||
tools:src="@drawable/ic_keyboard_back" /> |
||||
@ -0,0 +1,14 @@ |
||||
<?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="44dp" |
||||
android:layout_height="44dp" |
||||
android:background="@drawable/selector_keyboard" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:padding="6dp" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="0" /> |
||||
@ -0,0 +1,14 @@ |
||||
<?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/selector_type" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:nextFocusLeft="@id/word" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="推薦" /> |
||||
@ -0,0 +1,47 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import com.google.gson.Gson; |
||||
import com.google.gson.annotations.SerializedName; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class Hot { |
||||
|
||||
@SerializedName("data") |
||||
private Data data; |
||||
|
||||
private static Hot objectFrom(String str) { |
||||
return new Gson().fromJson(str, Hot.class); |
||||
} |
||||
|
||||
public static List<String> get(String str) { |
||||
List<String> items = new ArrayList<>(); |
||||
for (Data.Item item : objectFrom(str).getData().getItemList()) items.add(item.getTitle()); |
||||
return items; |
||||
} |
||||
|
||||
private Data getData() { |
||||
return data; |
||||
} |
||||
|
||||
static class Data { |
||||
|
||||
@SerializedName("itemList") |
||||
private List<Item> itemList; |
||||
|
||||
public List<Item> getItemList() { |
||||
return itemList; |
||||
} |
||||
|
||||
static class Item { |
||||
|
||||
@SerializedName("title") |
||||
private String title; |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import com.google.gson.Gson; |
||||
import com.google.gson.annotations.SerializedName; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class Suggest { |
||||
|
||||
@SerializedName("data") |
||||
private List<Data> data; |
||||
|
||||
private static Suggest objectFrom(String str) { |
||||
return new Gson().fromJson(str, Suggest.class); |
||||
} |
||||
|
||||
public static List<String> get(String str) { |
||||
List<String> items = new ArrayList<>(); |
||||
for (Data item : objectFrom(str).getData()) items.add(item.getName()); |
||||
return items; |
||||
} |
||||
|
||||
private List<Data> getData() { |
||||
return data; |
||||
} |
||||
|
||||
static class Data { |
||||
|
||||
@SerializedName("name") |
||||
private String name; |
||||
|
||||
private String getName() { |
||||
return name; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue