|
|
|
|
@ -3,16 +3,22 @@ package com.fongmi.android.tv.ui.activity; |
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
|
|
import androidx.viewbinding.ViewBinding; |
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.Product; |
|
|
|
|
import com.fongmi.android.tv.R; |
|
|
|
|
import com.fongmi.android.tv.api.ApiConfig; |
|
|
|
|
import com.fongmi.android.tv.bean.Config; |
|
|
|
|
import com.fongmi.android.tv.bean.Keep; |
|
|
|
|
import com.fongmi.android.tv.databinding.ActivityKeepBinding; |
|
|
|
|
import com.fongmi.android.tv.event.RefreshEvent; |
|
|
|
|
import com.fongmi.android.tv.net.Callback; |
|
|
|
|
import com.fongmi.android.tv.ui.adapter.KeepAdapter; |
|
|
|
|
import com.fongmi.android.tv.ui.base.BaseActivity; |
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.Subscribe; |
|
|
|
|
import org.greenrobot.eventbus.ThreadMode; |
|
|
|
|
@ -39,7 +45,7 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void initEvent() { |
|
|
|
|
|
|
|
|
|
mBinding.delete.setOnClickListener(this::onDelete); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setRecyclerView() { |
|
|
|
|
@ -54,8 +60,29 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis |
|
|
|
|
mAdapter.addAll(Keep.getVod()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setDelete(boolean delete) { |
|
|
|
|
mAdapter.setDelete(delete); |
|
|
|
|
private void onDelete(View view) { |
|
|
|
|
if (mAdapter.isDelete()) { |
|
|
|
|
new MaterialAlertDialogBuilder(this).setMessage(R.string.ask_keep_delete).setNegativeButton(R.string.dialog_negative, null).setPositiveButton(R.string.dialog_positive, (dialog, which) -> mAdapter.clear()).show(); |
|
|
|
|
} else if (mAdapter.getItemCount() > 0) { |
|
|
|
|
mAdapter.setDelete(true); |
|
|
|
|
} else { |
|
|
|
|
mBinding.delete.setVisibility(View.GONE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void loadConfig(Config config, Keep item) { |
|
|
|
|
ApiConfig.get().clear().config(config).load(true, new Callback() { |
|
|
|
|
@Override |
|
|
|
|
public void success() { |
|
|
|
|
DetailActivity.start(getActivity(), item.getSiteKey(), item.getVodId(), item.getVodName()); |
|
|
|
|
RefreshEvent.video(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void error(int resId) { |
|
|
|
|
CollectActivity.start(getActivity(), item.getVodName()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN) |
|
|
|
|
@ -65,18 +92,26 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onItemClick(Keep item) { |
|
|
|
|
DetailActivity.start(this, item.getSiteKey(), item.getVodId(), item.getVodName()); |
|
|
|
|
Config config = Config.find(item.getCid()); |
|
|
|
|
if (item.getCid() != ApiConfig.getCid()) loadConfig(config, item); |
|
|
|
|
else DetailActivity.start(this, item.getSiteKey(), item.getVodId(), item.getVodName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onItemDelete(Keep item) { |
|
|
|
|
mAdapter.remove(item.delete()); |
|
|
|
|
if (mAdapter.getItemCount() == 0) setDelete(false); |
|
|
|
|
if (mAdapter.getItemCount() == 0) mAdapter.setDelete(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onLongClick() { |
|
|
|
|
setDelete(!mAdapter.isDelete()); |
|
|
|
|
mAdapter.setDelete(!mAdapter.isDelete()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onBackPressed() { |
|
|
|
|
if (mAdapter.isDelete()) mAdapter.setDelete(false); |
|
|
|
|
else super.onBackPressed(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|