diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 620ec407..d34d1f5d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -7,7 +7,8 @@
-
+
+
map = new HashMap() {
+ {
+ put("sid", sessionId);
+ put("op", "getConfig");
+ }
+ };
+
+ req.execute(map);
+ }
+
private class FeedsRequest extends ApiRequest {
public FeedsRequest(Context context) {
@@ -206,7 +263,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
setLoadingStatus(R.string.error_no_feeds, false);
else
setLoadingStatus(R.string.blank, false);
-
+
+ if (m_enableFeedIcons) getFeedIcons();
+
}
} else {
MainActivity activity = (MainActivity)getActivity();
@@ -291,7 +350,27 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
ImageView icon = (ImageView)v.findViewById(R.id.icon);
if (icon != null) {
- icon.setImageResource(feed.unread > 0 ? R.drawable.ic_rss : R.drawable.ic_rss_bw);
+
+ if (m_enableFeedIcons) {
+
+ File storage = Environment.getExternalStorageDirectory();
+
+ File iconFile = new File(storage.getAbsolutePath() + ICON_PATH + feed.id + ".ico");
+ if (iconFile.exists()) {
+ Bitmap bmpOrig = BitmapFactory.decodeFile(iconFile.getAbsolutePath());
+ if (bmpOrig != null) {
+ Bitmap bmp = Bitmap.createScaledBitmap(bmpOrig, 28, 28, true);
+
+ icon.setImageBitmap(bmp);
+ }
+ } else {
+ icon.setImageResource(feed.unread > 0 ? R.drawable.ic_rss : R.drawable.ic_rss_bw);
+ }
+
+ } else {
+ icon.setImageResource(feed.unread > 0 ? R.drawable.ic_rss : R.drawable.ic_rss_bw);
+ }
+
}
return v;
@@ -310,4 +389,65 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
Collections.sort(m_feeds, cmp);
m_adapter.notifyDataSetInvalidated();
}
+
+ public class GetIconsTask extends AsyncTask {
+
+ private String m_baseUrl;
+
+ public GetIconsTask(String baseUrl) {
+ m_baseUrl = baseUrl;
+ }
+
+ @Override
+ protected Integer doInBackground(FeedList... params) {
+
+ try {
+ File storage = Environment.getExternalStorageDirectory();
+ final File iconPath = new File(storage.getAbsolutePath() + ICON_PATH);
+ if (!iconPath.exists()) iconPath.mkdir();
+
+ final FeedList feeds = params[0];
+
+ if (iconPath.exists()) {
+ for (Feed feed : feeds) {
+ if (feed.id > 0 && feed.has_icon) {
+ File iconFile = new File(iconPath.getAbsolutePath() + "/" + feed.id + ".ico");
+ String fetchUrl = m_baseUrl + "/" + feed.id + ".ico";
+
+ if (!iconFile.exists()) {
+ //Log.d(TAG, "Downloading " + fetchUrl);
+
+ try {
+ BufferedInputStream is = new BufferedInputStream(new URL(fetchUrl).openStream(), 1024);
+ FileOutputStream fos = new FileOutputStream(iconFile);
+
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ while ((len = is.read(buffer)) != -1) {
+ fos.write(buffer, 0, len);
+ }
+
+ fos.close();
+ is.close();
+ } catch (Exception e) {
+ Log.d(TAG, "Error downloading " + fetchUrl);
+ e.printStackTrace();
+ }
+
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ Log.d(TAG, "Error while downloading feed icons");
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected void onPostExecute(Integer result) {
+ m_adapter.notifyDataSetInvalidated();
+ }
+
+ }
}