mirror of https://github.com/FongMi/TV.git
parent
fe66bc94dc
commit
a2fc0a04cb
@ -0,0 +1,105 @@ |
||||
package com.fongmi.android.tv.ui.activity; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Intent; |
||||
import android.view.View; |
||||
import androidx.recyclerview.widget.GridLayoutManager; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.Product; |
||||
import com.fongmi.android.tv.bean.History; |
||||
import com.fongmi.android.tv.databinding.ActivityHistoryBinding; |
||||
import com.fongmi.android.tv.event.RefreshEvent; |
||||
import com.fongmi.android.tv.ui.adapter.HistoryAdapter; |
||||
import com.fongmi.android.tv.ui.base.BaseActivity; |
||||
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; |
||||
|
||||
import org.greenrobot.eventbus.Subscribe; |
||||
import org.greenrobot.eventbus.ThreadMode; |
||||
|
||||
public class HistoryActivity extends BaseActivity implements HistoryAdapter.OnClickListener { |
||||
|
||||
private ActivityHistoryBinding mBinding; |
||||
|
||||
private HistoryAdapter mAdapter; |
||||
|
||||
public static void start(Activity activity) { |
||||
activity.startActivity(new Intent(activity, HistoryActivity.class)); |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding() { |
||||
return mBinding = ActivityHistoryBinding.inflate(getLayoutInflater()); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
setRecyclerView(); |
||||
getHistory(); |
||||
} |
||||
|
||||
@Override |
||||
protected void initEvent() { |
||||
mBinding.delete.setOnClickListener(this::onDelete); |
||||
} |
||||
|
||||
private void setRecyclerView() { |
||||
mBinding.recycler.setHasFixedSize(true); |
||||
mBinding.recycler.setItemAnimator(null); |
||||
mBinding.recycler.setAdapter(mAdapter = new HistoryAdapter(this)); |
||||
mBinding.recycler.setLayoutManager(new GridLayoutManager(this, Product.getColumn())); |
||||
mBinding.recycler.addItemDecoration(new SpaceItemDecoration(Product.getColumn(), 16)); |
||||
} |
||||
|
||||
private void getHistory() { |
||||
mAdapter.addAll(History.get()); |
||||
mBinding.delete.setVisibility(mAdapter.getItemCount() > 0 ? View.VISIBLE : View.GONE); |
||||
} |
||||
|
||||
private void onDelete(View view) { |
||||
if (mAdapter.isDelete()) { |
||||
mAdapter.clear(); |
||||
} else if (mAdapter.getItemCount() > 0) { |
||||
mAdapter.setDelete(true); |
||||
} else { |
||||
mBinding.delete.setVisibility(View.GONE); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onItemClick(History item) { |
||||
VideoActivity.start(this, item.getSiteKey(), item.getVodId(), item.getVodName(), item.getVodPic()); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemDelete(History item) { |
||||
mAdapter.delete(item.delete()); |
||||
if (mAdapter.getItemCount() == 0) mAdapter.setDelete(false); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onLongClick() { |
||||
mAdapter.setDelete(true); |
||||
return true; |
||||
} |
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void onRefreshEvent(RefreshEvent event) { |
||||
super.onRefreshEvent(event); |
||||
switch (event.getType()) { |
||||
case HISTORY: |
||||
getHistory(); |
||||
break; |
||||
case SIZE: |
||||
getHistory(); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onBackPressed() { |
||||
if (mAdapter.isDelete()) mAdapter.setDelete(false); |
||||
else super.onBackPressed(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="48dp" |
||||
android:height="48dp" |
||||
android:tint="#FFFFFF" |
||||
android:viewportWidth="24" |
||||
android:viewportHeight="24"> |
||||
<path |
||||
android:fillColor="#FFFFFF" |
||||
android:pathData="M16,9v10H8V9h8m-1.5,-6h-5l-1,1H5v2h14V4h-3.5l-1,-1zM18,7H6v12c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7z" /> |
||||
</vector> |
||||
@ -0,0 +1,12 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="48dp" |
||||
android:height="48dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:pathData="M554.75,341.33a42.67,42.67 0,1 0,-85.33 0v170.84a42.67,42.67 0,0 0,12.5 30.17l106.58,106.5a42.67,42.67 0,1 0,60.33 -60.33L554.67,494.46V341.33z" |
||||
android:fillColor="#ffffff"/> |
||||
<path |
||||
android:pathData="M273.66,267.65h36.65a42.67,42.67 0,1 1,0 85.33H170.67a42.67,42.67 0,0 1,-42.67 -42.67V170.67a42.67,42.67 0,0 1,85.33 0v36.65A425.39,425.39 0,0 1,512 85.33c235.65,0 426.67,191.02 426.67,426.67s-191.02,426.67 -426.67,426.67S85.33,747.65 85.33,512a42.67,42.67 0,1 1,85.33 0,341.33 341.33,0 1,0 103,-244.35z" |
||||
android:fillColor="#ffffff"/> |
||||
</vector> |
||||
@ -0,0 +1,52 @@ |
||||
<?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="match_parent" |
||||
android:keepScreenOn="true" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/toolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingStart="24dp" |
||||
android:paddingTop="24dp" |
||||
android:paddingEnd="24dp" |
||||
android:paddingBottom="16dp" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:layout_gravity="start" |
||||
android:text="@string/home_history" |
||||
android:textColor="@color/white" |
||||
android:textSize="24sp" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/delete" |
||||
android:layout_width="32dp" |
||||
android:layout_height="32dp" |
||||
android:background="@drawable/selector_image" |
||||
android:src="@drawable/ic_action_delete" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" /> |
||||
|
||||
|
||||
</LinearLayout> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:paddingStart="24dp" |
||||
android:paddingEnd="24dp" |
||||
android:paddingBottom="24dp" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
Loading…
Reference in new issue