use of com.moro.mtweaks.views.recyclerview.RecyclerViewAdapter in project MTweaks-KernelAdiutorMOD by morogoku.
the class RecyclerViewFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
if (mHandler == null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mHandler = new Handler();
}
});
}
mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerview);
if (mViewPagerFragments != null && !hideBanner()) {
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
for (Fragment fragment : mViewPagerFragments) {
fragmentTransaction.remove(fragment);
}
fragmentTransaction.commit();
mViewPagerFragments.clear();
} else {
mViewPagerFragments = new ArrayList<>();
}
mViewPagerParent = mRootView.findViewById(R.id.viewpagerparent);
mViewPager = (ViewPager) mRootView.findViewById(R.id.viewpager);
mViewPager.setVisibility(View.INVISIBLE);
mViewPagerShadow = mRootView.findViewById(R.id.viewpager_shadow);
mViewPagerShadow.setVisibility(View.INVISIBLE);
mCirclePageIndicator = (CirclePageIndicator) mRootView.findViewById(R.id.indicator);
resizeBanner();
mViewPagerParent.setVisibility(View.INVISIBLE);
ViewUtils.dismissDialog(getChildFragmentManager());
mProgress = mRootView.findViewById(R.id.progress);
mAppBarLayout = ((BaseActivity) getActivity()).getAppBarLayout();
mToolBar = ((BaseActivity) getActivity()).getToolBar();
if (mAppBarLayout != null && !isForeground()) {
mAppBarLayout.postDelayed(new Runnable() {
@Override
public void run() {
if (mAppBarLayout != null && isAdded() && getActivity() != null) {
ViewCompat.setElevation(mAppBarLayout, showViewPager() && !hideBanner() ? 0 : getResources().getDimension(R.dimen.app_bar_elevation));
}
}
}, 150);
}
mTopFab = (FloatingActionButton) mRootView.findViewById(R.id.top_fab);
mBottomFab = (FloatingActionButton) mRootView.findViewById(R.id.bottom_fab);
mRecyclerView.clearOnScrollListeners();
if (showViewPager() && !hideBanner()) {
mScroller = new Scroller();
mRecyclerView.addOnScrollListener(mScroller);
}
mRecyclerView.setAdapter(mRecyclerViewAdapter == null ? mRecyclerViewAdapter = new RecyclerViewAdapter(mItems, new RecyclerViewAdapter.OnViewChangedListener() {
@Override
public void viewChanged() {
getHandler().postDelayed(new Runnable() {
@Override
public void run() {
if (isAdded() && getActivity() != null) {
adjustScrollPosition();
}
}
}, 250);
}
}) : mRecyclerViewAdapter);
mRecyclerView.setLayoutManager(mLayoutManager = getLayoutManager());
if (!Utils.DONATED && !showTopFab() && !isForeground() && getActivity() instanceof NavigationActivity && showAd() && mAdView == null) {
mAdView = new AdView();
} else {
mAdView = null;
}
mTopFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onTopFabClick();
}
});
{
Drawable drawable;
if ((drawable = getTopFabDrawable()) != null) {
mTopFab.setImageDrawable(drawable);
}
}
mBottomFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBottomFabClick();
}
});
{
Drawable drawable;
if ((drawable = getBottomFabDrawable()) != null) {
mBottomFab.setImageDrawable(drawable);
}
}
BaseFragment foregroundFragment = getForegroundFragment();
mForegroundVisible = false;
if (foregroundFragment != null) {
mForegroundParent = mRootView.findViewById(R.id.foreground_parent);
mForegroundText = (TextView) mRootView.findViewById(R.id.foreground_text);
mForegroundText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissForeground();
}
});
getChildFragmentManager().beginTransaction().replace(R.id.foreground_content, foregroundFragment).commit();
mForegroundHeight = getResources().getDisplayMetrics().heightPixels;
}
if (itemsSize() == 0) {
mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgress();
init();
}
@Override
protected List<RecyclerViewItem> doInBackground(Void... params) {
if (mDelay && needDelay()) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
mDelay = false;
}
if (isAdded() && getActivity() != null) {
List<RecyclerViewItem> items = new ArrayList<>();
addItems(items);
return items;
}
return null;
}
@Override
protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
super.onPostExecute(recyclerViewItems);
if (isCancelled() || recyclerViewItems == null)
return;
for (RecyclerViewItem item : recyclerViewItems) {
addItem(item);
}
hideProgress();
postInit();
mRecyclerView.post(new Runnable() {
@Override
public void run() {
Activity activity;
if ((activity = getActivity()) != null) {
mRecyclerView.scrollToPosition(0);
mLayoutManager.scrollToPosition(0);
mRecyclerView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.slide_in_bottom));
}
}
});
if (savedInstanceState == null) {
mViewPager.post(new Runnable() {
@Override
public void run() {
if (getActivity() != null) {
int cx = mViewPager.getWidth();
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(mViewPager, cx / 2, 0, 0, cx);
animator.addListener(new SupportAnimator.SimpleAnimatorListener() {
@Override
public void onAnimationStart() {
super.onAnimationStart();
mViewPager.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd() {
super.onAnimationEnd();
mViewPagerShadow.setVisibility(View.VISIBLE);
}
});
animator.setDuration(400);
animator.start();
}
}
});
} else {
mViewPager.setVisibility(View.VISIBLE);
mViewPagerShadow.setVisibility(View.VISIBLE);
}
mLoader = null;
}
};
mLoader.execute();
} else {
showProgress();
init();
hideProgress();
postInit();
adjustScrollPosition();
mViewPager.setVisibility(View.VISIBLE);
mViewPagerShadow.setVisibility(View.VISIBLE);
}
return mRootView;
}
Aggregations