parent
438d104644
commit
c01fbacb9e
@ -0,0 +1,31 @@ |
||||
package com.github.tvbox.osc.cache; |
||||
|
||||
import androidx.room.ColumnInfo; |
||||
import androidx.room.Entity; |
||||
import androidx.room.PrimaryKey; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Entity(tableName = "vodCollect") |
||||
public class VodCollect implements Serializable { |
||||
@PrimaryKey(autoGenerate = true) |
||||
private int id; |
||||
@ColumnInfo(name = "vodId") |
||||
public String vodId; |
||||
@ColumnInfo(name = "updateTime") |
||||
public long updateTime; |
||||
@ColumnInfo(name = "sourceKey") |
||||
public String sourceKey; |
||||
@ColumnInfo(name = "name") |
||||
public String name; |
||||
@ColumnInfo(name = "pic") |
||||
public String pic; |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(int id) { |
||||
this.id = id; |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
package com.github.tvbox.osc.cache; |
||||
|
||||
import androidx.room.Dao; |
||||
import androidx.room.Delete; |
||||
import androidx.room.Insert; |
||||
import androidx.room.OnConflictStrategy; |
||||
import androidx.room.Query; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author pj567 |
||||
* @date :2021/1/7 |
||||
* @description: |
||||
*/ |
||||
@Dao |
||||
public interface VodCollectDao { |
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) |
||||
long insert(VodCollect record); |
||||
|
||||
@Query("select * from vodCollect order by updateTime desc") |
||||
List<VodCollect> getAll(); |
||||
|
||||
@Query("select * from vodCollect where `id`=:id") |
||||
VodCollect getVodCollect(int id); |
||||
|
||||
@Query("delete from vodCollect where `id`=:id") |
||||
void delete(int id); |
||||
|
||||
@Query("select * from vodCollect where `sourceKey`=:sourceKey and `vodId`=:vodId") |
||||
VodCollect getVodCollect(String sourceKey, String vodId); |
||||
|
||||
@Delete |
||||
int delete(VodCollect record); |
||||
} |
||||
@ -0,0 +1,143 @@ |
||||
package com.github.tvbox.osc.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.graphics.Color; |
||||
import android.view.View; |
||||
import android.view.animation.BounceInterpolator; |
||||
import android.widget.TextView; |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter; |
||||
import com.github.tvbox.osc.R; |
||||
import com.github.tvbox.osc.base.BaseActivity; |
||||
import com.github.tvbox.osc.cache.RoomDataManger; |
||||
import com.github.tvbox.osc.cache.VodCollect; |
||||
import com.github.tvbox.osc.event.RefreshEvent; |
||||
import com.github.tvbox.osc.ui.adapter.CollectAdapter; |
||||
import com.github.tvbox.osc.util.FastClickCheckUtil; |
||||
import com.owen.tvrecyclerview.widget.TvRecyclerView; |
||||
import com.owen.tvrecyclerview.widget.V7GridLayoutManager; |
||||
|
||||
import org.greenrobot.eventbus.EventBus; |
||||
import org.greenrobot.eventbus.Subscribe; |
||||
import org.greenrobot.eventbus.ThreadMode; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class CollectActivity extends BaseActivity { |
||||
private TextView tvDel; |
||||
private TextView tvDelTip; |
||||
private TvRecyclerView mGridView; |
||||
private CollectAdapter collectAdapter; |
||||
private boolean delMode = false; |
||||
|
||||
@Override |
||||
protected int getLayoutResID() { |
||||
return R.layout.activity_collect; |
||||
} |
||||
|
||||
@Override |
||||
protected void init() { |
||||
initView(); |
||||
initData(); |
||||
} |
||||
|
||||
private void toggleDelMode() { |
||||
delMode = !delMode; |
||||
tvDelTip.setVisibility(delMode ? View.VISIBLE : View.GONE); |
||||
tvDel.setTextColor(delMode ? getResources().getColor(R.color.color_FF0057) : Color.WHITE); |
||||
} |
||||
|
||||
private void initView() { |
||||
EventBus.getDefault().register(this); |
||||
tvDel = findViewById(R.id.tvDel); |
||||
tvDelTip = findViewById(R.id.tvDelTip); |
||||
mGridView = findViewById(R.id.mGridView); |
||||
mGridView.setHasFixedSize(true); |
||||
mGridView.setLayoutManager(new V7GridLayoutManager(this.mContext, 5)); |
||||
collectAdapter = new CollectAdapter(); |
||||
mGridView.setAdapter(collectAdapter); |
||||
tvDel.setOnClickListener(new View.OnClickListener() { |
||||
@Override |
||||
public void onClick(View v) { |
||||
toggleDelMode(); |
||||
} |
||||
}); |
||||
mGridView.setOnInBorderKeyEventListener(new TvRecyclerView.OnInBorderKeyEventListener() { |
||||
@Override |
||||
public boolean onInBorderKeyEvent(int direction, View focused) { |
||||
if (direction == View.FOCUS_UP) { |
||||
tvDel.setFocusable(true); |
||||
tvDel.requestFocus(); |
||||
} |
||||
return false; |
||||
} |
||||
}); |
||||
mGridView.setOnItemListener(new TvRecyclerView.OnItemListener() { |
||||
@Override |
||||
public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) { |
||||
itemView.animate().scaleX(1.0f).scaleY(1.0f).setDuration(300).setInterpolator(new BounceInterpolator()).start(); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemSelected(TvRecyclerView parent, View itemView, int position) { |
||||
itemView.animate().scaleX(1.05f).scaleY(1.05f).setDuration(300).setInterpolator(new BounceInterpolator()).start(); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemClick(TvRecyclerView parent, View itemView, int position) { |
||||
|
||||
} |
||||
}); |
||||
collectAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { |
||||
@Override |
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { |
||||
FastClickCheckUtil.check(view); |
||||
VodCollect vodInfo = collectAdapter.getData().get(position); |
||||
if (vodInfo != null) { |
||||
if (delMode) { |
||||
collectAdapter.remove(position); |
||||
RoomDataManger.deleteVodCollect(vodInfo.getId()); |
||||
} else { |
||||
Intent newIntent = new Intent(mContext, SearchActivity.class); |
||||
newIntent.putExtra("title", vodInfo.name); |
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
||||
startActivity(newIntent); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initData() { |
||||
List<VodCollect> allVodRecord = RoomDataManger.getAllVodCollect(); |
||||
List<VodCollect> vodInfoList = new ArrayList<>(); |
||||
for (VodCollect vodInfo : allVodRecord) { |
||||
vodInfoList.add(vodInfo); |
||||
} |
||||
collectAdapter.setNewData(vodInfoList); |
||||
} |
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void refresh(RefreshEvent event) { |
||||
if (event.type == RefreshEvent.TYPE_HISTORY_REFRESH) { |
||||
initData(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
EventBus.getDefault().unregister(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onBackPressed() { |
||||
if (delMode) { |
||||
toggleDelMode(); |
||||
return; |
||||
} |
||||
super.onBackPressed(); |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
package com.github.tvbox.osc.ui.adapter; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.widget.ImageView; |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter; |
||||
import com.chad.library.adapter.base.BaseViewHolder; |
||||
import com.github.tvbox.osc.R; |
||||
import com.github.tvbox.osc.cache.VodCollect; |
||||
import com.github.tvbox.osc.picasso.RoundTransformation; |
||||
import com.github.tvbox.osc.util.MD5; |
||||
import com.squareup.picasso.Picasso; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils; |
||||
|
||||
public class CollectAdapter extends BaseQuickAdapter<VodCollect, BaseViewHolder> { |
||||
public CollectAdapter() { |
||||
super(R.layout.item_grid, new ArrayList<>()); |
||||
} |
||||
|
||||
@Override |
||||
protected void convert(BaseViewHolder helper, VodCollect item) { |
||||
helper.setVisible(R.id.tvYear, false); |
||||
helper.setVisible(R.id.tvLang, false); |
||||
helper.setVisible(R.id.tvArea, false); |
||||
helper.setVisible(R.id.tvNote, false); |
||||
helper.setText(R.id.tvName, item.name); |
||||
ImageView ivThumb = helper.getView(R.id.ivThumb); |
||||
//由于部分电视机使用glide报错
|
||||
if (!TextUtils.isEmpty(item.pic)) { |
||||
Picasso.get() |
||||
.load(item.pic) |
||||
.transform(new RoundTransformation(MD5.string2MD5(item.pic + item.name)) |
||||
.centerCorp(true) |
||||
.override(AutoSizeUtils.mm2px(mContext, 300), AutoSizeUtils.mm2px(mContext, 400)) |
||||
.roundRadius(AutoSizeUtils.mm2px(mContext, 10), RoundTransformation.RoundType.ALL)) |
||||
.placeholder(R.drawable.img_loading_placeholder) |
||||
.error(R.drawable.img_loading_placeholder) |
||||
.into(ivThumb); |
||||
} else { |
||||
ivThumb.setImageResource(R.drawable.img_loading_placeholder); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:orientation="horizontal" |
||||
android:paddingLeft="@dimen/vs_50" |
||||
android:paddingTop="@dimen/vs_20" |
||||
android:paddingRight="@dimen/vs_50" |
||||
android:paddingBottom="@dimen/vs_20"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="@dimen/vs_50" |
||||
android:drawablePadding="@dimen/vs_10" |
||||
android:gravity="center" |
||||
android:text="收藏夹" |
||||
android:textColor="@android:color/white" |
||||
android:textSize="@dimen/ts_34" |
||||
android:textStyle="bold" /> |
||||
|
||||
<Space |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tvDelTip" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="@dimen/vs_50" |
||||
android:layout_gravity="center" |
||||
android:layout_marginRight="@dimen/vs_10" |
||||
android:focusable="false" |
||||
android:focusableInTouchMode="false" |
||||
android:gravity="center" |
||||
android:text="确定键删除当前选中收藏" |
||||
android:textColor="@android:color/white" |
||||
android:textSize="@dimen/ts_24" |
||||
android:visibility="gone" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tvDel" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:background="@drawable/shape_user_focus" |
||||
android:focusable="false" |
||||
android:focusableInTouchMode="false" |
||||
android:gravity="center" |
||||
android:padding="@dimen/vs_10" |
||||
android:text="删除收藏" |
||||
android:textColor="@android:color/white" |
||||
android:textSize="@dimen/ts_24" /> |
||||
</LinearLayout> |
||||
|
||||
<com.owen.tvrecyclerview.widget.TvRecyclerView |
||||
android:id="@+id/mGridView" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:paddingLeft="@dimen/vs_60" |
||||
android:paddingTop="@dimen/vs_10" |
||||
android:paddingRight="@dimen/vs_60" |
||||
android:paddingBottom="@dimen/vs_10" |
||||
app:tv_horizontalSpacingWithMargins="@dimen/vs_10" |
||||
app:tv_selectedItemIsCentered="true" |
||||
app:tv_verticalSpacingWithMargins="@dimen/vs_10" /> |
||||
</LinearLayout> |
||||
Loading…
Reference in new issue