mirror of https://github.com/FongMi/TV.git
commit
013886cae4
@ -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(); |
||||
} |
||||
|
||||
} |
||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 861 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
@ -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> |
||||
@ -1,18 +1,16 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<item android:state_focused="true"> |
||||
<shape android:shape="oval"> |
||||
<solid android:color="@color/blue_500"/> |
||||
<shape android:shape="oval"> |
||||
<stroke |
||||
android:width="1.5dp" |
||||
android:color="@color/white" /> |
||||
<solid android:color="@color/black_20"/> |
||||
</shape> |
||||
</item> |
||||
<item android:state_activated="true"> |
||||
<shape android:shape="oval"> |
||||
<solid android:color="@color/grey_600"/> |
||||
</shape> |
||||
</item> |
||||
<item > |
||||
<shape android:shape="oval"> |
||||
<solid android:color="@color/grey_600"/> |
||||
<item> |
||||
<shape android:shape="oval"> |
||||
<solid android:color="@color/black_20"/> |
||||
</shape> |
||||
</item> |
||||
</selector> |
||||
@ -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