Search in sources :

Example 1 with KernelItemView

use of com.moro.mtweaks.views.recyclerview.downloads.KernelItemView 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)

Aggregations

WebpageReader (com.moro.mtweaks.utils.WebpageReader)1 SupportedDownloads (com.moro.mtweaks.utils.tools.SupportedDownloads)1 RecyclerViewItem (com.moro.mtweaks.views.recyclerview.RecyclerViewItem)1 KernelItemView (com.moro.mtweaks.views.recyclerview.downloads.KernelItemView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1