mirror of https://github.com/FongMi/TV.git
parent
0b8ba42c33
commit
3b1c956f39
@ -0,0 +1,77 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.databinding.AdapterRestoreBinding; |
||||
import com.github.catvod.utils.Path; |
||||
|
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class RestoreAdapter extends RecyclerView.Adapter<RestoreAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<File> mItems; |
||||
|
||||
public RestoreAdapter(OnClickListener listener) { |
||||
this.mItems = new ArrayList<>(); |
||||
this.mListener = listener; |
||||
this.addAll(); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(File item); |
||||
|
||||
void onDeleteClick(File item); |
||||
} |
||||
|
||||
public void addAll() { |
||||
File[] files = Path.tv().listFiles(); |
||||
if (files == null || files.length == 0) return; |
||||
for (File file : files) if (file.getName().startsWith("tv") && file.getName().endsWith(".bk.gz")) mItems.add(file); |
||||
notifyDataSetChanged(); |
||||
} |
||||
|
||||
public void remove(File item) { |
||||
int position = mItems.indexOf(item); |
||||
if (position == -1) return; |
||||
Path.clear(item); |
||||
mItems.remove(position); |
||||
notifyItemRemoved(position); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterRestoreBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
File item = mItems.get(position); |
||||
holder.binding.text.setText(item.getName()); |
||||
holder.binding.text.setOnClickListener(v -> mListener.onItemClick(item)); |
||||
holder.binding.delete.setOnClickListener(v -> mListener.onDeleteClick(item)); |
||||
} |
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterRestoreBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterRestoreBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
<?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="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text" |
||||
android:layout_width="0dp" |
||||
android:layout_height="40dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:ellipsize="middle" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:text="tv-2024-12-26.bk.gz" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/delete" |
||||
android:layout_width="40dp" |
||||
android:layout_height="40dp" |
||||
android:layout_marginStart="12dp" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:padding="8dp" |
||||
android:scaleType="fitCenter" |
||||
android:src="@drawable/ic_setting_delete" /> |
||||
|
||||
</LinearLayout> |
||||
@ -1,47 +1,9 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
<com.fongmi.android.tv.ui.custom.CustomRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:padding="24dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="16dp" |
||||
android:text="@string/dialog_restore_msg" |
||||
android:textColor="@color/grey_900" |
||||
android:textSize="16sp" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/positive" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:text="@string/dialog_positive" |
||||
android:textColor="@color/white" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/negative" |
||||
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" |
||||
android:text="@string/dialog_negative" |
||||
android:textColor="@color/white" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
android:padding="16dp" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" |
||||
app:maxHeight="352dp" /> |
||||
@ -1,6 +0,0 @@ |
||||
package com.fongmi.android.tv.impl; |
||||
|
||||
public interface RestoreCallback { |
||||
|
||||
void onRestore(); |
||||
} |
||||
Loading…
Reference in new issue