Search in sources :

Example 1 with OTALink

use of com.crdroid.settings.fragments.about.update.xml.OTALink in project android_packages_apps_crDroidSettings by crdroidandroid.

the class Update method updateLinks.

private void updateLinks(boolean force) {
    Context context = getActivity().getApplicationContext();
    List<OTALink> links = LinkConfig.getInstance().getLinks(context, force);
    Drawable drawable = context.getDrawable(R.drawable.ic_web);
    TypedArray ta = context.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
    drawable.setTint(ta.getColor(0, 0));
    if (mLinksCategory == null)
        return;
    for (OTALink link : links) {
        String id = link.getId();
        if (id.equalsIgnoreCase(DOWNLOAD_TAG) || id.equalsIgnoreCase(CHANGELOG_TAG) || id.equalsIgnoreCase(GAPPS_TAG) || id.equalsIgnoreCase(FORUM_TAG) || id.equalsIgnoreCase(PAYPAL_TAG) || id.equalsIgnoreCase(TELEGRAM_TAG)) {
            continue;
        }
        PreferenceScreen linkPref = (PreferenceScreen) getPreferenceScreen().findPreference(id.toLowerCase());
        if (linkPref == null) {
            linkPref = getPreferenceManager().createPreferenceScreen(context);
            linkPref.setKey(id.toLowerCase());
            linkPref.setIcon(drawable);
            mLinksCategory.addPreference(linkPref);
        }
        if (linkPref != null) {
            String title = link.getTitle();
            linkPref.setTitle(title.isEmpty() ? id : title);
            linkPref.setSummary(link.getDescription());
        }
    }
    mLinksCategory.setTitle(mShowLinks ? context.getString(R.string.links_category) : "");
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink)

Example 2 with OTALink

use of com.crdroid.settings.fragments.about.update.xml.OTALink in project android_packages_apps_crDroidSettings by crdroidandroid.

the class Update method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    final String key = preference.getKey();
    if (preference == mUpdateInterval)
        return super.onPreferenceTreeClick(preference);
    Context context = getActivity().getApplicationContext();
    if (preference == mCheckUpdate) {
        mTask = CheckUpdateTask.getInstance(false);
        if (!mTask.getStatus().equals(AsyncTask.Status.RUNNING)) {
            mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, context);
        }
        return true;
    }
    OTALink link = LinkConfig.getInstance().findLink(key, context);
    if (link != null) {
        OTAUtils.launchUrl(link.getUrl(), context);
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : Context(android.content.Context) OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink)

Example 3 with OTALink

use of com.crdroid.settings.fragments.about.update.xml.OTALink in project android_packages_apps_crDroidSettings by crdroidandroid.

the class Update method updateDownloadLinks.

private static void updateDownloadLinks(Context context) {
    List<OTALink> links = LinkConfig.getInstance().getLinks(context, true);
    if (mLinksCategory == null)
        return;
    mDownloadLink.setVisible(false);
    mChangelogLink.setVisible(false);
    mGappsLink.setVisible(false);
    mForumLink.setVisible(false);
    mPayPalLink.setVisible(false);
    mTelegramLink.setVisible(false);
    for (OTALink link : links) {
        String id = link.getId();
        if (id.equalsIgnoreCase(DOWNLOAD_TAG)) {
            mDownloadLink.setTitle(link.getTitle());
            mDownloadLink.setSummary(link.getDescription());
            mDownloadLink.setVisible(mShowLinks);
        } else if (id.equalsIgnoreCase(CHANGELOG_TAG)) {
            mChangelogLink.setTitle(link.getTitle());
            mChangelogLink.setSummary(link.getDescription());
            mChangelogLink.setVisible(mShowLinks);
        } else if (id.equalsIgnoreCase(GAPPS_TAG)) {
            mGappsLink.setTitle(link.getTitle());
            mGappsLink.setSummary(link.getDescription());
            mGappsLink.setVisible(mShowLinks);
        } else if (id.equalsIgnoreCase(FORUM_TAG)) {
            mForumLink.setTitle(link.getTitle());
            mForumLink.setSummary(link.getDescription());
            mForumLink.setVisible(mShowLinks);
        } else if (id.equalsIgnoreCase(PAYPAL_TAG)) {
            mPayPalLink.setTitle(link.getTitle());
            mPayPalLink.setSummary(link.getDescription());
            mPayPalLink.setVisible(mShowLinks);
        } else if (id.equalsIgnoreCase(TELEGRAM_TAG)) {
            mTelegramLink.setTitle(link.getTitle());
            mTelegramLink.setSummary(link.getDescription());
            mTelegramLink.setVisible(mShowLinks);
        }
    }
    mLinksCategory.setTitle(mShowLinks ? context.getString(R.string.links_category) : "");
}
Also used : OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink)

Example 4 with OTALink

use of com.crdroid.settings.fragments.about.update.xml.OTALink in project android_packages_apps_crDroidSettings by crdroidandroid.

the class LinkConfig method getLinks.

public List<OTALink> getLinks(Context context, boolean force) {
    if (mLinks == null || force) {
        try {
            mLinks = new ArrayList<>();
            FileInputStream fis = context.openFileInput(FILENAME);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
            StringBuffer out = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                out.append(line);
            }
            reader.close();
            fis.close();
            JSONArray jsonLinks = new JSONArray(out.toString());
            for (int i = 0; i < jsonLinks.length(); i++) {
                JSONObject jsonLink = jsonLinks.getJSONObject(i);
                OTALink link = new OTALink(jsonLink.getString(OTAParser.ID));
                link.setTitle(jsonLink.getString(OTAParser.TITLE));
                link.setDescription(jsonLink.getString(OTAParser.DESCRIPTION));
                link.setUrl(jsonLink.getString(OTAParser.URL));
                mLinks.add(link);
            }
        } catch (JSONException | IOException e) {
            OTAUtils.logError(e);
        }
    }
    return mLinks;
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink) FileInputStream(java.io.FileInputStream) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader)

Example 5 with OTALink

use of com.crdroid.settings.fragments.about.update.xml.OTALink in project android_packages_apps_crDroidSettings by crdroidandroid.

the class LinkConfig method persistLinks.

public static void persistLinks(List<OTALink> links, Context context) {
    try {
        File dir = context.getFilesDir();
        File file = new File(dir, FILENAME);
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream fos = context.openFileOutput(FILENAME, Context.MODE_PRIVATE);
        JSONArray jsonLinks = new JSONArray();
        for (OTALink link : links) {
            JSONObject jsonLink = new JSONObject();
            jsonLink.put(OTAParser.ID, link.getId());
            jsonLink.put(OTAParser.TITLE, link.getTitle());
            jsonLink.put(OTAParser.DESCRIPTION, link.getDescription());
            jsonLink.put(OTAParser.URL, link.getUrl());
            jsonLinks.put(jsonLink);
        }
        fos.write(jsonLinks.toString().getBytes());
        fos.close();
        LinkConfigListener listener = getLinkConfigListener(context);
        if (listener != null) {
            listener.onConfigChange();
        }
    } catch (IOException | JSONException e) {
        OTAUtils.logError(e);
    }
}
Also used : JSONObject(org.json.JSONObject) FileOutputStream(java.io.FileOutputStream) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) File(java.io.File) OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink)

Aggregations

OTALink (com.crdroid.settings.fragments.about.update.xml.OTALink)5 Context (android.content.Context)2 IOException (java.io.IOException)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 TypedArray (android.content.res.TypedArray)1 Drawable (android.graphics.drawable.Drawable)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1