Search in sources :

Example 31 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class ProfileFragment method reload.

private void reload() {
    if (mLoader == null) {
        getHandler().postDelayed(new Runnable() {

            @Override
            public void run() {
                clearItems();
                mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        showProgress();
                    }

                    @Override
                    protected List<RecyclerViewItem> doInBackground(Void... voids) {
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> items) {
                        super.onPostExecute(items);
                        for (RecyclerViewItem item : items) {
                            addItem(item);
                        }
                        hideProgress();
                        mLoader = null;
                    }
                };
                mLoader.execute();
            }
        }, 250);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 32 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class DownloadsFragment method postInit.

@Override
protected void postInit() {
    super.postInit();
    if (mWebpageReader == null && mSupport != null) {
        showProgress();
        mWebpageReader = new WebpageReader(getActivity(), new WebpageReader.WebpageListener() {

            private int mKernelCount;

            @Override
            public void onSuccess(String url, String raw, CharSequence html) {
                if (!isAdded())
                    return;
                hideProgress();
                final SupportedDownloads.Kernels kernels = new SupportedDownloads.Kernels(raw);
                mKernelWebpageReader.clear();
                final List<SupportedDownloads.KernelContent> contents = new ArrayList<>();
                if (kernels.readable()) {
                    for (int i = 0; i < kernels.length(); i++) {
                        WebpageReader reader = new WebpageReader(getActivity(), new WebpageReader.WebpageListener() {

                            @Override
                            public void onSuccess(String url, String raw, CharSequence html) {
                                if (!isAdded())
                                    return;
                                mKernelCount++;
                                SupportedDownloads.KernelContent content = new SupportedDownloads.KernelContent(raw);
                                if (content.readable()) {
                                    contents.add(content);
                                }
                                if (mKernelCount == kernels.length()) {
                                    addViews(contents);
                                }
                            }

                            @Override
                            public void onFailure(String url) {
                            }
                        });
                        reader.get(kernels.getLink(i));
                        mKernelWebpageReader.add(reader);
                    }
                } else {
                    error();
                }
            }

            @Override
            public void onFailure(String url) {
                error();
            }

            private void addViews(List<SupportedDownloads.KernelContent> contents) {
                if (contents.size() > 0) {
                    for (final SupportedDownloads.KernelContent content : contents) {
                        String n = content.getName();
                        if (n != null && content.getLogo() != null && content.getShortDescription() != null && content.getLongDescription() != null) {
                            KernelItemView kernelItemView = new KernelItemView(content);
                            kernelItemView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                                @Override
                                public void onClick(RecyclerViewItem item) {
                                    mKernelContent = content;
                                    requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                                }
                            });
                            addItem(kernelItemView);
                        }
                    }
                    hideProgress();
                } else {
                    error();
                }
            }
        });
        mWebpageReader.get(mSupport.getLink());
    }
}
Also used : SupportedDownloads(com.moro.mtweaks.utils.tools.SupportedDownloads) ArrayList(java.util.ArrayList) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) WebpageReader(com.moro.mtweaks.utils.WebpageReader) ArrayList(java.util.ArrayList) List(java.util.List) KernelItemView(com.moro.mtweaks.views.recyclerview.downloads.KernelItemView)

Example 33 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class RecyclerViewFragment method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    mItems.clear();
    mRecyclerViewAdapter = null;
    setAppBarLayoutAlpha(255);
    if (mAppBarLayout != null && !isForeground()) {
        mAppBarLayout.setTranslationY(0);
        ViewCompat.setElevation(mAppBarLayout, 0);
    }
    if (mLoader != null) {
        mLoader.cancel(true);
        mLoader = null;
    }
    if (mHandler != null) {
        mHandler.removeCallbacks(mRefresh);
    }
    mAdView = null;
    for (RecyclerViewItem item : mItems) {
        item.onDestroy();
    }
}
Also used : RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 34 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class RecyclerViewFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    mHandler.post(mRefresh);
    for (RecyclerViewItem item : mItems) {
        item.onResume();
    }
}
Also used : RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 35 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class CPUFragment method cpuQuietInit.

private void cpuQuietInit(List<RecyclerViewItem> items) {
    List<RecyclerViewItem> views = new ArrayList<>();
    CardView cpuQuietCard = new CardView(getActivity());
    cpuQuietCard.setTitle(getString(R.string.cpu_quiet));
    if (Misc.hasCpuQuietEnable()) {
        SwitchView cpuQuietEnable = new SwitchView();
        cpuQuietEnable.setSummary(getString(R.string.cpu_quiet));
        cpuQuietEnable.setChecked(Misc.isCpuQuietEnabled());
        cpuQuietEnable.addOnSwitchListener(new SwitchView.OnSwitchListener() {

            @Override
            public void onChanged(SwitchView switchView, boolean isChecked) {
                Misc.enableCpuQuiet(isChecked, getActivity());
            }
        });
        views.add(cpuQuietEnable);
    }
    if (Misc.hasCpuQuietGovernors()) {
        SelectView cpuQuietGovernors = new SelectView();
        cpuQuietGovernors.setSummary(getString(R.string.cpu_quiet_governor));
        cpuQuietGovernors.setItems(Misc.getCpuQuietAvailableGovernors());
        cpuQuietGovernors.setItem(Misc.getCpuQuietCurGovernor());
        cpuQuietGovernors.setOnItemSelected(new SelectView.OnItemSelected() {

            @Override
            public void onItemSelected(SelectView selectView, int position, String item) {
                Misc.setCpuQuietGovernor(item, getActivity());
            }
        });
        views.add(cpuQuietGovernors);
    }
    if (views.size() > 0) {
        DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(getString(R.string.cpu_quiet_summary));
        cpuQuietCard.addItem(descriptionView);
        for (RecyclerViewItem item : views) {
            cpuQuietCard.addItem(item);
        }
        items.add(cpuQuietCard);
    }
}
Also used : SwitchView(com.moro.mtweaks.views.recyclerview.SwitchView) ArrayList(java.util.ArrayList) CardView(com.moro.mtweaks.views.recyclerview.CardView) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) SelectView(com.moro.mtweaks.views.recyclerview.SelectView)

Aggregations

RecyclerViewItem (com.moro.mtweaks.views.recyclerview.RecyclerViewItem)42 ArrayList (java.util.ArrayList)26 TitleView (com.moro.mtweaks.views.recyclerview.TitleView)18 DescriptionView (com.moro.mtweaks.views.recyclerview.DescriptionView)16 SwitchView (com.moro.mtweaks.views.recyclerview.SwitchView)15 SeekBarView (com.moro.mtweaks.views.recyclerview.SeekBarView)14 CardView (com.moro.mtweaks.views.recyclerview.CardView)9 List (java.util.List)9 SelectView (com.moro.mtweaks.views.recyclerview.SelectView)8 AsyncTask (android.os.AsyncTask)6 DialogInterface (android.content.DialogInterface)5 Intent (android.content.Intent)3 Activity (android.app.Activity)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 PopupMenu (android.support.v7.widget.PopupMenu)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 Profiles (com.moro.mtweaks.database.tools.profiles.Profiles)2 Dialog (com.moro.mtweaks.views.dialog.Dialog)2 ProgressDialog (android.app.ProgressDialog)1