mirror of https://github.com/FongMi/TV.git
parent
2c6e56c574
commit
25c55dc72e
@ -0,0 +1,68 @@ |
||||
package com.fongmi.android.tv.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.net.Uri; |
||||
|
||||
import androidx.leanback.widget.ArrayObjectAdapter; |
||||
import androidx.leanback.widget.ItemBridgeAdapter; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.databinding.ActivityPickerBinding; |
||||
import com.fongmi.android.tv.ui.base.BaseActivity; |
||||
import com.fongmi.android.tv.ui.presenter.PickPresenter; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.github.catvod.utils.Path; |
||||
|
||||
import java.io.File; |
||||
|
||||
public class PickerActivity extends BaseActivity implements PickPresenter.OnClickListener { |
||||
|
||||
private ActivityPickerBinding mBinding; |
||||
private ArrayObjectAdapter mAdapter; |
||||
private File dir; |
||||
|
||||
private boolean isRoot() { |
||||
return Path.root().equals(dir); |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding() { |
||||
return mBinding = ActivityPickerBinding.inflate(getLayoutInflater()); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
setRecyclerView(); |
||||
update(Path.root()); |
||||
} |
||||
|
||||
private void setRecyclerView() { |
||||
mBinding.recycler.setHasFixedSize(true); |
||||
mBinding.recycler.setVerticalSpacing(ResUtil.dp2px(16)); |
||||
mBinding.recycler.setAdapter(new ItemBridgeAdapter(mAdapter = new ArrayObjectAdapter(new PickPresenter(this)))); |
||||
} |
||||
|
||||
private void update(File dir) { |
||||
mBinding.recycler.setSelectedPosition(0); |
||||
mAdapter.setItems(Path.list(this.dir = dir), null); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemClick(File file) { |
||||
if (file.isDirectory()) { |
||||
update(file); |
||||
} else { |
||||
setResult(RESULT_OK, new Intent().setData(Uri.fromFile(file))); |
||||
finish(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onBackPressed() { |
||||
if (isRoot()) { |
||||
super.onBackPressed(); |
||||
} else { |
||||
update(dir.getParentFile()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
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.R; |
||||
import com.fongmi.android.tv.databinding.AdapterPickerBinding; |
||||
|
||||
import java.io.File; |
||||
|
||||
public class PickPresenter extends Presenter { |
||||
|
||||
private final OnClickListener mListener; |
||||
|
||||
public PickPresenter(OnClickListener listener) { |
||||
this.mListener = listener; |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(File file); |
||||
} |
||||
|
||||
@Override |
||||
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { |
||||
return new ViewHolder(AdapterPickerBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object object) { |
||||
File file = (File) object; |
||||
ViewHolder holder = (ViewHolder) viewHolder; |
||||
holder.binding.name.setText(file.getName()); |
||||
holder.binding.getRoot().setOnClickListener(v -> mListener.onItemClick(file)); |
||||
holder.binding.image.setImageResource(file.isDirectory() ? R.drawable.ic_picker_folder : R.drawable.ic_picker_file); |
||||
} |
||||
|
||||
@Override |
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { |
||||
} |
||||
|
||||
public static class ViewHolder extends Presenter.ViewHolder { |
||||
|
||||
private final AdapterPickerBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterPickerBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/white" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M320,720L640,720L640,640L320,640L320,720ZM320,560L640,560L640,480L320,480L320,560ZM240,880Q207,880 183.5,856.5Q160,833 160,800L160,160Q160,127 183.5,103.5Q207,80 240,80L560,80L800,320L800,800Q800,833 776.5,856.5Q753,880 720,880L240,880ZM520,360L720,360L520,160L520,360Z" /> |
||||
</vector> |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/amber_300" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L400,160L480,240L800,240Q833,240 856.5,263.5Q880,287 880,320L880,720Q880,753 856.5,776.5Q833,800 800,800L160,800Z" /> |
||||
</vector> |
||||
@ -0,0 +1,36 @@ |
||||
<?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="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/shape_vod_list" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:foreground="@drawable/selector_vod"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView |
||||
android:id="@+id/image" |
||||
android:layout_width="48dp" |
||||
android:layout_height="48dp" |
||||
android:layout_margin="16dp" |
||||
android:scaleType="fitCenter" |
||||
tools:src="@drawable/ic_picker_folder" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/name" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="Download" /> |
||||
|
||||
</LinearLayout> |
||||
</FrameLayout> |
||||
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.leanback.widget.VerticalGridView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:padding="24dp" /> |
||||
|
||||
</FrameLayout> |
||||
Loading…
Reference in new issue