|
|
|
|
@ -18,13 +18,11 @@ import androidx.viewbinding.ViewBinding; |
|
|
|
|
import androidx.viewpager.widget.ViewPager; |
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide; |
|
|
|
|
import com.fongmi.android.tv.App; |
|
|
|
|
import com.fongmi.android.tv.R; |
|
|
|
|
import com.fongmi.android.tv.Setting; |
|
|
|
|
import com.fongmi.android.tv.api.config.VodConfig; |
|
|
|
|
import com.fongmi.android.tv.bean.Class; |
|
|
|
|
import com.fongmi.android.tv.bean.Config; |
|
|
|
|
import com.fongmi.android.tv.bean.Hot; |
|
|
|
|
import com.fongmi.android.tv.bean.Result; |
|
|
|
|
import com.fongmi.android.tv.bean.Site; |
|
|
|
|
import com.fongmi.android.tv.bean.Value; |
|
|
|
|
@ -52,32 +50,21 @@ import com.fongmi.android.tv.utils.FileChooser; |
|
|
|
|
import com.fongmi.android.tv.utils.FileUtil; |
|
|
|
|
import com.fongmi.android.tv.utils.Notify; |
|
|
|
|
import com.fongmi.android.tv.utils.ResUtil; |
|
|
|
|
import com.github.catvod.net.OkHttp; |
|
|
|
|
import com.github.catvod.utils.Trans; |
|
|
|
|
import com.google.common.net.HttpHeaders; |
|
|
|
|
import com.permissionx.guolindev.PermissionX; |
|
|
|
|
import java.security.SecureRandom; |
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus; |
|
|
|
|
import org.greenrobot.eventbus.Subscribe; |
|
|
|
|
import org.greenrobot.eventbus.ThreadMode; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
|
|
import okhttp3.Call; |
|
|
|
|
import okhttp3.Headers; |
|
|
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
|
public class VodFragment extends BaseFragment implements SiteCallback, FilterCallback, TypeAdapter.OnClickListener, ConfigCallback { |
|
|
|
|
|
|
|
|
|
private FragmentVodBinding mBinding; |
|
|
|
|
private SiteViewModel mViewModel; |
|
|
|
|
private TypeAdapter mAdapter; |
|
|
|
|
private Runnable mRunnable; |
|
|
|
|
private List<String> mHots; |
|
|
|
|
private Result mResult; |
|
|
|
|
|
|
|
|
|
public static VodFragment newInstance() { |
|
|
|
|
@ -101,21 +88,17 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
protected void initView() { |
|
|
|
|
EventBus.getDefault().register(this); |
|
|
|
|
setRecyclerView(); |
|
|
|
|
setAppBarView(); |
|
|
|
|
setViewModel(); |
|
|
|
|
showProgress(); |
|
|
|
|
initHot(); |
|
|
|
|
getHot(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void initEvent() { |
|
|
|
|
mBinding.hot.setOnClickListener(this::onHot); |
|
|
|
|
mBinding.top.setOnClickListener(this::onTop); |
|
|
|
|
mBinding.link.setOnClickListener(this::onLink); |
|
|
|
|
mBinding.logo.setOnClickListener(this::onLogo); |
|
|
|
|
mBinding.logo.setOnLongClickListener(this::onRefresh); |
|
|
|
|
mBinding.settingVodHistory.setOnClickListener(this::onSettingVodHistory); |
|
|
|
|
mBinding.site.setOnClickListener(this::onSite); |
|
|
|
|
mBinding.keep.setOnClickListener(this::onKeep); |
|
|
|
|
mBinding.retry.setOnClickListener(this::onRetry); |
|
|
|
|
mBinding.filter.setOnClickListener(this::onFilter); |
|
|
|
|
@ -131,8 +114,9 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setAppBarView() { |
|
|
|
|
mBinding.settingVodHistory.setVisibility(Setting.isHomeChangeConfig() ? View.VISIBLE : View.GONE); |
|
|
|
|
private void setSiteText() { |
|
|
|
|
String site = getSite().getName(); |
|
|
|
|
mBinding.site.setText(site); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setRecyclerView() { |
|
|
|
|
@ -147,26 +131,6 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
mViewModel.result.observe(getViewLifecycleOwner(), result -> setAdapter(mResult = result)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initHot() { |
|
|
|
|
mHots = Hot.get(Setting.getHot()); |
|
|
|
|
App.post(mRunnable = this::updateHot, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getHot() { |
|
|
|
|
OkHttp.newCall("https://api.web.360kan.com/v1/rank?cat=1", Headers.of(HttpHeaders.REFERER, "https://www.360kan.com/rank/general")).enqueue(new Callback() { |
|
|
|
|
@Override |
|
|
|
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { |
|
|
|
|
mHots = Hot.get(response.body().string()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateHot() { |
|
|
|
|
App.post(mRunnable, 10 * 1000); |
|
|
|
|
if (mHots.isEmpty() || mHots.size() < 10) return; |
|
|
|
|
mBinding.hot.setText(mHots.get(new SecureRandom().nextInt(11))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Result handle(Result result) { |
|
|
|
|
List<Class> types = new ArrayList<>(); |
|
|
|
|
for (Class type : result.getTypes()) if (result.getFilters().containsKey(type.getTypeId())) type.setFilters(result.getFilters().get(type.getTypeId())); |
|
|
|
|
@ -215,6 +179,11 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onLogo(View view) { |
|
|
|
|
if (Setting.isHomeChangeConfig()) HistoryDialog.create(this).type(0).show(); |
|
|
|
|
else SiteDialog.create(this).change().show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onSite(View view) { |
|
|
|
|
SiteDialog.create(this).change().show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -228,10 +197,6 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onSettingVodHistory(View view) { |
|
|
|
|
HistoryDialog.create(this).type(0).show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onKeep(View view) { |
|
|
|
|
KeepActivity.start(getActivity()); |
|
|
|
|
} |
|
|
|
|
@ -244,12 +209,8 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
if (mAdapter.getItemCount() > 0) FilterDialog.create().filter(mAdapter.get(mBinding.pager.getCurrentItem()).getFilters()).show(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onHot(View view) { |
|
|
|
|
CollectActivity.start(getActivity()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onSearch(View view) { |
|
|
|
|
CollectActivity.start(getActivity(), mBinding.hot.getText().toString()); |
|
|
|
|
CollectActivity.start(getActivity(), ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onHistory(View view) { |
|
|
|
|
@ -266,6 +227,7 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void homeContent() { |
|
|
|
|
setSiteText(); |
|
|
|
|
showProgress(); |
|
|
|
|
setFabVisible(0); |
|
|
|
|
mAdapter.clear(); |
|
|
|
|
@ -336,7 +298,6 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
homeContent(); |
|
|
|
|
break; |
|
|
|
|
case CONFIG: |
|
|
|
|
setAppBarView(); |
|
|
|
|
setLogo(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
@ -362,6 +323,7 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
@Override |
|
|
|
|
public void setSite(Site item) { |
|
|
|
|
VodConfig.get().setHome(item); |
|
|
|
|
setSiteText(); |
|
|
|
|
homeContent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -397,7 +359,6 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal |
|
|
|
|
@Override |
|
|
|
|
public void onDestroyView() { |
|
|
|
|
super.onDestroyView(); |
|
|
|
|
App.removeCallbacks(mRunnable); |
|
|
|
|
EventBus.getDefault().unregister(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|