mirror of https://github.com/FongMi/TV.git
parent
768e92acab
commit
91f41186cc
@ -1,36 +1,37 @@ |
||||
package com.fongmi.bear.ui.adapter; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.fragment.app.Fragment; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
import androidx.viewpager2.adapter.FragmentStateAdapter; |
||||
import androidx.fragment.app.FragmentManager; |
||||
import androidx.fragment.app.FragmentStatePagerAdapter; |
||||
|
||||
import com.fongmi.bear.bean.Class; |
||||
import com.fongmi.bear.bean.Filter; |
||||
import com.fongmi.bear.bean.Result; |
||||
import com.fongmi.bear.ui.fragment.VodFragment; |
||||
|
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
public class PageAdapter extends FragmentStatePagerAdapter { |
||||
|
||||
public class PageAdapter extends FragmentStateAdapter { |
||||
private final Result mResult; |
||||
|
||||
private final List<Class> mItems; |
||||
private final LinkedHashMap<String, List<Filter>> mFilters; |
||||
public PageAdapter(@NonNull FragmentManager fm, Result result) { |
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); |
||||
mResult = result; |
||||
} |
||||
|
||||
public PageAdapter(@NonNull FragmentActivity activity, List<Class> items, LinkedHashMap<String, List<Filter>> filters) { |
||||
super(activity); |
||||
mItems = items; |
||||
mFilters = filters; |
||||
@Nullable |
||||
@Override |
||||
public CharSequence getPageTitle(int position) { |
||||
return mResult.getTypes().get(position).getTypeName(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public Fragment createFragment(int position) { |
||||
return VodFragment.newInstance(mItems.get(position).getTypeId(), mFilters.get(mItems.get(position).getTypeId())); |
||||
public Fragment getItem(int position) { |
||||
return VodFragment.newInstance(mResult.getTypes().get(position).getTypeId(), mResult.getFilters().get(mResult.getTypes().get(position).getTypeId())); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
public int getCount() { |
||||
return mResult.getTypes().size(); |
||||
} |
||||
} |
||||
@ -1,47 +0,0 @@ |
||||
package com.fongmi.bear.ui.custom; |
||||
|
||||
import android.graphics.Rect; |
||||
import android.view.View; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.bear.utils.ResUtil; |
||||
|
||||
public class SpaceItemDecoration extends RecyclerView.ItemDecoration { |
||||
|
||||
private final boolean includeEdge; |
||||
private final int spanCount; |
||||
private final int spacing; |
||||
private final int headerNum; |
||||
|
||||
public SpaceItemDecoration(int spanCount, int spacing, boolean includeEdge, int headerNum) { |
||||
this.spanCount = spanCount; |
||||
this.spacing = ResUtil.dp2px(spacing); |
||||
this.includeEdge = includeEdge; |
||||
this.headerNum = headerNum; |
||||
} |
||||
|
||||
@Override |
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, RecyclerView parent, @NonNull RecyclerView.State state) { |
||||
int position = parent.getChildAdapterPosition(view) - headerNum; |
||||
if (position >= 0) { |
||||
int column = position % spanCount; |
||||
if (includeEdge) { |
||||
outRect.left = spacing - column * spacing / spanCount; |
||||
outRect.right = (column + 1) * spacing / spanCount; |
||||
if (position < spanCount) outRect.top = spacing; |
||||
outRect.bottom = spacing; |
||||
} else { |
||||
outRect.left = column * spacing / spanCount; |
||||
outRect.right = spacing - (column + 1) * spacing / spanCount; |
||||
if (position >= spanCount) outRect.top = spacing; |
||||
} |
||||
} else { |
||||
outRect.left = 0; |
||||
outRect.right = 0; |
||||
outRect.top = 0; |
||||
outRect.bottom = 0; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue