mirror of https://github.com/FongMi/TV.git
commit
8cf0bc9102
@ -0,0 +1,93 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.Gravity; |
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.AdapterDisplayBinding; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class DisplayAdapter extends RecyclerView.Adapter<DisplayAdapter.ViewHolder> { |
||||
|
||||
private List<String> mItems; |
||||
|
||||
public DisplayAdapter() { |
||||
mItems = new ArrayList<>(); |
||||
mItems.add(ResUtil.getString(R.string.play_time)); |
||||
mItems.add(ResUtil.getString(R.string.play_netspeed)); |
||||
mItems.add(ResUtil.getString(R.string.play_duration)); |
||||
mItems.add(ResUtil.getString(R.string.play_mini_progress)); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterDisplayBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
String name = mItems.get(position); |
||||
holder.binding.text.setText(name); |
||||
holder.binding.check.setChecked(getChecked(position)); |
||||
holder.binding.select.setOnLongClickListener(v -> onItemLongClick(position)); |
||||
holder.binding.select.setOnClickListener(v -> onItemClick(position)); |
||||
holder.binding.text.setGravity(Gravity.CENTER); |
||||
} |
||||
|
||||
private boolean getChecked(int position) { |
||||
if (position == 0) return Setting.isDisplayTime(); |
||||
else if (position == 1) return Setting.isDisplaySpeed(); |
||||
else if (position == 2) return Setting.isDisplayDuration(); |
||||
else if (position == 3) return Setting.isDisplayMiniProgress(); |
||||
return false; |
||||
} |
||||
|
||||
private void onItemClick(int position) { |
||||
if (position == 0) Setting.putDisplayTime(!Setting.isDisplayTime()); |
||||
else if (position == 1) Setting.putDisplaySpeed(!Setting.isDisplaySpeed()); |
||||
else if (position == 2) Setting.putDisplayDuration(!Setting.isDisplayDuration()); |
||||
else if (position == 3) Setting.putDisplayMiniProgress(!Setting.isDisplayMiniProgress()); |
||||
notifyItemRangeChanged(0, getItemCount()); |
||||
} |
||||
|
||||
private boolean onItemLongClick(int position) { |
||||
boolean checked = false; |
||||
if (position == 0) checked = Setting.isDisplayTime(); |
||||
else if (position == 1) checked = Setting.isDisplaySpeed(); |
||||
else if (position == 2) checked = Setting.isDisplayDuration(); |
||||
else if (position == 3) checked = Setting.isDisplayMiniProgress(); |
||||
Setting.putDisplayTime(!checked); |
||||
Setting.putDisplaySpeed(!checked); |
||||
Setting.putDisplayDuration(!checked); |
||||
Setting.putDisplayMiniProgress(!checked); |
||||
notifyItemRangeChanged(0, getItemCount()); |
||||
return true; |
||||
} |
||||
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterDisplayBinding binding; |
||||
|
||||
ViewHolder(@NonNull AdapterDisplayBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.app.Activity; |
||||
import android.view.LayoutInflater; |
||||
import android.view.WindowManager; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.recyclerview.widget.GridLayoutManager; |
||||
|
||||
import com.fongmi.android.tv.databinding.DialogDisplayBinding; |
||||
import com.fongmi.android.tv.ui.adapter.DisplayAdapter; |
||||
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class DisplayDialog { |
||||
private final DialogDisplayBinding binding; |
||||
private final DisplayAdapter adapter; |
||||
private final AlertDialog dialog; |
||||
|
||||
|
||||
public static DisplayDialog create(Activity activity) { |
||||
return new DisplayDialog(activity); |
||||
} |
||||
|
||||
public DisplayDialog(Activity activity) { |
||||
this.adapter = new DisplayAdapter(); |
||||
this.binding = DialogDisplayBinding.inflate(LayoutInflater.from(activity)); |
||||
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initView() { |
||||
setRecyclerView(); |
||||
setDialog(); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
|
||||
} |
||||
|
||||
private void setRecyclerView() { |
||||
binding.recycler.setAdapter(adapter); |
||||
binding.recycler.setHasFixedSize(true); |
||||
binding.recycler.setItemAnimator(null); |
||||
binding.recycler.addItemDecoration(new SpaceItemDecoration(1, 16)); |
||||
binding.recycler.setLayoutManager(new GridLayoutManager(dialog.getContext(), 1)); |
||||
binding.recycler.post(() -> binding.recycler.scrollToPosition(0)); |
||||
|
||||
} |
||||
|
||||
private void setDialog() { |
||||
if (adapter.getItemCount() == 0) return; |
||||
WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); |
||||
params.width = (int) (ResUtil.getScreenWidth() * 0.4f); |
||||
dialog.getWindow().setAttributes(params); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
} |
||||
@ -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="match_parent" |
||||
android:layout_height="40dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/select" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
<TextView |
||||
android:id="@+id/text" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="18sp" |
||||
tools:text="時間" /> |
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox |
||||
android:id="@+id/check" |
||||
android:layout_width="24dp" |
||||
android:layout_height="24dp" |
||||
android:layout_marginStart="12dp" |
||||
android:buttonTint="@color/white" |
||||
android:clickable="false" |
||||
android:enabled="false" |
||||
android:focusable="false" |
||||
android:focusableInTouchMode="false" /> |
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,18 @@ |
||||
<?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="horizontal" |
||||
android:padding="16dp"> |
||||
|
||||
<com.fongmi.android.tv.ui.custom.CustomRecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
app:maxHeight="264dp" |
||||
tools:itemCount="5" |
||||
tools:listitem="@layout/adapter_display" /> |
||||
</LinearLayout> |
||||
Loading…
Reference in new issue