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