use of com.moro.mtweaks.utils.WebpageReader in project MTweaks-KernelAdiutorMOD by morogoku.
the class ServerSearchDevice method getBoards.
public void getBoards(final BoardSearchListener boardSearchListener) {
mBoardReader = new WebpageReader(mActivity, new WebpageReader.WebpageListener() {
@Override
public void onSuccess(String url, String raw, CharSequence html) {
try {
JSONArray boards = new JSONArray(raw);
List<String> list = new ArrayList<>();
for (int i = 0; i < boards.length(); i++) {
list.add(boards.getString(i));
}
Collections.sort(list);
boardSearchListener.onBoardResult(list);
} catch (JSONException ignored) {
boardSearchListener.onBoardFailure();
}
}
@Override
public void onFailure(String url) {
boardSearchListener.onBoardFailure();
}
});
mBoardReader.get(getAddress(BOARD_GET));
}
use of com.moro.mtweaks.utils.WebpageReader in project MTweaks-KernelAdiutorMOD by morogoku.
the class NavigationActivity method init.
private void init(Bundle savedInstanceState) {
int result = Prefs.getInt("license", -1, this);
int intentResult = getIntent().getIntExtra("result", -1);
if ((result == intentResult && (result == 1 || result == 2)) && mLicenseDialog) {
ViewUtils.dialogBuilder(getString(R.string.license_invalid), null, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mLicenseDialog = false;
Prefs.saveInt("license", -1, NavigationActivity.this);
}
}, this).show();
} else if ((result != intentResult || result == 3) && mLicenseDialog) {
ViewUtils.dialogBuilder(getString(R.string.pirated), null, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mLicenseDialog = false;
Prefs.saveInt("license", -1, NavigationActivity.this);
}
}, this).show();
} else {
mLicenseDialog = false;
if (result == 0) {
Utils.DONATED = true;
}
}
sCallback = new Callback() {
@Override
public void onBannerResize() {
Fragment fragment = sActualFragments.get(mSelection);
if (fragment instanceof RecyclerViewFragment) {
((RecyclerViewFragment) fragment).resizeBanner();
}
}
};
setContentView(R.layout.activity_navigation);
Toolbar toolbar = getToolBar();
setSupportActionBar(toolbar);
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, toolbar, 0, 0);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
mNavigationView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
v.clearFocus();
}
}
});
appendFragments(false);
if (savedInstanceState != null) {
mSelection = savedInstanceState.getInt("selection");
mLicenseDialog = savedInstanceState.getBoolean("license");
mFetchingAds = savedInstanceState.getBoolean("fetching_ads");
}
String section = getIntent().getStringExtra("section");
if (section != null) {
for (int id : sActualFragments.keySet()) {
if (sActualFragments.get(id) != null && sActualFragments.get(id).getClass().getCanonicalName().equals(section)) {
mSelection = id;
break;
}
}
getIntent().removeExtra("section");
}
if (mSelection == 0 || !sActualFragments.containsKey(mSelection)) {
mSelection = firstTab();
}
onItemSelected(mSelection, false, false);
if (Prefs.getBoolean("data_sharing", true, this)) {
startService(new Intent(this, Monitor.class));
}
if (!mFetchingAds && !Utils.DONATED) {
mFetchingAds = true;
mAdsFetcher = new WebpageReader(this, new WebpageReader.WebpageListener() {
@Override
public void onSuccess(String url, String raw, CharSequence html) {
AdNativeExpress.GHAds ghAds = new AdNativeExpress.GHAds(raw);
if (ghAds.readable()) {
ghAds.cache(NavigationActivity.this);
for (int id : sActualFragments.keySet()) {
Fragment fragment = sActualFragments.get(id);
if (fragment instanceof RecyclerViewFragment) {
((RecyclerViewFragment) fragment).ghAdReady();
}
}
}
}
@Override
public void onFailure(String url) {
}
});
mAdsFetcher.get(AdNativeExpress.ADS_FETCH);
}
}
use of com.moro.mtweaks.utils.WebpageReader in project MTweaks-KernelAdiutorMOD by morogoku.
the class ContributorsFragment method postInit.
@Override
protected void postInit() {
super.postInit();
showProgress();
if (mWebpageReader == null) {
mWebpageReader = new WebpageReader(getActivity(), new WebpageReader.WebpageListener() {
@Override
public void onSuccess(String url, String raw, CharSequence html) {
if (!isAdded())
return;
hideProgress();
Contributors contributors = new Contributors(raw);
if (contributors.readable()) {
for (final Contributors.Contributor contributor : contributors.getContributors()) {
if (contributor.getLogin().equals("Grarak")) {
continue;
}
addItem(new ContributorView(contributor));
}
} else {
error();
}
}
@Override
public void onFailure(String url) {
error();
}
});
mWebpageReader.get("https://api.github.com/repos/Grarak/KernelAdiutor/contributors");
}
}
use of com.moro.mtweaks.utils.WebpageReader 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());
}
}
use of com.moro.mtweaks.utils.WebpageReader in project MTweaks-KernelAdiutorMOD by morogoku.
the class DownloadsFragment method onDestroy.
@Override
public void onDestroy() {
super.onDestroy();
if (mWebpageReader != null) {
mWebpageReader.cancel();
mWebpageReader = null;
}
if (mErrorBar != null) {
mErrorBar.dismiss();
mErrorBar = null;
}
for (WebpageReader reader : mKernelWebpageReader) {
reader.cancel();
}
}
Aggregations