Search in sources :

Example 1 with NavigationActivity

use of com.moro.mtweaks.activities.NavigationActivity 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;
}
Also used : BaseActivity(com.moro.mtweaks.activities.BaseActivity) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Activity(android.app.Activity) RecyclerViewAdapter(com.moro.mtweaks.views.recyclerview.RecyclerViewAdapter) Fragment(android.support.v4.app.Fragment) FragmentTransaction(android.support.v4.app.FragmentTransaction) SupportAnimator(io.codetail.animation.SupportAnimator) ArrayList(java.util.ArrayList) List(java.util.List) AdView(com.moro.mtweaks.views.recyclerview.AdView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) AdView(com.moro.mtweaks.views.recyclerview.AdView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Nullable(android.support.annotation.Nullable)

Example 2 with NavigationActivity

use of com.moro.mtweaks.activities.NavigationActivity in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    boolean checked = (boolean) o;
    String key = preference.getKey();
    switch(key) {
        case KEY_UPDATE_NOTIFICATION:
            Prefs.saveBoolean("show_update_notif", checked, getActivity());
            return true;
        case KEY_FORCE_ENGLISH:
            if (!checked) {
                Utils.setLocale(Resources.getSystem().getConfiguration().locale.getLanguage(), getActivity());
            }
        case KEY_DARK_THEME:
            getActivity().finish();
            Intent intent = new Intent(getActivity(), MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return true;
        /*
            case KEY_MATERIAL_ICON:
                Utils.setStartActivity(checked, getActivity());
                return true;
            */
        case KEY_HIDE_BANNER:
            if (!Utils.DONATED) {
                ViewUtils.dialogDonate(getActivity()).show();
                return false;
            }
            return true;
        default:
            if (key.equals(KEY_SECTIONS_ICON) || key.endsWith("_enabled")) {
                if (key.equals(KEY_SECTIONS_ICON) && !Utils.DONATED) {
                    ViewUtils.dialogDonate(getActivity()).show();
                    return false;
                }
                Prefs.saveBoolean(key, checked, getActivity());
                ((NavigationActivity) getActivity()).appendFragments();
                return true;
            }
            break;
    }
    return false;
}
Also used : Intent(android.content.Intent) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity)

Aggregations

NavigationActivity (com.moro.mtweaks.activities.NavigationActivity)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BaseActivity (com.moro.mtweaks.activities.BaseActivity)1 AdView (com.moro.mtweaks.views.recyclerview.AdView)1 RecyclerViewAdapter (com.moro.mtweaks.views.recyclerview.RecyclerViewAdapter)1 RecyclerViewItem (com.moro.mtweaks.views.recyclerview.RecyclerViewItem)1 SupportAnimator (io.codetail.animation.SupportAnimator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1