diff options
author | Daniel Oeh <daniel@danielpc.(none)> | 2012-04-12 20:51:59 +0200 |
---|---|---|
committer | Daniel Oeh <daniel@danielpc.(none)> | 2012-04-12 20:51:59 +0200 |
commit | 13cb72c34e2daccf6c913d68a77bd3d3cd137ab5 (patch) | |
tree | 5370b790f52392652d064062ea32ee225ca88fb3 | |
parent | ca2eefe1692c64e6accd7f845bdf06edaa5804bc (diff) | |
download | AntennaPod-13cb72c34e2daccf6c913d68a77bd3d3cd137ab5.zip |
Added size in FeedItemlist
-rw-r--r-- | res/layout/feeditemlist_item.xml | 14 | ||||
-rw-r--r-- | src/de/podfetcher/adapter/FeedItemlistAdapter.java | 4 | ||||
-rw-r--r-- | src/de/podfetcher/util/Converter.java | 34 |
3 files changed, 48 insertions, 4 deletions
diff --git a/res/layout/feeditemlist_item.xml b/res/layout/feeditemlist_item.xml index 406303f67..a51d64cd7 100644 --- a/res/layout/feeditemlist_item.xml +++ b/res/layout/feeditemlist_item.xml @@ -1,11 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" > + android:layout_width="fill_parent" + android:layout_height="fill_parent" > <TextView android:id="@+id/txtvItemname" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - /> + /> + <TextView + android:id="@+id/txtvItemsize" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_below="@id/txtvItemname" + /> + </RelativeLayout> diff --git a/src/de/podfetcher/adapter/FeedItemlistAdapter.java b/src/de/podfetcher/adapter/FeedItemlistAdapter.java index 4ae67c48f..d888b72a9 100644 --- a/src/de/podfetcher/adapter/FeedItemlistAdapter.java +++ b/src/de/podfetcher/adapter/FeedItemlistAdapter.java @@ -3,6 +3,7 @@ package de.podfetcher.adapter; import java.util.List; import de.podfetcher.feed.FeedItem; +import de.podfetcher.util.Converter; import de.podfetcher.R; import android.widget.ArrayAdapter; import android.widget.TextView; @@ -29,6 +30,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> { LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.feeditemlist_item, null); holder.title = (TextView) convertView.findViewById(R.id.txtvItemname); + holder.size = (TextView) convertView.findViewById(R.id.txtvItemsize); convertView.setTag(holder); } else { @@ -36,11 +38,13 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> { } holder.title.setText(item.getTitle()); + holder.size.setText(Converter.byteToString(item.getMedia().getSize())); return convertView; } static class Holder { TextView title; + TextView size; } } diff --git a/src/de/podfetcher/util/Converter.java b/src/de/podfetcher/util/Converter.java new file mode 100644 index 000000000..fcf91015b --- /dev/null +++ b/src/de/podfetcher/util/Converter.java @@ -0,0 +1,34 @@ +package de.podfetcher.util; + +import android.util.Log; + +/** Provides methods for converting various units */ +public class Converter { + private static final String TAG = "Converter"; + + public static String byteToString(long input) { + int i = 0; + int result = 0; + + for(i = 0; i < 4; i++) { + result = (int) (input / Math.pow(1024, i)); + if(result < 1000) { + break; + } + } + + switch(i) { + case 0: + return result + " B"; + case 1: + return result + " KB"; + case 2: + return result + " MB"; + case 3: + return result + " GB"; + default: + Log.e(TAG, "Error happened in byteToString"); + return "ERROR"; + } + } +} |