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());
}
}
Aggregations