Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Last active August 29, 2015 14:08
Show Gist options
  • Save jayrambhia/70869c6f7c4ab2c47757 to your computer and use it in GitHub Desktop.
Save jayrambhia/70869c6f7c4ab2c47757 to your computer and use it in GitHub Desktop.
<?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="80dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="768dp"
android:id="@+id/audio_main_layout"
android:background="#ebeff1" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/audio_object_like_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/heart_flat_4_3">
</ImageView>
<TextView
android:id="@+id/audio_object_likes_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerInParent="true"
android:textSize="22sp"
android:textStyle="bold|normal"
android:textColor="#ebeff1" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/album_art_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:layout_marginTop="8dp">
<ImageView
android:id="@+id/audio_object_album_art"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginLeft="40dp"
android:src="@drawable/unkown_album_art_image" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/album_art_layout"
android:layout_marginTop="15dp"
android:gravity="left|top">
<TextView
android:id="@+id/audio_object_title"
android:layout_width="180dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold"
android:textColor="#171716"
android:textSize="@dimen/regular_text_size" />
<TextView
android:id="@+id/audio_object_artist"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="Artist"
android:layout_below="@id/audio_object_title"
android:textColor="#ffad6868"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
public class PlayList extends ArrayAdapter<AudioObject> {
private int layoutResource;
private LayoutInflater inflater;
private final Context context;
public PlayList(Context con, int resource) {
super(con, resource);
layoutResource = resource;
context = con;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View workingView = null;
if (convertView == null) {
workingView = inflater.inflate(layoutResource, null);
} else {
workingView = convertView;
}
AudioObjectHolder holder = getAudioObjectHolder(workingView);
AudioObject entry = getItem(position);
holder.title.setText(entry.getTitle());
holder.artist.setText(entry.getAlbumArtist());
holder.likesTextView.setText(String.valueOf(entry.getNumberOfVotes()));
Bitmap bitmap = entry.getAlbumArtBitmap();
if (bitmap != null) {
holder.albumArt.setImageBitmap(bitmap);
} else {
holder.albumArt.setImageDrawable(context.getResources().getDrawable(R.drawable.unkown_album_art_image));
}
return workingView;
}
private AudioObjectHolder getAudioObjectHolder(View workingView) {
Object tag = workingView.getTag();
AudioObjectHolder holder = null;
if (tag == null || !(tag instanceof AudioObjectHolder)) {
holder = new AudioObjectHolder();
holder.title = (TextView)workingView.findViewById(R.id.audio_object_title);
holder.albumArt = (ImageView)workingView.findViewById(R.id.audio_object_album_art);
holder.artist = (TextView)workingView.findViewById(R.id.audio_object_artist);
holder.heartView = (SimpleButton)workingView.findViewById(R.id.audio_object_like_imageview);
holder.likesTextView = (TextView)workingView.findViewById(R.id.audio_object_likes_textview);
} else {
holder = (AudioObjectHolder) tag;
}
return holder;
}
public static class AudioObjectHolder {
public TextView title;
public TextView artist;
public ImageView albumArt;
public ImageView heartView;
public TextView likesTextView;
}
}
PlayList playlist = new PlayList(context, R.layout.audio_object_layout);
ListView listview = findViewById(R.id.listview);
listview.setAdapter(playlist);
// add some AudioObject to playlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment