mirror of https://github.com/FongMi/TV.git
parent
12bf0a12f7
commit
2ef19a4876
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960" |
||||
android:tint="@color/white"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M240,920Q207,920 183.5,896.5Q160,873 160,840L160,400Q160,367 183.5,343.5Q207,320 240,320L360,320L360,400L240,400Q240,400 240,400Q240,400 240,400L240,840Q240,840 240,840Q240,840 240,840L720,840Q720,840 720,840Q720,840 720,840L720,400Q720,400 720,400Q720,400 720,400L600,400L600,320L720,320Q753,320 776.5,343.5Q800,367 800,400L800,840Q800,873 776.5,896.5Q753,920 720,920L240,920ZM440,640L440,193L376,257L320,200L480,40L640,200L584,257L520,193L520,640L440,640Z"/> |
||||
</vector> |
||||
@ -0,0 +1,15 @@ |
||||
<?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="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/selector_item" |
||||
android:ellipsize="marquee" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:singleLine="true" |
||||
android:gravity="center" |
||||
android:textColor="@color/text" |
||||
android:textSize="14sp" |
||||
tools:text="EXO" /> |
||||
@ -0,0 +1,52 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_margin="16dp" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
android:text="@string/player" |
||||
tools:text="選擇播放器" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/choose" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/selector_image" |
||||
android:padding="4dp" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:src="@drawable/ic_action_share" |
||||
android:visibility="visible" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<com.fongmi.android.tv.ui.custom.CustomRecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:paddingStart="16dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="16dp" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" |
||||
app:maxHeight="204dp" |
||||
tools:listitem="@layout/adapter_player" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,78 @@ |
||||
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.AdapterPlayerBinding; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class PlayerAdapter extends RecyclerView.Adapter<PlayerAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<Integer> mItems; |
||||
private final String[] mPlayers; |
||||
private int selected; |
||||
|
||||
public PlayerAdapter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
this.mPlayers = ResUtil.getStringArray(R.array.select_player); |
||||
this.mItems = new ArrayList<>(); |
||||
for(int i= 0; i<this.mPlayers.length; i++) this.mItems.add(i); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(Integer item); |
||||
} |
||||
|
||||
public void setSelected(int player) { |
||||
this.selected = player; |
||||
} |
||||
|
||||
public int getSelected() { |
||||
return this.selected; |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterPlayerBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Integer item = mItems.get(position); |
||||
holder.binding.text.setText(mPlayers[item]); |
||||
holder.binding.text.setActivated(item == selected); |
||||
} |
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
||||
|
||||
private final AdapterPlayerBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterPlayerBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
itemView.setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View view) { |
||||
Integer item = mItems.get(getLayoutPosition()); |
||||
mListener.onItemClick(item); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,94 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.fragment.app.Fragment; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.databinding.DialogPlayerBinding; |
||||
import com.fongmi.android.tv.ui.adapter.PlayerAdapter; |
||||
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; |
||||
|
||||
public class PlayerDialog extends BaseDialog implements PlayerAdapter.OnClickListener { |
||||
|
||||
private final PlayerAdapter adapter; |
||||
private DialogPlayerBinding binding; |
||||
private Listener listener; |
||||
private String title; |
||||
|
||||
|
||||
public static PlayerDialog create() { |
||||
return new PlayerDialog(); |
||||
} |
||||
|
||||
public PlayerDialog() { |
||||
this.adapter = new PlayerAdapter(this); |
||||
} |
||||
|
||||
public PlayerDialog select(int player) { |
||||
this.adapter.setSelected(player); |
||||
return this; |
||||
} |
||||
|
||||
public PlayerDialog title(String title) { |
||||
this.title = title; |
||||
return this; |
||||
} |
||||
|
||||
public void show(FragmentActivity activity) { |
||||
for (Fragment f : activity.getSupportFragmentManager().getFragments()) if (f instanceof BottomSheetDialogFragment) ((BottomSheetDialogFragment) f).dismiss(); |
||||
show(activity.getSupportFragmentManager(), null); |
||||
this.listener = (Listener) activity; |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
||||
return binding = DialogPlayerBinding.inflate(inflater, container, false); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
binding.recycler.setHasFixedSize(true); |
||||
binding.recycler.setAdapter(adapter); |
||||
binding.recycler.addItemDecoration(new SpaceItemDecoration(1, 16)); |
||||
binding.recycler.post(() -> binding.recycler.scrollToPosition(adapter.getSelected())); |
||||
binding.recycler.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE); |
||||
} |
||||
|
||||
@Override |
||||
protected void initEvent() { |
||||
binding.choose.setOnClickListener(this::onShare); |
||||
} |
||||
|
||||
private void onShare(View view) { |
||||
listener.onPlayerShare(title); |
||||
dismiss(); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemClick(Integer item) { |
||||
listener.onPlayerClick(item); |
||||
dismiss(); |
||||
} |
||||
|
||||
public interface Listener { |
||||
|
||||
void onPlayerClick(Integer item); |
||||
|
||||
void onPlayerShare(String title); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void onResume() { |
||||
super.onResume(); |
||||
getDialog().getWindow().setLayout(ResUtil.dp2px(320), -1); |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960" |
||||
android:tint="?attr/colorControlNormal"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M240,920Q207,920 183.5,896.5Q160,873 160,840L160,400Q160,367 183.5,343.5Q207,320 240,320L360,320L360,400L240,400Q240,400 240,400Q240,400 240,400L240,840Q240,840 240,840Q240,840 240,840L720,840Q720,840 720,840Q720,840 720,840L720,400Q720,400 720,400Q720,400 720,400L600,400L600,320L720,320Q753,320 776.5,343.5Q800,367 800,400L800,840Q800,873 776.5,896.5Q753,920 720,920L240,920ZM440,640L440,193L376,257L320,200L480,40L640,200L584,257L520,193L520,640L440,640Z"/> |
||||
</vector> |
||||
@ -0,0 +1,13 @@ |
||||
<?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="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/shape_accent" |
||||
android:ellipsize="marquee" |
||||
android:singleLine="true" |
||||
android:gravity="center" |
||||
android:textColor="@color/control" |
||||
android:textSize="14sp" |
||||
tools:text="EXO" /> |
||||
@ -0,0 +1,50 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_margin="16dp" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:textColor="?android:attr/textColorPrimary" |
||||
android:textSize="16sp" |
||||
android:text="@string/player" |
||||
tools:text="選擇播放器" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/choose" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:src="@drawable/ic_action_share" |
||||
android:visibility="visible" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<com.fongmi.android.tv.ui.custom.CustomRecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:paddingStart="16dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="16dp" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" |
||||
app:maxHeight="204dp" |
||||
tools:listitem="@layout/adapter_player" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue