|
|
|
@ -1,6 +1,5 @@ |
|
|
|
package com.fongmi.android.tv.ui.fragment; |
|
|
|
package com.fongmi.android.tv.ui.fragment; |
|
|
|
|
|
|
|
|
|
|
|
import android.animation.ValueAnimator; |
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.Menu; |
|
|
|
import android.view.Menu; |
|
|
|
@ -44,8 +43,7 @@ public class CollectFragment extends BaseFragment implements MenuProvider, Colle |
|
|
|
private CustomScroller mScroller; |
|
|
|
private CustomScroller mScroller; |
|
|
|
private SiteViewModel mViewModel; |
|
|
|
private SiteViewModel mViewModel; |
|
|
|
private PauseExecutor mExecutor; |
|
|
|
private PauseExecutor mExecutor; |
|
|
|
private ValueAnimator mAnimator; |
|
|
|
private List<Site> sites; |
|
|
|
private int maxWidth; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static CollectFragment newInstance(String keyword) { |
|
|
|
public static CollectFragment newInstance(String keyword) { |
|
|
|
Bundle args = new Bundle(); |
|
|
|
Bundle args = new Bundle(); |
|
|
|
@ -76,11 +74,11 @@ public class CollectFragment extends BaseFragment implements MenuProvider, Colle |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void initView() { |
|
|
|
protected void initView() { |
|
|
|
maxWidth = ResUtil.getScreenWidth() / (getCount() + 1) - ResUtil.dp2px(32); |
|
|
|
|
|
|
|
mScroller = new CustomScroller(this); |
|
|
|
mScroller = new CustomScroller(this); |
|
|
|
setRecyclerView(); |
|
|
|
setRecyclerView(); |
|
|
|
setViewModel(); |
|
|
|
setViewModel(); |
|
|
|
setAnimator(); |
|
|
|
setSites(); |
|
|
|
|
|
|
|
setWidth(); |
|
|
|
search(); |
|
|
|
search(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -100,23 +98,25 @@ public class CollectFragment extends BaseFragment implements MenuProvider, Colle |
|
|
|
mViewModel.result.observe(this, this::setSearch); |
|
|
|
mViewModel.result.observe(this, this::setSearch); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setAnimator() { |
|
|
|
private void setSites() { |
|
|
|
mAnimator = new ValueAnimator(); |
|
|
|
sites = new ArrayList<>(); |
|
|
|
mAnimator.addUpdateListener(animation -> { |
|
|
|
for (Site site : VodConfig.get().getSites()) if (site.isSearchable()) sites.add(site); |
|
|
|
ViewGroup.LayoutParams params = mBinding.collect.getLayoutParams(); |
|
|
|
|
|
|
|
params.width = (Integer) animation.getAnimatedValue(); |
|
|
|
|
|
|
|
mBinding.collect.setLayoutParams(params); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Site> getSites() { |
|
|
|
private void setWidth() { |
|
|
|
List<Site> items = new ArrayList<>(); |
|
|
|
int width = 0; |
|
|
|
for (Site site : VodConfig.get().getSites()) if (site.isSearchable()) items.add(site); |
|
|
|
int space = ResUtil.dp2px(48); |
|
|
|
return items; |
|
|
|
int maxWidth = ResUtil.getScreenWidth() / (getCount() + 1) - ResUtil.dp2px(32); |
|
|
|
|
|
|
|
for (Site site : sites) width = Math.max(width, ResUtil.getTextWidth(site.getName(), 14)); |
|
|
|
|
|
|
|
int contentWidth = width + space; |
|
|
|
|
|
|
|
int minWidth = ResUtil.dp2px(120); |
|
|
|
|
|
|
|
int finalWidth = Math.max(minWidth, Math.min(contentWidth, maxWidth)); |
|
|
|
|
|
|
|
ViewGroup.LayoutParams params = mBinding.collect.getLayoutParams(); |
|
|
|
|
|
|
|
params.width = finalWidth; |
|
|
|
|
|
|
|
mBinding.collect.setLayoutParams(params); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void search() { |
|
|
|
private void search() { |
|
|
|
List<Site> sites = getSites(); |
|
|
|
|
|
|
|
if (sites.isEmpty()) return; |
|
|
|
if (sites.isEmpty()) return; |
|
|
|
if (mExecutor != null) mExecutor.shutdownNow(); |
|
|
|
if (mExecutor != null) mExecutor.shutdownNow(); |
|
|
|
mExecutor = new PauseExecutor(20, sites.size()); |
|
|
|
mExecutor = new PauseExecutor(20, sites.size()); |
|
|
|
@ -141,25 +141,10 @@ public class CollectFragment extends BaseFragment implements MenuProvider, Colle |
|
|
|
private void setCollect(Result result) { |
|
|
|
private void setCollect(Result result) { |
|
|
|
if (result == null) return; |
|
|
|
if (result == null) return; |
|
|
|
if (mCollectAdapter.getPosition() == 0) mSearchAdapter.addAll(result.getList()); |
|
|
|
if (mCollectAdapter.getPosition() == 0) mSearchAdapter.addAll(result.getList()); |
|
|
|
mCollectAdapter.add(Collect.create(result.getList()), this::setWidth); |
|
|
|
mCollectAdapter.add(Collect.create(result.getList())); |
|
|
|
mCollectAdapter.add(result.getList()); |
|
|
|
mCollectAdapter.add(result.getList()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setWidth() { |
|
|
|
|
|
|
|
int maxTextWidth = 0; |
|
|
|
|
|
|
|
int space = ResUtil.dp2px(48); |
|
|
|
|
|
|
|
for (Collect item : mCollectAdapter.getItems()) maxTextWidth = Math.max(maxTextWidth, ResUtil.getTextWidth(item.getSite().getName(), 14)); |
|
|
|
|
|
|
|
int contentWidth = maxTextWidth + space; |
|
|
|
|
|
|
|
int minWidth = ResUtil.dp2px(120); |
|
|
|
|
|
|
|
int finalWidth = Math.max(minWidth, Math.min(contentWidth, maxWidth)); |
|
|
|
|
|
|
|
int startWidth = mBinding.collect.getWidth(); |
|
|
|
|
|
|
|
if (finalWidth == startWidth) return; |
|
|
|
|
|
|
|
if (mAnimator.isRunning()) mAnimator.cancel(); |
|
|
|
|
|
|
|
mAnimator.setIntValues(startWidth, finalWidth); |
|
|
|
|
|
|
|
mAnimator.setDuration(300); |
|
|
|
|
|
|
|
mAnimator.start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setSearch(Result result) { |
|
|
|
private void setSearch(Result result) { |
|
|
|
if (result == null) return; |
|
|
|
if (result == null) return; |
|
|
|
boolean same = !result.getList().isEmpty() && mCollectAdapter.getActivated().getSite().equals(result.getList().get(0).getSite()); |
|
|
|
boolean same = !result.getList().isEmpty() && mCollectAdapter.getActivated().getSite().equals(result.getList().get(0).getSite()); |
|
|
|
|