From 3e6eb652b371946ca40863114f42f655a96920a2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 22 Apr 2014 20:44:53 -0700 Subject: More work on showing albums in grid --- res/layout/album_cell_item.xml | 56 +++++++++++++++++ res/layout/select_album.xml | 1 - .../dsub/fragments/SelectDirectoryFragment.java | 4 +- src/github/daneren2005/dsub/view/AlbumCell.java | 71 +++++++++++++++++++++- .../daneren2005/dsub/view/AlbumGridAdapter.java | 9 ++- .../daneren2005/dsub/view/SquareImageView.java | 32 ++++++++++ 6 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 res/layout/album_cell_item.xml create mode 100644 src/github/daneren2005/dsub/view/SquareImageView.java diff --git a/res/layout/album_cell_item.xml b/res/layout/album_cell_item.xml new file mode 100644 index 00000000..9cc85c6e --- /dev/null +++ b/res/layout/album_cell_item.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/select_album.xml b/res/layout/select_album.xml index b9bd3196..53b6bb63 100644 --- a/res/layout/select_album.xml +++ b/res/layout/select_album.xml @@ -30,7 +30,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="auto_fit" - android:columnWidth="90dp" android:horizontalSpacing="10dp" android:verticalSpacing="10dp" android:gravity="center" diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 499732f1..fb03f325 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -142,13 +142,13 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } }); - entryList.setOnScrollListener(new AbsListView.OnScrollListener() { + albumList.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - int topRowVerticalPosition = (entryList.getChildCount() == 0) ? 0 : entryList.getChildAt(0).getTop(); + int topRowVerticalPosition = (albumList.getChildCount() == 0) ? 0 : albumList.getChildAt(0).getTop(); refreshLayout.setEnabled(topRowVerticalPosition >= 0); } }); diff --git a/src/github/daneren2005/dsub/view/AlbumCell.java b/src/github/daneren2005/dsub/view/AlbumCell.java index b78ed442..9cee0c41 100644 --- a/src/github/daneren2005/dsub/view/AlbumCell.java +++ b/src/github/daneren2005/dsub/view/AlbumCell.java @@ -15,5 +15,74 @@ package github.daneren2005.dsub.view; -public class AlbumCell { +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import java.io.File; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.ImageLoader; + +public class AlbumCell extends UpdateView { + private static final String TAG = AlbumCell.class.getSimpleName(); + + private Context context; + private MusicDirectory.Entry album; + private File file; + + private View coverArtView; + private TextView titleView; + private TextView artistView; + + public AlbumCell(Context context) { + super(context); + this.context = context; + LayoutInflater.from(context).inflate(R.layout.album_cell_item, this, true); + + coverArtView = findViewById(R.id.album_coverart); + titleView = (TextView) findViewById(R.id.album_title); + artistView = (TextView) findViewById(R.id.album_artist); + moreButton = (ImageView) findViewById(R.id.album_more); + moreButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + v.showContextMenu(); + } + }); + } + + protected void setObjectImpl(Object obj1, Object obj2) { + this.album = (MusicDirectory.Entry) obj1; + if(album.getAlbum() == null) { + titleView.setText(album.getTitle()); + } else { + titleView.setText(album.getAlbum()); + } + String artist = album.getArtist(); + if(artist == null) { + artist = ""; + } + if(album.getYear() != null) { + artist += " - " + album.getYear(); + } + artistView.setText(artist); + artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE); + ((ImageLoader)obj2).loadImage(coverArtView, album, false, true); + file = null; + } + + @Override + protected void updateBackground() { + if(file == null) { + file = FileUtil.getAlbumDirectory(context, album); + } + + exists = file.exists(); + isStarred = album.isStarred(); + } } diff --git a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java index 60d4cda6..3c81fa9a 100644 --- a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java +++ b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java @@ -42,8 +42,13 @@ public class AlbumGridAdapter extends ArrayAdapter { public View getView(int position, View convertView, ViewGroup parent) { MusicDirectory.Entry entry = getItem(position); - AlbumView view; - view = new AlbumView(activity); + AlbumCell view; + if(convertView instanceof AlbumCell) { + view = (AlbumCell) convertView; + } else { + view = new AlbumCell(activity); + } + view.setObject(entry, imageLoader); return view; } diff --git a/src/github/daneren2005/dsub/view/SquareImageView.java b/src/github/daneren2005/dsub/view/SquareImageView.java new file mode 100644 index 00000000..77ca50db --- /dev/null +++ b/src/github/daneren2005/dsub/view/SquareImageView.java @@ -0,0 +1,32 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + Copyright 2014 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ImageView; + +public class SquareImageView extends ImageView { + public SquareImageView(final Context context, final AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void onMeasure(final int widthSpec, final int heightSpec) { + super.onMeasure(widthSpec, heightSpec); + setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); + } +} -- cgit v1.2.3