Added size in FeedItemlist

This commit is contained in:
Daniel Oeh 2012-04-12 20:51:59 +02:00
parent ca2eefe169
commit 13cb72c34e
3 changed files with 48 additions and 4 deletions

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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";
}
}
}