Search in sources :

Example 1 with WebpageReader

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));
}
Also used : WebpageReader(com.moro.mtweaks.utils.WebpageReader) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

Example 2 with WebpageReader

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);
    }
}
Also used : DialogInterface(android.content.DialogInterface) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) RecyclerViewFragment(com.moro.mtweaks.fragments.RecyclerViewFragment) LMKFragment(com.moro.mtweaks.fragments.kernel.LMKFragment) BackupFragment(com.moro.mtweaks.fragments.tools.BackupFragment) BuildpropFragment(com.moro.mtweaks.fragments.tools.BuildpropFragment) RecyclerViewFragment(com.moro.mtweaks.fragments.RecyclerViewFragment) Fragment(android.support.v4.app.Fragment) ThermalFragment(com.moro.mtweaks.fragments.kernel.ThermalFragment) EntropyFragment(com.moro.mtweaks.fragments.kernel.EntropyFragment) OverallFragment(com.moro.mtweaks.fragments.statistics.OverallFragment) CPUVoltageCl0Fragment(com.moro.mtweaks.fragments.kernel.CPUVoltageCl0Fragment) ScreenFragment(com.moro.mtweaks.fragments.kernel.ScreenFragment) LEDFragment(com.moro.mtweaks.fragments.kernel.LEDFragment) CPUFragment(com.moro.mtweaks.fragments.kernel.CPUFragment) DeviceFragment(com.moro.mtweaks.fragments.statistics.DeviceFragment) MemoryFragment(com.moro.mtweaks.fragments.statistics.MemoryFragment) AboutFragment(com.moro.mtweaks.fragments.other.AboutFragment) InitdFragment(com.moro.mtweaks.fragments.tools.InitdFragment) RecoveryFragment(com.moro.mtweaks.fragments.tools.RecoveryFragment) WakelockFragment(com.moro.mtweaks.fragments.kernel.WakelockFragment) CPUVoltageCl1Fragment(com.moro.mtweaks.fragments.kernel.CPUVoltageCl1Fragment) SoundFragment(com.moro.mtweaks.fragments.kernel.SoundFragment) IOFragment(com.moro.mtweaks.fragments.kernel.IOFragment) DvfsFragment(com.moro.mtweaks.fragments.kernel.DvfsFragment) SpectrumFragment(com.moro.mtweaks.fragments.kernel.SpectrumFragment) MiscFragment(com.moro.mtweaks.fragments.kernel.MiscFragment) SettingsFragment(com.moro.mtweaks.fragments.other.SettingsFragment) CustomControlsFragment(com.moro.mtweaks.fragments.tools.customcontrols.CustomControlsFragment) BoefflaWakelockFragment(com.moro.mtweaks.fragments.kernel.BoefflaWakelockFragment) ContributorsFragment(com.moro.mtweaks.fragments.other.ContributorsFragment) ProfileFragment(com.moro.mtweaks.fragments.tools.ProfileFragment) GPUFragment(com.moro.mtweaks.fragments.kernel.GPUFragment) VMFragment(com.moro.mtweaks.fragments.kernel.VMFragment) DownloadsFragment(com.moro.mtweaks.fragments.tools.downloads.DownloadsFragment) DonationFragment(com.moro.mtweaks.fragments.other.DonationFragment) BaseFragment(com.moro.mtweaks.fragments.BaseFragment) KSMFragment(com.moro.mtweaks.fragments.kernel.KSMFragment) BatteryFragment(com.moro.mtweaks.fragments.kernel.BatteryFragment) InputsFragment(com.moro.mtweaks.fragments.statistics.InputsFragment) HmpFragment(com.moro.mtweaks.fragments.kernel.HmpFragment) OnBootFragment(com.moro.mtweaks.fragments.tools.OnBootFragment) CPUHotplugFragment(com.moro.mtweaks.fragments.kernel.CPUHotplugFragment) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) Monitor(com.moro.mtweaks.services.monitor.Monitor) WebpageReader(com.moro.mtweaks.utils.WebpageReader) Toolbar(android.support.v7.widget.Toolbar) AdNativeExpress(com.moro.mtweaks.views.AdNativeExpress)

Example 3 with WebpageReader

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");
    }
}
Also used : ContributorView(com.moro.mtweaks.views.recyclerview.ContributorView) WebpageReader(com.moro.mtweaks.utils.WebpageReader) Contributors(com.moro.mtweaks.utils.other.Contributors)

Example 4 with WebpageReader

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());
    }
}
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 5 with WebpageReader

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();
    }
}
Also used : WebpageReader(com.moro.mtweaks.utils.WebpageReader)

Aggregations

WebpageReader (com.moro.mtweaks.utils.WebpageReader)6 ArrayList (java.util.ArrayList)3 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 NavigationView (android.support.design.widget.NavigationView)1 Fragment (android.support.v4.app.Fragment)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 BaseFragment (com.moro.mtweaks.fragments.BaseFragment)1 RecyclerViewFragment (com.moro.mtweaks.fragments.RecyclerViewFragment)1 BatteryFragment (com.moro.mtweaks.fragments.kernel.BatteryFragment)1 BoefflaWakelockFragment (com.moro.mtweaks.fragments.kernel.BoefflaWakelockFragment)1 CPUFragment (com.moro.mtweaks.fragments.kernel.CPUFragment)1 CPUHotplugFragment (com.moro.mtweaks.fragments.kernel.CPUHotplugFragment)1 CPUVoltageCl0Fragment (com.moro.mtweaks.fragments.kernel.CPUVoltageCl0Fragment)1 CPUVoltageCl1Fragment (com.moro.mtweaks.fragments.kernel.CPUVoltageCl1Fragment)1 DvfsFragment (com.moro.mtweaks.fragments.kernel.DvfsFragment)1 EntropyFragment (com.moro.mtweaks.fragments.kernel.EntropyFragment)1 GPUFragment (com.moro.mtweaks.fragments.kernel.GPUFragment)1