-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FongMi#351 from okcaptain/dev
Dev
- Loading branch information
Showing
15 changed files
with
279 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/leanback/java/com/fongmi/android/tv/ui/adapter/DisplayAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/leanback/java/com/fongmi/android/tv/ui/dialog/DisplayDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.